fix weatherdaemon for new usefull_macros

This commit is contained in:
2025-06-23 11:08:39 +03:00
parent cc8e915546
commit 453a56429d
34 changed files with 2979 additions and 354 deletions

View File

@@ -39,7 +39,7 @@
extern glob_pars *GP;
static char *answer = NULL;
static char answer[BUFSIZ] = {0};
static int freshdata = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -156,7 +156,7 @@ static int handle_socket(int sock, int notchkhdr){
return 1;
}
}
if(answer) send_data(sock, webquery, answer);
if(*answer) send_data(sock, webquery, answer);
else send_data(sock, webquery, "No data\n");
if(webquery) return 1; // close web query after message processing
return 0;
@@ -178,7 +178,7 @@ static void *server(void *asock){
memset(notchkhdr, 0, sizeof(notchkhdr));
poll_set[0].fd = sock;
poll_set[0].events = POLLIN;
double lastdatat = dtime();
double lastdatat = sl_dtime();
while(1){
poll(poll_set, nfd, 1); // poll for 1ms
for(int fdidx = 0; fdidx < nfd; ++fdidx){ // poll opened FDs
@@ -223,15 +223,15 @@ static void *server(void *asock){
}
}
} // endfor
if(freshdata && answer){ // send new data to all
if(freshdata){ // send new data to all
freshdata = 0;
lastdatat = dtime();
lastdatat = sl_dtime();
for(int fdidx = 1; fdidx < nfd; ++fdidx){
if(notchkhdr[fdidx])
send_data(poll_set[fdidx].fd, 0, answer);
}
}
if(dtime() - lastdatat > NODATA_TMOUT){
if(sl_dtime() - lastdatat > NODATA_TMOUT){
LOGERR("No data timeout");
ERRX("No data timeout");
}
@@ -242,16 +242,14 @@ static void *server(void *asock){
static void *ttyparser(_U_ void *notused){
double tlast = 0;
while(1){
if(dtime() - tlast > T_INTERVAL){
char *got = poll_device();
if(sl_dtime() - tlast > T_INTERVAL){
char *got = poll_device(answer, BUFSIZ);
if(got){
if (0 == pthread_mutex_lock(&mutex)){
FREE(answer);
answer = strdup(got);
if(0 == pthread_mutex_lock(&mutex)){
freshdata = 1;
pthread_mutex_unlock(&mutex);
}
tlast = dtime();
tlast = sl_dtime();
}
}
sleep(1);