USAGE prompt; client number, client select, server exit
This commit is contained in:
parent
8eabc532ed
commit
fe0747336c
|
@ -1,5 +1,5 @@
|
||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1388947181 source:/home/stefan/Proj/UDPclient/main.c
|
1389037649 source:/home/stefan/Proj/UDPclient/main.c
|
||||||
<pthread.h>
|
<pthread.h>
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<stdlib.h>
|
<stdlib.h>
|
||||||
|
@ -17,13 +17,15 @@
|
||||||
<signal.h>
|
<signal.h>
|
||||||
<sys/socket.h>
|
<sys/socket.h>
|
||||||
<netinet/in.h>
|
<netinet/in.h>
|
||||||
<unistd.h>
|
|
||||||
<arpa/inet.h>
|
<arpa/inet.h>
|
||||||
<inttypes.h>
|
<inttypes.h>
|
||||||
|
|
||||||
1388951235 source:/home/stefan/Proj/UDPclient/henglong.c
|
|
||||||
"henglong.h"
|
"henglong.h"
|
||||||
|
|
||||||
1388951303 /home/stefan/Proj/UDPclient/henglong.h
|
1389038648 source:/home/stefan/Proj/UDPclient/henglong.c
|
||||||
<linux/input.h>
|
"henglong.h"
|
||||||
|
|
||||||
|
1389038543 /home/stefan/Proj/UDPclient/henglong.h
|
||||||
|
<linux/input.h>
|
||||||
|
<stdio.h>
|
||||||
|
<inttypes.h>
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -2,3 +2,4 @@ INPUTDEV /dev/input/event2
|
||||||
FRAME_US 100000
|
FRAME_US 100000
|
||||||
SERVER 127.0.0.1:32000
|
SERVER 127.0.0.1:32000
|
||||||
TIMEOUT 250
|
TIMEOUT 250
|
||||||
|
CLINBR 0
|
||||||
|
|
135
henglong.c
135
henglong.c
|
@ -43,81 +43,96 @@ void inithenglong(henglong_t* henglong)
|
||||||
henglong->turret_left = 0;
|
henglong->turret_left = 0;
|
||||||
henglong->turret_right = 0;
|
henglong->turret_right = 0;
|
||||||
henglong->recoil = 0;
|
henglong->recoil = 0;
|
||||||
|
henglong->clisel = 0;
|
||||||
|
henglong->servoff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int event2data(henglong_t* henglong, struct input_event event)
|
int event2data(henglong_t* henglong, struct input_event event)
|
||||||
{
|
{
|
||||||
if(108==event.code){
|
//printf("%d\n", event.code);
|
||||||
if(event.value){
|
if(107==event.code){
|
||||||
henglong->velocity = 0b11111;
|
if(event.value){
|
||||||
}else{
|
henglong->servoff = 1;
|
||||||
henglong->velocity = 0b10000;
|
}else{
|
||||||
}
|
henglong->servoff = 0;
|
||||||
}
|
}
|
||||||
if(103==event.code){
|
}
|
||||||
if(event.value){
|
if(2<=event.code && 11>=event.code){
|
||||||
henglong->velocity = 0b00000;
|
if(event.value){
|
||||||
}else{
|
henglong->clisel = (event.code - 1) % 10;
|
||||||
henglong->velocity = 0b10000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(105==event.code){
|
}
|
||||||
if(event.value){
|
if(108==event.code){
|
||||||
henglong->direction = 0b00000;
|
if(event.value){
|
||||||
}else{
|
henglong->velocity = 0b11111;
|
||||||
henglong->direction = 0b01111;
|
}else{
|
||||||
}
|
henglong->velocity = 0b10000;
|
||||||
}
|
}
|
||||||
if(106==event.code){
|
}
|
||||||
if(event.value){
|
if(103==event.code){
|
||||||
henglong->direction = 0b11111;
|
if(event.value){
|
||||||
}else{
|
henglong->velocity = 0b00000;
|
||||||
henglong->direction = 0b01111;
|
}else{
|
||||||
}
|
henglong->velocity = 0b10000;
|
||||||
}
|
}
|
||||||
if(23==event.code){
|
}
|
||||||
if(event.value){
|
if(105==event.code){
|
||||||
henglong->ignation = 1;
|
if(event.value){
|
||||||
}else{
|
henglong->direction = 0b00000;
|
||||||
henglong->ignation = 0;
|
}else{
|
||||||
}
|
henglong->direction = 0b01111;
|
||||||
}
|
}
|
||||||
if(34==event.code){
|
}
|
||||||
if(event.value){
|
if(106==event.code){
|
||||||
henglong->mg = 1;
|
if(event.value){
|
||||||
}else{
|
henglong->direction = 0b11111;
|
||||||
henglong->mg = 0;
|
}else{
|
||||||
}
|
henglong->direction = 0b01111;
|
||||||
}
|
}
|
||||||
if(33==event.code){
|
}
|
||||||
if(event.value){
|
if(23==event.code){
|
||||||
henglong->fire = 1;
|
if(event.value){
|
||||||
}else{
|
henglong->ignation = 1;
|
||||||
henglong->fire = 0;
|
}else{
|
||||||
}
|
henglong->ignation = 0;
|
||||||
}
|
}
|
||||||
if(29==event.code){
|
}
|
||||||
if(event.value){
|
if(34==event.code){
|
||||||
henglong->turret_left = 1;
|
if(event.value){
|
||||||
}else{
|
henglong->mg = 1;
|
||||||
henglong->turret_left = 0;
|
}else{
|
||||||
}
|
henglong->mg = 0;
|
||||||
}
|
}
|
||||||
if(20==event.code){
|
}
|
||||||
if(event.value){
|
if(33==event.code){
|
||||||
henglong->turretelev = 1;
|
if(event.value){
|
||||||
}else{
|
henglong->fire = 1;
|
||||||
henglong->turretelev = 0;
|
}else{
|
||||||
}
|
henglong->fire = 0;
|
||||||
}
|
}
|
||||||
if(19==event.code){
|
}
|
||||||
if(event.value){
|
if(29==event.code){
|
||||||
henglong->recoil = 1;
|
if(event.value){
|
||||||
}else{
|
henglong->turret_left = 1;
|
||||||
henglong->recoil = 0;
|
}else{
|
||||||
}
|
henglong->turret_left = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(20==event.code){
|
||||||
|
if(event.value){
|
||||||
|
henglong->turretelev = 1;
|
||||||
|
}else{
|
||||||
|
henglong->turretelev = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(19==event.code){
|
||||||
|
if(event.value){
|
||||||
|
henglong->recoil = 1;
|
||||||
|
}else{
|
||||||
|
henglong->recoil = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return values2data(henglong->velocity, henglong->direction, henglong->ignation, henglong->mg, henglong->fire, henglong->turretelev, henglong->turret_left, henglong->turret_right, henglong->recoil);
|
return values2data(henglong->velocity, henglong->direction, henglong->ignation, henglong->mg, henglong->fire, henglong->turretelev, henglong->turret_left, henglong->turret_right, henglong->recoil);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,16 @@
|
||||||
#define HENGLONG_H_INCLUDED
|
#define HENGLONG_H_INCLUDED
|
||||||
|
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct henglong_t
|
typedef struct henglong_t
|
||||||
{
|
{
|
||||||
int velocity, direction;
|
int velocity, direction;
|
||||||
int ignation, mg, fire, turretelev, turret_left, turret_right, recoil;
|
int ignation, mg, fire, turretelev, turret_left, turret_right, recoil;
|
||||||
|
uint8_t clisel;
|
||||||
|
unsigned char servoff;
|
||||||
} henglong_t;
|
} henglong_t;
|
||||||
|
|
||||||
int CRC(int data);
|
int CRC(int data);
|
||||||
|
|
25
main.c
25
main.c
|
@ -16,7 +16,6 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
@ -90,6 +89,8 @@ void *refl_thread_fcn(void* arg)
|
||||||
unsigned char recvline[64];
|
unsigned char recvline[64];
|
||||||
uint16_t frame_nbr_refl;
|
uint16_t frame_nbr_refl;
|
||||||
refl_thread_args_t* refl_thread_args_ptr;
|
refl_thread_args_t* refl_thread_args_ptr;
|
||||||
|
uint8_t clinbr, clisel;
|
||||||
|
unsigned char servoff;
|
||||||
printf("pthread refl started\n");
|
printf("pthread refl started\n");
|
||||||
|
|
||||||
refl_thread_args_ptr = (refl_thread_args_t*) arg;
|
refl_thread_args_ptr = (refl_thread_args_t*) arg;
|
||||||
|
@ -108,7 +109,10 @@ void *refl_thread_fcn(void* arg)
|
||||||
for(i=0;i<4;i++){
|
for(i=0;i<4;i++){
|
||||||
frame_refl |= recvline[i+10] << i*8;
|
frame_refl |= recvline[i+10] << i*8;
|
||||||
}
|
}
|
||||||
printf("REFL FRAME -- FRM_NBR: %5d, RTT: %7" PRIu64 ", BYTES recv: %3d, REFL_FRM: %#x\n", frame_nbr_refl, get_us() - time_us_refl, n, frame_refl);
|
clinbr = recvline[14];
|
||||||
|
clisel = recvline[15];
|
||||||
|
servoff = recvline[16];
|
||||||
|
printf("REFL FRAME -- FRM_NBR: %5d, RTT: %7" PRIu64 ", BYTES recv: %3d, REFL_FRM: %#x, CLINBR: %d, CLISEL: %d, SERVOFF: %d\n", frame_nbr_refl, get_us() - time_us_refl, n, frame_refl, clinbr, clisel, servoff);
|
||||||
refl_thread_args_ptr->timestamps[frame_nbr_refl % refl_thread_args_ptr->timeout] = 0;
|
refl_thread_args_ptr->timestamps[frame_nbr_refl % refl_thread_args_ptr->timeout] = 0;
|
||||||
}
|
}
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
@ -121,6 +125,7 @@ typedef struct henglongconf_t
|
||||||
in_addr_t ip; // v4 only
|
in_addr_t ip; // v4 only
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint8_t timeout;
|
uint8_t timeout;
|
||||||
|
uint8_t clinbr;
|
||||||
} henglongconf_t;
|
} henglongconf_t;
|
||||||
|
|
||||||
henglongconf_t getconfig(char* conffilename)
|
henglongconf_t getconfig(char* conffilename)
|
||||||
|
@ -154,6 +159,9 @@ henglongconf_t getconfig(char* conffilename)
|
||||||
if(0==strcmp(parameter,"TIMEOUT")){
|
if(0==strcmp(parameter,"TIMEOUT")){
|
||||||
sscanf(value, "%" SCNu8 , &conf.timeout);
|
sscanf(value, "%" SCNu8 , &conf.timeout);
|
||||||
}
|
}
|
||||||
|
if(0==strcmp(parameter,"CLINBR")){
|
||||||
|
sscanf(value, "%" SCNu8 , &conf.clinbr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
@ -175,6 +183,12 @@ int main(int argc, char* argv[])
|
||||||
uint64_t time_us;
|
uint64_t time_us;
|
||||||
henglongconf_t conf;
|
henglongconf_t conf;
|
||||||
|
|
||||||
|
|
||||||
|
if(2!=argc){
|
||||||
|
printf("\nThis program is intented to be run on the PC as client to control the server on the heng long tank. \n\n USAGE: UDPclient client.config\n\n Copyright (C) 2014 Stefan Helmert <stefan.helmert@gmx.net>\n\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
inithenglong(&hl1);
|
inithenglong(&hl1);
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,10 +234,13 @@ int main(int argc, char* argv[])
|
||||||
for(i=0;i<4;i++){
|
for(i=0;i<4;i++){
|
||||||
sendline[i+10] = (frame >> i*8) & 0xFF;
|
sendline[i+10] = (frame >> i*8) & 0xFF;
|
||||||
}
|
}
|
||||||
|
sendline[14] = conf.clinbr;
|
||||||
|
sendline[15] = hl1.clisel;
|
||||||
|
sendline[16] = hl1.servoff;
|
||||||
|
|
||||||
n_send = sendto(sockfd, sendline, 16, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
n_send = sendto(sockfd, sendline, 32, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
||||||
|
|
||||||
printf("SEND FRAME -- FRM_NBR: %5d, BYTES send: %3d, SEND_FRM: %#x\n", frame_nbr, n_send, frame);
|
printf("SEND FRAME -- FRM_NBR: %5d, BYTES send: %3d, SEND_FRM: %#x, CLINBR: %d, CLISEL: %d, SERVOFF: %d\n", frame_nbr, n_send, frame, conf.clinbr, hl1.clisel, hl1.servoff);
|
||||||
if(pthread_kill(inpthread, 0)) break;
|
if(pthread_kill(inpthread, 0)) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
BIN
obj/Debug/main.o
BIN
obj/Debug/main.o
Binary file not shown.
Loading…
Reference in New Issue