diff --git a/UDPclient.depend b/UDPclient.depend index 2e47e21..471f30b 100644 --- a/UDPclient.depend +++ b/UDPclient.depend @@ -60,3 +60,44 @@ 1392494235 source:/home/chch/HengLongUDPclient/henglong.c "henglong.h" +1393274981 source:/home/stefan/Proj/HengLongUDPclient/henglong.c + "henglong.h" + +1393274981 /home/stefan/Proj/HengLongUDPclient/henglong.h + + + + +1393291221 source:/home/stefan/Proj/HengLongUDPclient/main.c + + + + + + + + + + + + + + + + + + + + "henglong.h" + + "wansview.h" + +1393285475 /home/stefan/Proj/HengLongUDPclient/wansview.h + + + + + +1393290504 source:/home/stefan/Proj/HengLongUDPclient/wansview.c + "wansview.h" + diff --git a/bin/Debug/UDPclient b/bin/Debug/UDPclient index 649fc1b..7ac107e 100755 Binary files a/bin/Debug/UDPclient and b/bin/Debug/UDPclient differ diff --git a/client.config b/client.config index 844644d..acf2378 100644 --- a/client.config +++ b/client.config @@ -1,5 +1,7 @@ KEYBOARD /dev/input/event2 JOYSTICK /dev/input/js0 +CAM 192.168.1.23 +CAMINTERVAL 100000 FRAME_US 100000 SERVER 10.8.245.47:32000 TIMEOUT 250 diff --git a/main.c b/main.c index 6f2576a..ec7e44c 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,8 @@ #include #include "henglong.h" #include +#include "wansview.h" + typedef struct outtty_t { @@ -113,7 +115,6 @@ void *keyboard_thread_fcn(void * arg) pthread_exit(0); } - void *joystick_thread_fcn(void * arg) { printf("pthread input started\n"); @@ -274,6 +275,8 @@ typedef struct henglongconf_t char keyboarddevname[256]; char joystickdevname[256]; in_addr_t ip; // v4 only + char cam[64]; + uint32_t caminterval; uint16_t port; uint8_t timeout; uint8_t clinbr; @@ -295,7 +298,8 @@ henglongconf_t getconfig(char* conffilename) conf.ip = inet_addr("127.0.0.1"); conf.keyboarddevname[0] = 0; conf.joystickdevname[0] = 0; - + conf.cam[0] = 0; + conf.caminterval = 100000; while(fgets(line, 256, configFile)){ sscanf(line, "%16s %256s", parameter, value); if(0==strcmp(parameter,"KEYBOARD")){ @@ -304,6 +308,12 @@ henglongconf_t getconfig(char* conffilename) if(0==strcmp(parameter,"JOYSTICK")){ sscanf(value, "%256s", conf.joystickdevname); } + if(0==strcmp(parameter,"CAM")){ + sscanf(value, "%64s", conf.cam); + } + if(0==strcmp(parameter,"CAMINTERVAL")){ + sscanf(value, "%" SCNu32, &conf.caminterval); + } if(0==strcmp(parameter,"FRAME_US")){ sscanf(value, "%" SCNu32 , &conf.frame_us); } @@ -322,12 +332,44 @@ henglongconf_t getconfig(char* conffilename) } +typedef struct cam_ctrl_thread_t +{ + char* ip; + int up, down, cw, ccw, end; + uint32_t caminterval; +} cam_ctrl_thread_t; + + +void *cam_ctrl_thread_fcn(void* arg) +{ + printf("pthread cam_ctrl started\n"); + + cam_ctrl_thread_t* args; + + args = (cam_ctrl_thread_t*) arg; + + while(!args->end){ + usleep(args->caminterval); + if(args->up) cam_up(args->ip); + if(args->down) cam_down(args->ip); + if(args->cw) cam_cw(args->ip); + if(args->ccw) cam_ccw(args->ip); + } + + pthread_exit(0); +} + + int main(int argc, char* argv[]) { - pthread_t keybthread, joythread, refl_thread; + + + + pthread_t keybthread, joythread, refl_thread, cam_ctrl_thread; input_thread_t keyboard_thread_args; input_thread_t joystick_thread_args; refl_thread_args_t refl_thread_args; + cam_ctrl_thread_t cam_ctrl_thread_args; int frame = 0; uint16_t frame_nbr; int sockfd, n_send; @@ -335,6 +377,7 @@ int main(int argc, char* argv[]) uint64_t time_us; henglongconf_t conf; RCdatagram_t senddata; + int updown, cwccw; 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"); @@ -361,6 +404,19 @@ int main(int argc, char* argv[]) }else{ printf("no joystick!\n"); } + if(conf.cam[0]){ + cam_ctrl_thread_args.down = 0; + cam_ctrl_thread_args.up = 0; + cam_ctrl_thread_args.cw = 0; + cam_ctrl_thread_args.ccw = 0; + cam_ctrl_thread_args.end = 0; + cam_ctrl_thread_args.ip = conf.cam; + cam_ctrl_thread_args.caminterval = conf.caminterval; + if (pthread_create(&cam_ctrl_thread, NULL, cam_ctrl_thread_fcn , (void *) &cam_ctrl_thread_args)) printf("failed to create cam_ctrl thread\n"); + }else{ + printf("no cam config!\n"); + } + sockfd = socket(AF_INET,SOCK_DGRAM,0); @@ -398,8 +454,33 @@ int main(int argc, char* argv[]) senddata.outtty.motor_l = keyboard_thread_args.outtty.motor_l + joystick_thread_args.outtty.motor_l; senddata.outtty.motor_r = keyboard_thread_args.outtty.motor_r + joystick_thread_args.outtty.motor_r; - senddata.outtty.servo_pan += keyboard_thread_args.hl.pan_right - keyboard_thread_args.hl.pan_left + joystick_thread_args.hl.pan_right - joystick_thread_args.hl.pan_left; - senddata.outtty.servo_tilt += keyboard_thread_args.hl.tilt_up - keyboard_thread_args.hl.tilt_down + joystick_thread_args.hl.tilt_up - joystick_thread_args.hl.tilt_down; + cwccw = keyboard_thread_args.hl.pan_right - keyboard_thread_args.hl.pan_left + joystick_thread_args.hl.pan_right - joystick_thread_args.hl.pan_left; + updown = keyboard_thread_args.hl.tilt_up - keyboard_thread_args.hl.tilt_down + joystick_thread_args.hl.tilt_up - joystick_thread_args.hl.tilt_down; + + senddata.outtty.servo_pan += cwccw; + senddata.outtty.servo_tilt += updown; + + if(+1<=cwccw) { + cam_ctrl_thread_args.ccw = 1; + cam_ctrl_thread_args.cw = 0; + }else if(-1>=cwccw){ + cam_ctrl_thread_args.ccw = 0; + cam_ctrl_thread_args.cw = 1; + }else{ + cam_ctrl_thread_args.ccw = 0; + cam_ctrl_thread_args.cw = 0; + } + if(+1<=updown) { + cam_ctrl_thread_args.up = 1; + cam_ctrl_thread_args.down = 0; + }else if(-1>=updown){ + cam_ctrl_thread_args.up = 0; + cam_ctrl_thread_args.down = 1; + }else{ + cam_ctrl_thread_args.up = 0; + cam_ctrl_thread_args.down = 0; + } + if(keyboard_thread_args.hl.ignation | joystick_thread_args.hl.ignation){ senddata.outtty.servo_pan = 0; diff --git a/main.h b/main.h new file mode 100644 index 0000000..e69de29 diff --git a/obj/Debug/henglong.o b/obj/Debug/henglong.o index 5c890b8..2f9e69a 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 3ca2d68..d8f21b0 100644 Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ diff --git a/obj/Debug/wansview.o b/obj/Debug/wansview.o new file mode 100644 index 0000000..1b1424b Binary files /dev/null and b/obj/Debug/wansview.o differ diff --git a/wansview.c b/wansview.c new file mode 100644 index 0000000..f9a7a68 --- /dev/null +++ b/wansview.c @@ -0,0 +1,71 @@ + + +#include "wansview.h" + +int wvcamctrl(char* ip, int cmd) +{ + int sockfd = 0, n = 0; + char recvBuff[1024]; + char sendBuff[1024]; + struct sockaddr_in serv_addr; + + memset(recvBuff, '0',sizeof(recvBuff)); + if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + printf("\n Error : Could not create socket \n"); + return 1; + } + + memset(&serv_addr, '0', sizeof(serv_addr)); + + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(80); + + if(inet_pton(AF_INET, ip, &serv_addr.sin_addr)<=0) + { + printf("\n inet_pton error occured\n"); + return 1; + } + + if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + printf("\n Error : Connect Failed \n"); + return 1; + } + + sprintf(sendBuff, "GET /decoder_control.cgi?onestep=1&command=%d&user=chch&pwd=chch HTTP/1.1\r\nHost: %s\r\n\r\n", cmd, ip); + + n = write(sockfd, sendBuff, strlen(sendBuff)); + + while ( (n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) > 0) + { + } + + + if(n < 0) + { + printf("\n Read error \n"); + } + close(sockfd); + return 0; +} + +int cam_down(char* ip) +{ + return wvcamctrl(ip, 0); +} + +int cam_up(char* ip) +{ + return wvcamctrl(ip, 2); +} + +int cam_cw(char* ip) +{ + return wvcamctrl(ip, 4); +} + +int cam_ccw(char* ip) +{ + return wvcamctrl(ip, 6); +} diff --git a/wansview.h b/wansview.h new file mode 100644 index 0000000..1c0b9f8 --- /dev/null +++ b/wansview.h @@ -0,0 +1,17 @@ +#ifndef WANSVIEW_H_INCLUDED +#define WANSVIEW_H_INCLUDED + +#include +#include +#include +#include + + + +int wvcamctrl(char* ip, int cmd); +int cam_down(char* ip); +int cam_up(char* ip); +int cam_cw(char* ip); +int cam_ccw(char* ip); + +#endif // WANSVIEW_H_INCLUDED