Minor changes

This commit is contained in:
Loic Guegan 2023-07-17 19:06:16 +02:00
parent 7f55253d26
commit a32c39d8a5

View file

@ -32,6 +32,7 @@ void publish(int queue_id, void* publisher);
typedef struct queue {
int size;
char issending;
char msg[ZMQ_MSG_SIZE];
} queue;
queue queues[MAX_QUEUES];
@ -97,10 +98,17 @@ int main (int argc, char *argv [])
struct timespec power_ts;
int queue_id=0;
// Init queues
for(int i=0;i<MAX_QUEUES;i++){
queues[queue_id].issending=0;
}
while(!__stop){
interval=INTERVAL(__loginterval);
// Log current interval
queue_id=(queue_id+1)>=MAX_QUEUES ? 0 : (queue_id+1);
// Busy wait:
while(queues[queue_id].issending){};
// Write msg header:
*queues[queue_id].msg='\0';
sprintf(queues[queue_id].msg,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,__client,interval);
@ -128,6 +136,7 @@ int main (int argc, char *argv [])
#endif
//printf("Tick\n"); fflush(stdout);
}
queues[queue_id].issending=1;
publish(queue_id,publisher);
}
@ -142,5 +151,6 @@ int main (int argc, char *argv [])
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");
}