summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-07-17 15:10:35 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2023-07-17 15:10:35 +0200
commit5f0585f4d431247fb93e6920b0388cb6d236c50d (patch)
tree1dd35d8c90a58557de415ab434cbae8c17524ee2 /src
parent75a323118b7cd5769039c25ea263eda3ad67809b (diff)
Minor changes
Diffstat (limited to 'src')
-rw-r--r--src/logger.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/logger.c b/src/logger.c
index e34ab5f..73c85ca 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -13,6 +13,7 @@
// Global:
char *__client;
char *__ip;
+char *__key;
int __port;
char __logdir[STATIC_LEN];
char __regpower[STATIC_LEN];
@@ -38,6 +39,7 @@ typedef struct record {
typedef struct queue {
int length;
+ int interval;
record records[RECORD_MAX];
} queue;
@@ -45,8 +47,8 @@ queue queues[RECORD_QUEUES];
int main (int argc, char *argv [])
{
- if(argc != 6){
- printf("Usage: %s <abslogdir> <client> <loginterval> <ip> <port>",argv[0]);
+ if(argc != 7){
+ printf("Usage: %s <abslogdir> <client> <loginterval> <ip> <port> <key>",argv[0]);
exit(1);
}
@@ -55,6 +57,7 @@ int main (int argc, char *argv [])
__loginterval=atoi(argv[3]);
__ip=argv[4];
__port=atoi(argv[5]);
+ __key=argv[6];
// __logdir:
strcat(__logdir,argv[1]);
strcat(__logdir,"/");
@@ -107,6 +110,7 @@ int main (int argc, char *argv [])
interval=INTERVAL(__loginterval);
// Log current interval
queue_id=queue_id>=RECORD_QUEUES ? 0 : queue_id+1;
+ queues[queue_id].interval=interval;
int record=0;
while((TIMESTAMP()-interval)<__loginterval){
if(__stop)
@@ -142,8 +146,29 @@ int main (int argc, char *argv [])
void publish(int queue_id){
- for(int i=0;i<queues[queue_id].length;i++){
- printf("%d,%ld,%d\n",queues[queue_id].records[i].secs,queues[queue_id].records[i].nsecs,queues[queue_id].records[i].power);
- fflush(stdout);
- }
+ // Build message header:
+ char buffer[ZMQ_MSG_SIZE];
+ sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,__client,queues[queue_id].interval);
+ int msglen=strlen(buffer);
+
+ // Put every lines in the buffer and send it
+ char line[STATIC_LEN];
+ for(int record=0;record<queues[queue_id].length;record++){
+ *line='\0';
+ sprintf(line,"%d,%ld,%d",queues[queue_id].records[record].secs,queues[queue_id].records[record].nsecs,queues[queue_id].records[record].power);
+ int linelength=strlen(line);
+ if((linelength+msglen) <ZMQ_MSG_SIZE){
+ strcat(buffer,line);
+ msglen+=linelength;
+ } else {
+ // It buffer is full, we send the message and create another one
+ zmq_send (__zmq_publisher, buffer, msglen, 0);
+ // Build new message header:
+ sprintf(buffer,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,__client,queues[queue_id].interval);
+ strcat(buffer,line);
+ msglen=strlen(buffer);
+ }
+ }
+ // Finally send the last message (or the only one)
+ zmq_send (__zmq_publisher, buffer, msglen, 0);
} \ No newline at end of file