Minor changes

This commit is contained in:
Loic Guegan 2023-07-17 20:29:37 +02:00
parent a32c39d8a5
commit 29ff963194
2 changed files with 25 additions and 9 deletions

View file

@ -17,7 +17,7 @@ subscriber: src/subscriber.c src/utils.c config.mk
$(CC) -lzmq $(filter-out config.mk,$^) -o $@ $(MACROS)
logger: src/logger.c src/utils.c config.mk
$(CC) -lzmq $(filter-out config.mk,$^) -o $@ $(MACROS)
$(CC) -lzmq -lpthread $(filter-out config.mk,$^) -o $@ $(MACROS)
publish: publisher logger
for client in $$(basename -a /sys/kernel/ina260/*); \

View file

@ -5,6 +5,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <signal.h>
#include <pthread.h>
#include "utils.h"
#ifndef LOGGERS_DELAY
@ -28,7 +29,7 @@ void sighandler(int signo){
}
}
void publish(int queue_id, void* publisher);
void *publish(void *publisher);
typedef struct queue {
int size;
@ -87,6 +88,7 @@ int main (int argc, char *argv [])
//----- Start logging
pthread_t zmq_thread;
printf("Logger started [client=%s,interval=%ds]\n",__client,__loginterval);
FILE *regptr,*logptr;
@ -102,6 +104,7 @@ int main (int argc, char *argv [])
for(int i=0;i<MAX_QUEUES;i++){
queues[queue_id].issending=0;
}
pthread_create(&zmq_thread, NULL, publish, publisher);
while(!__stop){
interval=INTERVAL(__loginterval);
@ -137,20 +140,33 @@ int main (int argc, char *argv [])
//printf("Tick\n"); fflush(stdout);
}
queues[queue_id].issending=1;
publish(queue_id,publisher);
}
fclose(regptr);
pthread_join(zmq_thread, NULL);
zmq_close (publisher);
zmq_ctx_destroy (context);
return 0;
}
void publish(int queue_id, void* publisher){
printf("Publishing...");
zmq_send(publisher,queues[queue_id].msg,queues[queue_id].size,0);
queues[queue_id].issending=0;
printf("done\n");
void *publish(void *publisher){
int queue_id=0;
while(!__stop){
if(queues[queue_id].issending){
printf("Publishing...");
zmq_send(publisher,queues[queue_id].msg,queues[queue_id].size,0);
queues[queue_id].issending=0;
printf("done\n");
} else {
#if LOGGERS_DELAY > 0
usleep(LOGGERS_DELAY*1000);
#endif
continue;
}
queue_id++;
if(queue_id>=MAX_QUEUES)
queue_id=0;
}
pthread_exit(EXIT_SUCCESS);
}