mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-12 17:18:38 +00:00
Minor changes
This commit is contained in:
parent
7f55253d26
commit
a32c39d8a5
1 changed files with 10 additions and 0 deletions
10
src/logger.c
10
src/logger.c
|
@ -32,6 +32,7 @@ void publish(int queue_id, void* publisher);
|
||||||
|
|
||||||
typedef struct queue {
|
typedef struct queue {
|
||||||
int size;
|
int size;
|
||||||
|
char issending;
|
||||||
char msg[ZMQ_MSG_SIZE];
|
char msg[ZMQ_MSG_SIZE];
|
||||||
} queue;
|
} queue;
|
||||||
queue queues[MAX_QUEUES];
|
queue queues[MAX_QUEUES];
|
||||||
|
@ -97,10 +98,17 @@ int main (int argc, char *argv [])
|
||||||
struct timespec power_ts;
|
struct timespec power_ts;
|
||||||
int queue_id=0;
|
int queue_id=0;
|
||||||
|
|
||||||
|
// Init queues
|
||||||
|
for(int i=0;i<MAX_QUEUES;i++){
|
||||||
|
queues[queue_id].issending=0;
|
||||||
|
}
|
||||||
|
|
||||||
while(!__stop){
|
while(!__stop){
|
||||||
interval=INTERVAL(__loginterval);
|
interval=INTERVAL(__loginterval);
|
||||||
// Log current interval
|
// Log current interval
|
||||||
queue_id=(queue_id+1)>=MAX_QUEUES ? 0 : (queue_id+1);
|
queue_id=(queue_id+1)>=MAX_QUEUES ? 0 : (queue_id+1);
|
||||||
|
// Busy wait:
|
||||||
|
while(queues[queue_id].issending){};
|
||||||
// Write msg header:
|
// Write msg header:
|
||||||
*queues[queue_id].msg='\0';
|
*queues[queue_id].msg='\0';
|
||||||
sprintf(queues[queue_id].msg,"%s\n%s\n%s\n%ld\n",ZMQ_TOKEN,__key,__client,interval);
|
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
|
#endif
|
||||||
//printf("Tick\n"); fflush(stdout);
|
//printf("Tick\n"); fflush(stdout);
|
||||||
}
|
}
|
||||||
|
queues[queue_id].issending=1;
|
||||||
publish(queue_id,publisher);
|
publish(queue_id,publisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,5 +151,6 @@ int main (int argc, char *argv [])
|
||||||
void publish(int queue_id, void* publisher){
|
void publish(int queue_id, void* publisher){
|
||||||
printf("Publishing...");
|
printf("Publishing...");
|
||||||
zmq_send(publisher,queues[queue_id].msg,queues[queue_id].size,0);
|
zmq_send(publisher,queues[queue_id].msg,queues[queue_id].size,0);
|
||||||
|
queues[queue_id].issending=0;
|
||||||
printf("done\n");
|
printf("done\n");
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue