Minor changes

This commit is contained in:
Loic Guegan 2023-07-17 14:55:34 +02:00
parent e8417d7397
commit 75a323118b
2 changed files with 24 additions and 3 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) $(filter-out config.mk,$^) -o $@ $(MACROS)
$(CC) -lzmq $(filter-out config.mk,$^) -o $@ $(MACROS)
publish: publisher logger
for client in $$(basename -a /sys/kernel/ina260/*); \

View file

@ -12,10 +12,14 @@
// Global:
char *__client;
char *__ip;
int __port;
char __logdir[STATIC_LEN];
char __regpower[STATIC_LEN];
int __loginterval;
unsigned char __stop=0;
void *__zmq_context;
void *__zmq_publisher;
void sighandler(int signo){
if (signo == SIGINT){
@ -41,14 +45,16 @@ queue queues[RECORD_QUEUES];
int main (int argc, char *argv [])
{
if(argc != 4){
printf("Usage: %s <abslogdir> <client> <loginterval>",argv[0]);
if(argc != 6){
printf("Usage: %s <abslogdir> <client> <loginterval> <ip> <port>",argv[0]);
exit(1);
}
//----- Init global variables
__client=argv[2];
__loginterval=atoi(argv[3]);
__ip=argv[4];
__port=atoi(argv[5]);
// __logdir:
strcat(__logdir,argv[1]);
strcat(__logdir,"/");
@ -72,6 +78,19 @@ int main (int argc, char *argv [])
exit(3);
}
//----- Prepare our context and publisher
__zmq_context = zmq_ctx_new ();
__zmq_publisher = zmq_socket (__zmq_context, ZMQ_PUB);
char bindto[STATIC_LEN];
sprintf(bindto,"tcp://%s:%d",__ip,__port);
int rc = zmq_connect (__zmq_publisher, bindto);
if(rc!=0){
printf("Failed to connect to %s\n",bindto);
exit(1);
}
//----- Start logging
printf("Logger started [client=%s,interval=%ds]\n",__client,__loginterval);
@ -116,6 +135,8 @@ int main (int argc, char *argv [])
}
fclose(regptr);
zmq_close (__zmq_publisher);
zmq_ctx_destroy (__zmq_context);
return 0;
}