diff --git a/UDPclient.depend b/UDPclient.depend index 679bf23..ba39e76 100644 --- a/UDPclient.depend +++ b/UDPclient.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1388947181 source:/home/stefan/Proj/UDPclient/main.c +1389037649 source:/home/stefan/Proj/UDPclient/main.c @@ -17,13 +17,15 @@ - - -1388951235 source:/home/stefan/Proj/UDPclient/henglong.c "henglong.h" -1388951303 /home/stefan/Proj/UDPclient/henglong.h - +1389038648 source:/home/stefan/Proj/UDPclient/henglong.c + "henglong.h" + +1389038543 /home/stefan/Proj/UDPclient/henglong.h + + + diff --git a/bin/Debug/UDPclient b/bin/Debug/UDPclient index 740a021..b1dbef6 100755 Binary files a/bin/Debug/UDPclient and b/bin/Debug/UDPclient differ diff --git a/client.config b/client.config index be1d189..b11e9ae 100644 --- a/client.config +++ b/client.config @@ -2,3 +2,4 @@ INPUTDEV /dev/input/event2 FRAME_US 100000 SERVER 127.0.0.1:32000 TIMEOUT 250 +CLINBR 0 diff --git a/henglong.c b/henglong.c index c440128..6e5a721 100644 --- a/henglong.c +++ b/henglong.c @@ -43,81 +43,96 @@ void inithenglong(henglong_t* henglong) henglong->turret_left = 0; henglong->turret_right = 0; henglong->recoil = 0; + henglong->clisel = 0; + henglong->servoff = 0; } int event2data(henglong_t* henglong, struct input_event event) { - if(108==event.code){ - if(event.value){ - henglong->velocity = 0b11111; - }else{ - henglong->velocity = 0b10000; - } + //printf("%d\n", event.code); + if(107==event.code){ + if(event.value){ + henglong->servoff = 1; + }else{ + henglong->servoff = 0; } - if(103==event.code){ - if(event.value){ - henglong->velocity = 0b00000; - }else{ - henglong->velocity = 0b10000; - } + } + if(2<=event.code && 11>=event.code){ + if(event.value){ + henglong->clisel = (event.code - 1) % 10; } - if(105==event.code){ - if(event.value){ - henglong->direction = 0b00000; - }else{ - henglong->direction = 0b01111; - } + } + if(108==event.code){ + if(event.value){ + henglong->velocity = 0b11111; + }else{ + henglong->velocity = 0b10000; } - if(106==event.code){ - if(event.value){ - henglong->direction = 0b11111; - }else{ - henglong->direction = 0b01111; - } + } + if(103==event.code){ + if(event.value){ + henglong->velocity = 0b00000; + }else{ + henglong->velocity = 0b10000; } - if(23==event.code){ - if(event.value){ - henglong->ignation = 1; - }else{ - henglong->ignation = 0; - } + } + if(105==event.code){ + if(event.value){ + henglong->direction = 0b00000; + }else{ + henglong->direction = 0b01111; } - if(34==event.code){ - if(event.value){ - henglong->mg = 1; - }else{ - henglong->mg = 0; - } + } + if(106==event.code){ + if(event.value){ + henglong->direction = 0b11111; + }else{ + henglong->direction = 0b01111; } - if(33==event.code){ - if(event.value){ - henglong->fire = 1; - }else{ - henglong->fire = 0; - } + } + if(23==event.code){ + if(event.value){ + henglong->ignation = 1; + }else{ + henglong->ignation = 0; } - if(29==event.code){ - if(event.value){ - henglong->turret_left = 1; - }else{ - henglong->turret_left = 0; - } + } + if(34==event.code){ + if(event.value){ + henglong->mg = 1; + }else{ + henglong->mg = 0; } - if(20==event.code){ - if(event.value){ - henglong->turretelev = 1; - }else{ - henglong->turretelev = 0; - } + } + if(33==event.code){ + if(event.value){ + henglong->fire = 1; + }else{ + henglong->fire = 0; } - if(19==event.code){ - if(event.value){ - henglong->recoil = 1; - }else{ - henglong->recoil = 0; - } + } + if(29==event.code){ + if(event.value){ + henglong->turret_left = 1; + }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); } diff --git a/henglong.h b/henglong.h index 9dbdd03..9adf154 100644 --- a/henglong.h +++ b/henglong.h @@ -2,12 +2,16 @@ #define HENGLONG_H_INCLUDED #include +#include +#include typedef struct henglong_t { int velocity, direction; int ignation, mg, fire, turretelev, turret_left, turret_right, recoil; + uint8_t clisel; + unsigned char servoff; } henglong_t; int CRC(int data); diff --git a/main.c b/main.c index 01a07d4..35dba46 100644 --- a/main.c +++ b/main.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #define __STDC_FORMAT_MACROS #include @@ -90,6 +89,8 @@ void *refl_thread_fcn(void* arg) unsigned char recvline[64]; uint16_t frame_nbr_refl; refl_thread_args_t* refl_thread_args_ptr; + uint8_t clinbr, clisel; + unsigned char servoff; printf("pthread refl started\n"); 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++){ 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; } pthread_exit(0); @@ -121,6 +125,7 @@ typedef struct henglongconf_t in_addr_t ip; // v4 only uint16_t port; uint8_t timeout; + uint8_t clinbr; } henglongconf_t; henglongconf_t getconfig(char* conffilename) @@ -154,6 +159,9 @@ henglongconf_t getconfig(char* conffilename) if(0==strcmp(parameter,"TIMEOUT")){ sscanf(value, "%" SCNu8 , &conf.timeout); } + if(0==strcmp(parameter,"CLINBR")){ + sscanf(value, "%" SCNu8 , &conf.clinbr); + } } return conf; } @@ -175,6 +183,12 @@ int main(int argc, char* argv[]) uint64_t time_us; 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 \n\n"); + return 0; + } + inithenglong(&hl1); @@ -220,10 +234,13 @@ int main(int argc, char* argv[]) for(i=0;i<4;i++){ 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; } diff --git a/obj/Debug/henglong.o b/obj/Debug/henglong.o index bf0af53..1b6ee4c 100644 Binary files a/obj/Debug/henglong.o and b/obj/Debug/henglong.o differ diff --git a/obj/Debug/main.o b/obj/Debug/main.o index d3905e4..402296a 100644 Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ