diff --git a/UDPclient.depend b/UDPclient.depend index 02a5400..3b36cdc 100644 --- a/UDPclient.depend +++ b/UDPclient.depend @@ -29,7 +29,7 @@ -1395763961 source:/home/chch/HengLongUDPclient/main.c +1395876570 source:/home/chch/HengLongUDPclient/main.c @@ -53,6 +53,7 @@ "wansview.h" "extern.h" + "checkvideo.h" 1395699958 /home/chch/HengLongUDPclient/henglong.h @@ -110,7 +111,7 @@ -1395763555 source:/home/chch/HengLongUDPclient/wansview.c +1395764006 source:/home/chch/HengLongUDPclient/wansview.c "wansview.h" 1395529103 source:/root/HengLongUDPclient/henglong.c @@ -165,3 +166,12 @@ 1395699958 /home/chch/HengLongUDPclient/extern.h +1395871885 /home/chch/HengLongUDPclient/checkvideo.h + + + + + +1395876458 source:/home/chch/HengLongUDPclient/checkvideo.c + "checkvideo.h" + diff --git a/UDPclient.layout b/UDPclient.layout index 3b75491..a0d800b 100644 --- a/UDPclient.layout +++ b/UDPclient.layout @@ -1,13 +1,13 @@ - - + + - + - + @@ -17,12 +17,12 @@ - + - - + + - - + + diff --git a/bin/Debug/UDPclient b/bin/Debug/UDPclient index 6c7748b..9442034 100755 Binary files a/bin/Debug/UDPclient and b/bin/Debug/UDPclient differ diff --git a/checkvideo.c b/checkvideo.c new file mode 100644 index 0000000..576ba3f --- /dev/null +++ b/checkvideo.c @@ -0,0 +1,32 @@ + +#include "checkvideo.h" + +int connectionstate(char* remip, uint16_t remport) +{ + FILE* tcpfile; + char line[256]; + uint32_t remipi; + uint32_t remporti; + uint32_t statei; + + statei = 0; + remipi = 0; + remporti = 0; + tcpfile = fopen("/proc/net/tcp","r"); + while(fgets(line,256,tcpfile)){ + sscanf(line, "%*u: %*x:%*x %x:%x %x", &remipi, &remporti, &statei); + if((inet_addr(remip)==remipi) & (remport==remporti)) { + fclose(tcpfile); + return statei; + } + } + fclose(tcpfile); + return 0; +} + +int checkvideo(char* remip, uint16_t remport) +{ + if(0==remip[0]) return 2; + if(1==connectionstate(remip, remport)) return 1; + return 0; +} diff --git a/checkvideo.h b/checkvideo.h new file mode 100644 index 0000000..39ef5f0 --- /dev/null +++ b/checkvideo.h @@ -0,0 +1,12 @@ +#ifndef CHECKVIDEO_H_INCLUDED +#define CHECKVIDEO_H_INCLUDED + +#include +#include +#include +#include + +int connectionstate(char* remip, uint16_t remport); +int checkvideo(char* remip, uint16_t remport); + +#endif // CHECKVIDEO_H_INCLUDED diff --git a/client.config b/client.config index d5d920c..859ca9b 100644 --- a/client.config +++ b/client.config @@ -5,6 +5,7 @@ CAMINTERVAL 100000 USER admin PWD 123456 FRAME_US 100000 -SERVER 192.168.1.18:32000 +SERVER 192.168.1.13:32000 TIMEOUT 250 CLINBR 0 +VIDEO 192.168.1.20:8080 diff --git a/main.c b/main.c index 4ada16f..5fdc451 100644 --- a/main.c +++ b/main.c @@ -23,6 +23,7 @@ #include #include "wansview.h" #include "extern.h" +#include "checkvideo.h" typedef struct outtty_t { @@ -264,10 +265,11 @@ typedef struct henglongconf_t char joystickdevname[256]; in_addr_t ip; // v4 only char cam[64]; + char video[16]; char user[64]; char pwd[64]; uint32_t caminterval; - uint16_t port; + uint16_t port, videoport; uint8_t timeout; uint8_t clinbr; } henglongconf_t; @@ -292,6 +294,8 @@ henglongconf_t getconfig(char* conffilename) conf.caminterval = 100000; conf.user[0] = 0; conf.pwd[0] = 0; + conf.video[0] = 0; + conf.videoport = 0; while(fgets(line, 256, configFile)){ sscanf(line, "%16s %256s", parameter, value); if(0==strcmp(parameter,"KEYBOARD")){ @@ -325,6 +329,9 @@ henglongconf_t getconfig(char* conffilename) if(0==strcmp(parameter,"CLINBR")){ sscanf(value, "%" SCNu8 , &conf.clinbr); } + if(0==strcmp(parameter,"VIDEO")){ + sscanf(value, "%16[^:]:%" SCNu16, conf.video, &conf.videoport); + } } return conf; } @@ -366,6 +373,7 @@ void *cam_ctrl_thread_fcn(void* arg) int main(int argc, char* argv[]) { + pthread_t keybthread, joythread, refl_thread, cam_ctrl_thread; input_thread_t keyboard_thread_args; input_thread_t joystick_thread_args; @@ -443,6 +451,11 @@ int main(int argc, char* argv[]) while(1){ usleep(conf.frame_us); + // do not send control commands if live video is not watched + if(0==checkvideo(conf.video, conf.videoport)){ + printf("No video stream connection from %s:%u, remote control locked!\n", conf.video, conf.videoport); + continue; + } frame = 0xc0ffee; time_us = get_us(); @@ -505,7 +518,7 @@ int main(int argc, char* argv[]) if(senddata.outtty.servo_tilt<-50) senddata.outtty.servo_tilt = -50; // Return-Button on Keyboard via Joystick-Fire for screenshot in Browser - if(0==fire_old & 1==joystick_thread_args.hl.fire){ + if((0==fire_old) & (1==joystick_thread_args.hl.fire)){ fire(); } fire_old = joystick_thread_args.hl.fire; diff --git a/obj/Debug/checkvideo.o b/obj/Debug/checkvideo.o new file mode 100644 index 0000000..4d5a8a3 Binary files /dev/null and b/obj/Debug/checkvideo.o differ diff --git a/obj/Debug/main.o b/obj/Debug/main.o index c052141..6eed1b5 100644 Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ