mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-10 08:20:27 +00:00
Minor changes
This commit is contained in:
parent
75a323118b
commit
5f0585f4d4
1 changed files with 31 additions and 6 deletions
37
src/logger.c
37
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);
|
||||
}
|
Loading…
Add table
Reference in a new issue