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
|
||||
1388947181 source:/home/stefan/Proj/UDPclient/main.c
|
||||
1389037649 source:/home/stefan/Proj/UDPclient/main.c
|
||||
<pthread.h>
|
||||
<stdio.h>
|
||||
<stdlib.h>
|
||||
|
@ -17,13 +17,15 @@
|
|||
<signal.h>
|
||||
<sys/socket.h>
|
||||
<netinet/in.h>
|
||||
<unistd.h>
|
||||
<arpa/inet.h>
|
||||
<inttypes.h>
|
||||
|
||||
1388951235 source:/home/stefan/Proj/UDPclient/henglong.c
|
||||
"henglong.h"
|
||||
|
||||
1388951303 /home/stefan/Proj/UDPclient/henglong.h
|
||||
<linux/input.h>
|
||||
1389038648 source:/home/stefan/Proj/UDPclient/henglong.c
|
||||
"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
|
||||
SERVER 127.0.0.1:32000
|
||||
TIMEOUT 250
|
||||
CLINBR 0
|
||||
|
|
15
henglong.c
15
henglong.c
|
@ -43,11 +43,26 @@ 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)
|
||||
{
|
||||
//printf("%d\n", event.code);
|
||||
if(107==event.code){
|
||||
if(event.value){
|
||||
henglong->servoff = 1;
|
||||
}else{
|
||||
henglong->servoff = 0;
|
||||
}
|
||||
}
|
||||
if(2<=event.code && 11>=event.code){
|
||||
if(event.value){
|
||||
henglong->clisel = (event.code - 1) % 10;
|
||||
}
|
||||
}
|
||||
if(108==event.code){
|
||||
if(event.value){
|
||||
henglong->velocity = 0b11111;
|
||||
|
|
|
@ -2,12 +2,16 @@
|
|||
#define HENGLONG_H_INCLUDED
|
||||
|
||||
#include <linux/input.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
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);
|
||||
|
|
25
main.c
25
main.c
|
@ -16,7 +16,6 @@
|
|||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#include <inttypes.h>
|
||||
|
@ -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 <stefan.helmert@gmx.net>\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;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
BIN
obj/Debug/main.o
BIN
obj/Debug/main.o
Binary file not shown.
Loading…
Reference in New Issue