client sends a structure, now with right, left, pan, tilt

This commit is contained in:
Stefan Helmert 2014-02-05 06:43:14 +01:00
parent 8b56939b21
commit 3b507ff03c
10 changed files with 118 additions and 40 deletions

View File

@ -31,6 +31,14 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
</Compiler> </Compiler>
<Linker>
<Add option="-pthread" />
</Linker>
<Unit filename="client.config" />
<Unit filename="henglong.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="henglong.h" />
<Unit filename="main.c"> <Unit filename="main.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>

View File

@ -1,5 +1,5 @@
# depslib dependency file v1.0 # depslib dependency file v1.0
1389621137 source:/home/stefan/Proj/UDPclient/main.c 1391553490 source:/home/stefan/Proj/UDPclient/main.c
<pthread.h> <pthread.h>
<stdio.h> <stdio.h>
<stdlib.h> <stdlib.h>
@ -21,10 +21,10 @@
<inttypes.h> <inttypes.h>
"henglong.h" "henglong.h"
1389212471 source:/home/stefan/Proj/UDPclient/henglong.c 1391557977 source:/home/stefan/Proj/UDPclient/henglong.c
"henglong.h" "henglong.h"
1389038543 /home/stefan/Proj/UDPclient/henglong.h 1391558168 /home/stefan/Proj/UDPclient/henglong.h
<linux/input.h> <linux/input.h>
<stdio.h> <stdio.h>
<inttypes.h> <inttypes.h>

View File

@ -1,9 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<ActiveTarget name="Debug" /> <ActiveTarget name="Debug" />
<File name="henglong.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="303" topLine="0" />
</Cursor>
</File>
<File name="client.config" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="62" topLine="0" />
</Cursor>
</File>
<File name="henglong.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3563" topLine="94" />
</Cursor>
</File>
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="1353" topLine="176" /> <Cursor1 position="2309" topLine="99" />
</Cursor> </Cursor>
</File> </File>
</CodeBlocks_layout_file> </CodeBlocks_layout_file>

Binary file not shown.

View File

@ -1,5 +1,5 @@
INPUTDEV /dev/input/event2 INPUTDEV /dev/input/event2
FRAME_US 100000 FRAME_US 100000
SERVER 10.8.191.196:32000 SERVER 127.0.0.1:32000
TIMEOUT 250 TIMEOUT 250
CLINBR 0 CLINBR 0

View File

@ -45,6 +45,11 @@ void inithenglong(henglong_t* henglong)
henglong->recoil = 0; henglong->recoil = 0;
henglong->clisel = 0; henglong->clisel = 0;
henglong->servoff = 0; henglong->servoff = 0;
henglong->tilt_up = 0;
henglong->tilt_down = 0;
henglong->pan_left = 0;
henglong->pan_right = 0;
} }
@ -58,6 +63,34 @@ int event2data(henglong_t* henglong, struct input_event event)
henglong->servoff = 0; henglong->servoff = 0;
} }
} }
if(17==event.code){
if(event.value){
henglong->tilt_up = 1;
}else{
henglong->tilt_up = 0;
}
}
if(31==event.code){
if(event.value){
henglong->tilt_down = 1;
}else{
henglong->tilt_down = 0;
}
}
if(30==event.code){
if(event.value){
henglong->pan_left = 1;
}else{
henglong->pan_left = 0;
}
}
if(32==event.code){
if(event.value){
henglong->pan_right = 1;
}else{
henglong->pan_right = 0;
}
}
if(2<=event.code && 11>=event.code){ if(2<=event.code && 11>=event.code){
if(event.value){ if(event.value){
henglong->clisel = (event.code - 1) % 10; henglong->clisel = (event.code - 1) % 10;

View File

@ -9,7 +9,7 @@
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, tilt_up, tilt_down, pan_left, pan_right;
uint8_t clisel; uint8_t clisel;
unsigned char servoff; unsigned char servoff;
} henglong_t; } henglong_t;

90
main.c
View File

@ -21,13 +21,33 @@
#include <inttypes.h> #include <inttypes.h>
#include "henglong.h" #include "henglong.h"
typedef struct outtty_t
{
int16_t motor_r;
int16_t motor_l;
int16_t servo_tilt;
int16_t servo_pan;
} outtty_t;
typedef struct input_thread_t typedef struct input_thread_t
{ {
char* filename; char* filename;
int frame; int frame;
henglong_t hl; henglong_t hl;
outtty_t outtty;
} input_thread_t; } input_thread_t;
typedef struct RCdatagram_t
{
uint16_t frame_nbr;
uint64_t time_us;
int frame_recv;
uint8_t clisel;
uint8_t clinbr;
uint8_t client_selected;
unsigned char servoff;
outtty_t outtty;
} RCdatagram_t;
void *input_thread_fcn(void * arg) void *input_thread_fcn(void * arg)
{ {
@ -55,7 +75,18 @@ void *input_thread_fcn(void * arg)
if(EV_KEY == ev.type) { if(EV_KEY == ev.type) {
printf("%d %d\n", ev.code, ev.value); printf("%d %d\n", ev.code, ev.value);
args->frame = data2frame(event2data(&args->hl, ev)); args->frame = data2frame(event2data(&args->hl, ev));
args->outtty.motor_r = (2*0b01111 - args->hl.velocity - args->hl.direction)*40;
args->outtty.motor_l = (- args->hl.velocity + args->hl.direction)*40;
args->outtty.servo_pan += args->hl.pan_left - args->hl.pan_right;
if(args->outtty.servo_pan>50) args->outtty.servo_pan = 50;
if(args->outtty.servo_pan<-50) args->outtty.servo_pan = -50;
if(args->outtty.servo_tilt>50) args->outtty.servo_tilt = 50;
if(args->outtty.servo_tilt<-50) args->outtty.servo_tilt = -50;
args->outtty.servo_tilt += args->hl.tilt_up - args->hl.tilt_down;
if(args->hl.ignation) {
args->outtty.servo_pan = 0;
args->outtty.servo_tilt= 0;
}
} }
// quit // quit
if(16==ev.code && 1==ev.value) break; if(16==ev.code && 1==ev.value) break;
@ -87,14 +118,14 @@ uint64_t get_us(void)
void *refl_thread_fcn(void* arg) void *refl_thread_fcn(void* arg)
{ {
int n, i = 0; int n;
int frame_refl; int frame_refl;
uint64_t time_us_refl; uint64_t time_us_refl;
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; uint8_t clinbr, clisel;
unsigned char servoff; unsigned char servoff;
RCdatagram_t refldata;
printf("pthread refl started\n"); printf("pthread refl started\n");
@ -102,22 +133,19 @@ void *refl_thread_fcn(void* arg)
refl_thread_args_ptr = (refl_thread_args_t*) arg; refl_thread_args_ptr = (refl_thread_args_t*) arg;
while(1){ while(1){
n=recvfrom(refl_thread_args_ptr->sockfd,recvline,64,0,NULL,NULL); n=recvfrom(refl_thread_args_ptr->sockfd,&refldata,64,0,NULL,NULL);
frame_nbr_refl = 0;
for(i=0;i<2;i++){
frame_nbr_refl |= recvline[i] << i*8; frame_nbr_refl = refldata.frame_nbr;
}
time_us_refl = 0ULL; time_us_refl = refldata.time_us;
for(i=0;i<8;i++){
time_us_refl |= ((uint64_t)recvline[i+2]) << i*8;
} frame_refl = refldata.frame_recv;
frame_refl = 0;
for(i=0;i<4;i++){ clinbr = refldata.clinbr;
frame_refl |= recvline[i+10] << i*8; clisel = refldata.clisel;
} servoff = refldata.servoff;
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); 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;
} }
@ -178,14 +206,13 @@ int main(int argc, char* argv[])
pthread_t inpthread, refl_thread; pthread_t inpthread, refl_thread;
input_thread_t input_thread_args; input_thread_t input_thread_args;
refl_thread_args_t refl_thread_args; refl_thread_args_t refl_thread_args;
int i=0;
int frame = 0; int frame = 0;
uint16_t frame_nbr; uint16_t frame_nbr;
int sockfd, n_send; int sockfd, n_send;
struct sockaddr_in servaddr; struct sockaddr_in servaddr;
unsigned char sendline[64];
uint64_t time_us; uint64_t time_us;
henglongconf_t conf; henglongconf_t conf;
RCdatagram_t senddata;
if(2!=argc){ if(2!=argc){
@ -228,20 +255,15 @@ int main(int argc, char* argv[])
if(refl_thread_args.timestamps[frame_nbr % conf.timeout]) printf("*** Frameloss detected! Lost frame from local time: %" PRIu64 "\n", refl_thread_args.timestamps[frame_nbr % conf.timeout]); if(refl_thread_args.timestamps[frame_nbr % conf.timeout]) printf("*** Frameloss detected! Lost frame from local time: %" PRIu64 "\n", refl_thread_args.timestamps[frame_nbr % conf.timeout]);
refl_thread_args.timestamps[frame_nbr % conf.timeout] = time_us; refl_thread_args.timestamps[frame_nbr % conf.timeout] = time_us;
for(i=0;i<2;i++){ senddata.frame_nbr = frame_nbr;
sendline[i] = (frame_nbr >> i*8) & 0xFF; senddata.time_us = time_us;
} senddata.frame_recv = frame;
for(i=0;i<8;i++){ senddata.clinbr = conf.clinbr;
sendline[i+2] = (time_us >> i*8) & 0xFF; senddata.clisel = input_thread_args.hl.clisel;
} senddata.servoff = input_thread_args.hl.servoff;
for(i=0;i<4;i++){ senddata.outtty = input_thread_args.outtty;
sendline[i+10] = (frame >> i*8) & 0xFF;
}
sendline[14] = conf.clinbr;
sendline[15] = input_thread_args.hl.clisel;
sendline[16] = input_thread_args.hl.servoff;
n_send = sendto(sockfd, sendline, 32, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); n_send = sendto(sockfd, &senddata, sizeof(senddata), 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
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, input_thread_args.hl.clisel, input_thread_args.hl.servoff); 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, input_thread_args.hl.clisel, input_thread_args.hl.servoff);
if(pthread_kill(inpthread, 0)) break; if(pthread_kill(inpthread, 0)) break;

Binary file not shown.

Binary file not shown.