Minor changes

This commit is contained in:
Loic Guegan 2023-07-16 14:50:53 +02:00
parent e0fdde7cd0
commit 33c5443794
4 changed files with 37 additions and 6 deletions

View file

@ -20,12 +20,12 @@ logger: src/logger.c src/utils.c config.mk
$(CC) $(filter-out config.mk,$^) -o $@ $(MACROS)
publish: publisher logger
[ -f pid ] && { kill $(shell cat pid); rm pid; }
for client in $$(basename -a /home/loic/registers/*); \
do \
./logger $(LOGGERS_DIR) $$client $(LOG_INTERVAL) &> logger_$${client}.log & echo $$! >> pid; \
done
./publisher $(LOGGERS_DIR) $(LOG_INTERVAL) $(SUBSCRIBER_ADDR) $(ZMQ_PORT) $(KEY)
[ -f pid ] && { kill -INT $(shell cat pid); rm pid; }
subscribe: subscriber
./subscriber $(ZMQ_PORT) $(SUBSCRIBER_DIR)

View file

@ -8,6 +8,7 @@
#include <sys/stat.h>
#include "utils.h"
#include <time.h>
#include <signal.h>
#ifndef LOGGER_DELAY
#define LOGGER_DELAY 0
@ -18,6 +19,14 @@ char *__client;
char __logdir[STATIC_LEN];
char __regpower[STATIC_LEN];
int __loginterval;
unsigned char __stop=0;
void sighandler(int signo){
if (signo == SIGINT){
printf("Stopping...\n");
__stop=1;
}
}
int main (int argc, char *argv [])
{
@ -41,6 +50,7 @@ int main (int argc, char *argv [])
strcat(__regpower,INA260_POWER_REGISTER);
//----- Sanity checks
signal(SIGINT,sighandler);
mkdirp(__logdir);
if(__loginterval<MIN_INTERVAL){
printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL);
@ -62,7 +72,7 @@ int main (int argc, char *argv [])
time_t interval;
struct timespec power_ts;
while(1){
while(!__stop){
interval=INTERVAL(__loginterval);
*logfilepath='\0';
sprintf(logfilepath,"%s/%ld",__logdir,interval);

View file

@ -2,6 +2,7 @@
#include <assert.h>
#include <time.h>
#include <dirent.h>
#include <signal.h>
#include "utils.h"
@ -12,9 +13,17 @@ char *__interface;
char *__ip;
int __loginterval;
int __port;
unsigned char __stop=0;
void publish(void *publisher, char *filepath, char* client, long int interval);
void sighandler(int signo){
if (signo == SIGINT){
printf("Stopping...\n");
__stop=1;
}
}
int main (int argc, char *argv [])
{
if(argc != 6){
@ -30,6 +39,7 @@ int main (int argc, char *argv [])
__key=argv[5];
//----- Sanity checks
signal(SIGINT,sighandler);
if(__loginterval<MIN_INTERVAL){
printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL);
exit(2);
@ -48,7 +58,7 @@ int main (int argc, char *argv [])
//----- Start publisher
struct dirent *de; // Pointer for directory entry
while(1){
while(!__stop){
int interval=INTERVAL(__loginterval);
int interval_next=INTERVAL_NEXT(__loginterval);
DIR *dr = opendir(__logdir);
@ -63,7 +73,7 @@ int main (int argc, char *argv [])
// As long as next logfile is not available, we should wait
// for sending the current one
printf("Waiting for %s logger measurements...\n",client);
while(!FILE_EXISTS(logfile_next)){
while(!FILE_EXISTS(logfile_next) && (!__stop)){
sleep(1);
}
// Send current one

View file

@ -2,9 +2,17 @@
#include <assert.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include "utils.h"
unsigned char __stop=0;
void sighandler(int signo){
if (signo == SIGINT){
printf("Stopping...\n");
__stop=1;
}
}
int main (int argc, char *argv [])
{
if(argc != 3){
@ -18,6 +26,7 @@ int main (int argc, char *argv [])
//----- Various inits
mkdirp(cdatadir);
signal(SIGINT,sighandler);
//----- Init ZMQ
void *context = zmq_ctx_new ();
@ -35,8 +44,10 @@ int main (int argc, char *argv [])
//----- Listen
char buffer[ZMQ_MSG_SIZE];
int size;
while(1){
while(!__stop){
size=zmq_recv (subscriber, buffer, ZMQ_MSG_SIZE-1, 0);
if(size<=0)
continue;
buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0';
//----- Read buffer
char *token = strtok(buffer, "\n");