mirror of
https://github.com/TheTesla/HengLongUDPclient.git
synced 2025-04-10 11:40:16 +02:00
killswitch in extra thread for lower control delay
This commit is contained in:
parent
ceb1edb67b
commit
824ec1c1d9
11 changed files with 55 additions and 10 deletions
|
@ -176,10 +176,10 @@
|
|||
1395878369 source:/home/chch/HengLongUDPclient/checkvideo.c
|
||||
"checkvideo.h"
|
||||
|
||||
1396205007 source:/home/chch/HengLongUDPclient/checkkillswitch.c
|
||||
1396457823 source:/home/chch/HengLongUDPclient/checkkillswitch.c
|
||||
"checkkillswitch.h"
|
||||
|
||||
1396202748 /home/chch/HengLongUDPclient/checkkillswitch.h
|
||||
1396457833 /home/chch/HengLongUDPclient/checkkillswitch.h
|
||||
<stdio.h>
|
||||
<string.h>
|
||||
<unistd.h>
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -2,12 +2,15 @@
|
|||
#include "checkkillswitch.h"
|
||||
|
||||
|
||||
int getPage(char* ip, uint16_t port, char* url, char* recvBuffer, uint32_t size)
|
||||
int getPage(char* ip, uint16_t port, char* url, char* recvBuffer, uint32_t size, uint32_t timeout_us)
|
||||
{
|
||||
int sockfd = 0, n = 0;
|
||||
//char recvBuff[1024];
|
||||
char sendBuff[1024];
|
||||
struct sockaddr_in serv_addr;
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = timeout_us/1000000;
|
||||
timeout.tv_usec = timeout_us;
|
||||
|
||||
memset(recvBuffer, '0',size);
|
||||
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
|
@ -27,6 +30,9 @@ int getPage(char* ip, uint16_t port, char* url, char* recvBuffer, uint32_t size)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (setsockopt (sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) printf("setsockopt failed\n");
|
||||
if (setsockopt (sockfd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) printf("setsockopt failed\n");
|
||||
|
||||
if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
|
||||
{
|
||||
printf("\n Error : Connect Failed \n");
|
||||
|
@ -48,12 +54,12 @@ int getPage(char* ip, uint16_t port, char* url, char* recvBuffer, uint32_t size)
|
|||
return n;
|
||||
}
|
||||
|
||||
int checkkillswitch(char* ip, uint16_t port, char* url)
|
||||
int checkkillswitch(char* ip, uint16_t port, char* url, uint32_t timeout_us)
|
||||
{
|
||||
char rb[1024];
|
||||
int n;
|
||||
if(0==ip[0]) return 1;
|
||||
getPage(ip, port, url, rb, sizeof(rb));
|
||||
getPage(ip, port, url, rb, sizeof(rb), timeout_us);
|
||||
n = strstr(rb, "true");
|
||||
if(NULL != n) return 1;
|
||||
return 0;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <sys/time.h>
|
||||
|
||||
|
||||
int getPage(char* ip, uint16_t port, char* url, char* recvBuffer, uint32_t size);
|
||||
int checkkillswitch(char* ip, uint16_t port, char* url);
|
||||
int getPage(char* ip, uint16_t port, char* url, char* recvBuffer, uint32_t size, uint32_t timeout_us);
|
||||
int checkkillswitch(char* ip, uint16_t port, char* url, uint32_t timeout_us);
|
||||
|
||||
#endif // CHECKKILLSWITCH_H_INCLUDED
|
||||
|
|
|
@ -10,3 +10,4 @@ TIMEOUT 250
|
|||
CLINBR 0
|
||||
VIDEO 192.168.1.66:8080
|
||||
KILLSW 192.168.1.20:8080/status
|
||||
KILLSWTO_US 600000
|
||||
|
|
44
main.c
44
main.c
|
@ -275,6 +275,7 @@ typedef struct henglongconf_t
|
|||
uint16_t port, videoport, killport;
|
||||
uint8_t timeout;
|
||||
uint8_t clinbr;
|
||||
uint32_t killswtimeoutus;
|
||||
} henglongconf_t;
|
||||
|
||||
henglongconf_t getconfig(char* conffilename)
|
||||
|
@ -302,6 +303,7 @@ henglongconf_t getconfig(char* conffilename)
|
|||
conf.killsw[0] = 0;
|
||||
conf.killport = 0;
|
||||
conf.killurl[0] = 0;
|
||||
conf.killswtimeoutus = 500000;
|
||||
while(fgets(line, 256, configFile)){
|
||||
sscanf(line, "%16s %256s", parameter, value);
|
||||
if(0==strcmp(parameter,"KEYBOARD")){
|
||||
|
@ -341,6 +343,9 @@ henglongconf_t getconfig(char* conffilename)
|
|||
if(0==strcmp(parameter,"KILLSW")){
|
||||
sscanf(value, "%16[^:]:%" SCNu16 "%256s", conf.killsw, &conf.killport, conf.killurl);
|
||||
}
|
||||
if(0==strcmp(parameter,"KILLSWTO_US")){
|
||||
sscanf(value, "%" SCNu32 , &conf.killswtimeoutus);
|
||||
}
|
||||
}
|
||||
return conf;
|
||||
}
|
||||
|
@ -380,14 +385,37 @@ void *cam_ctrl_thread_fcn(void* arg)
|
|||
}
|
||||
|
||||
|
||||
typedef struct killsw_thread_t
|
||||
{
|
||||
char* ip;
|
||||
uint16_t port;
|
||||
char* url;
|
||||
uint32_t timeout_us;
|
||||
int state;
|
||||
} killsw_thread_t;
|
||||
|
||||
void *killsw_thread_fcn(void* arg)
|
||||
{
|
||||
printf("pthread killsw started\n");
|
||||
killsw_thread_t* args;
|
||||
args = (killsw_thread_t*) arg;
|
||||
args->state = 0;
|
||||
while(1){
|
||||
args->state = checkkillswitch(args->ip, args->port, args->url, args->timeout_us);
|
||||
}
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
|
||||
pthread_t keybthread, joythread, refl_thread, cam_ctrl_thread;
|
||||
pthread_t keybthread, joythread, refl_thread, cam_ctrl_thread, killsw_thread;
|
||||
input_thread_t keyboard_thread_args;
|
||||
input_thread_t joystick_thread_args;
|
||||
refl_thread_args_t refl_thread_args;
|
||||
killsw_thread_t killsw_thread_args;
|
||||
cam_ctrl_thread_t cam_ctrl_thread_args;
|
||||
int frame = 0;
|
||||
uint16_t frame_nbr;
|
||||
|
@ -438,7 +466,17 @@ int main(int argc, char* argv[])
|
|||
}else{
|
||||
printf("no cam config!\n");
|
||||
}
|
||||
|
||||
killsw_thread_args.state = 1; // default, wenn kein Killswitch konfiguriert - immer an
|
||||
if(conf.killsw[0]){
|
||||
killsw_thread_args.ip = conf.killsw;
|
||||
killsw_thread_args.port = conf.killport;
|
||||
killsw_thread_args.url = conf.killurl;
|
||||
killsw_thread_args.state = 0;
|
||||
killsw_thread_args.timeout_us = conf.killswtimeoutus;
|
||||
if (pthread_create(&killsw_thread, NULL, killsw_thread_fcn , (void *) &killsw_thread_args)) printf("failed to create killsw thread\n");
|
||||
}else{
|
||||
printf("no killswitch!\n");
|
||||
}
|
||||
|
||||
sockfd = socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
|
@ -466,7 +504,7 @@ int main(int argc, char* argv[])
|
|||
printf("No video stream connection from %s:%u, remote control locked!\n", conf.video, conf.videoport);
|
||||
continue;
|
||||
}
|
||||
if(0==checkkillswitch(conf.killsw,conf.killport,conf.killurl)){
|
||||
if(0==killsw_thread_args.state){
|
||||
printf("Killswitch pressed or no connection.!\n");
|
||||
continue;
|
||||
}
|
||||
|
|
Binary file not shown.
BIN
obj/Debug/main.o
BIN
obj/Debug/main.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue