summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-07-17 14:55:34 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2023-07-17 14:55:34 +0200
commit75a323118b7cd5769039c25ea263eda3ad67809b (patch)
tree9e2613b52d9680f2ef01266b54a78e925c305741
parente8417d7397564e2f16b484da357fe01f1c0ccf13 (diff)
Minor changes
-rw-r--r--Makefile2
-rw-r--r--src/logger.c25
2 files changed, 24 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 5456ca3..5ea15b4 100644
--- a/Makefile
+++ b/Makefile
@@ -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/*); \
diff --git a/src/logger.c b/src/logger.c
index 667627b..e34ab5f 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -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;
}