mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-19 04:09:45 +00:00
Minor changes
This commit is contained in:
parent
75a323118b
commit
5f0585f4d4
1 changed files with 31 additions and 6 deletions
35
src/logger.c
35
src/logger.c
|
@ -13,6 +13,7 @@
|
||||||
// Global:
|
// Global:
|
||||||
char *__client;
|
char *__client;
|
||||||
char *__ip;
|
char *__ip;
|
||||||
|
char *__key;
|
||||||
int __port;
|
int __port;
|
||||||
char __logdir[STATIC_LEN];
|
char __logdir[STATIC_LEN];
|
||||||
char __regpower[STATIC_LEN];
|
char __regpower[STATIC_LEN];
|
||||||
|
@ -38,6 +39,7 @@ typedef struct record {
|
||||||
|
|
||||||
typedef struct queue {
|
typedef struct queue {
|
||||||
int length;
|
int length;
|
||||||
|
int interval;
|
||||||
record records[RECORD_MAX];
|
record records[RECORD_MAX];
|
||||||
} queue;
|
} queue;
|
||||||
|
|
||||||
|
@ -45,8 +47,8 @@ queue queues[RECORD_QUEUES];
|
||||||
|
|
||||||
int main (int argc, char *argv [])
|
int main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
if(argc != 6){
|
if(argc != 7){
|
||||||
printf("Usage: %s <abslogdir> <client> <loginterval> <ip> <port>",argv[0]);
|
printf("Usage: %s <abslogdir> <client> <loginterval> <ip> <port> <key>",argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ int main (int argc, char *argv [])
|
||||||
__loginterval=atoi(argv[3]);
|
__loginterval=atoi(argv[3]);
|
||||||
__ip=argv[4];
|
__ip=argv[4];
|
||||||
__port=atoi(argv[5]);
|
__port=atoi(argv[5]);
|
||||||
|
__key=argv[6];
|
||||||
// __logdir:
|
// __logdir:
|
||||||
strcat(__logdir,argv[1]);
|
strcat(__logdir,argv[1]);
|
||||||
strcat(__logdir,"/");
|
strcat(__logdir,"/");
|
||||||
|
@ -107,6 +110,7 @@ int main (int argc, char *argv [])
|
||||||
interval=INTERVAL(__loginterval);
|
interval=INTERVAL(__loginterval);
|
||||||
// Log current interval
|
// Log current interval
|
||||||
queue_id=queue_id>=RECORD_QUEUES ? 0 : queue_id+1;
|
queue_id=queue_id>=RECORD_QUEUES ? 0 : queue_id+1;
|
||||||
|
queues[queue_id].interval=interval;
|
||||||
int record=0;
|
int record=0;
|
||||||
while((TIMESTAMP()-interval)<__loginterval){
|
while((TIMESTAMP()-interval)<__loginterval){
|
||||||
if(__stop)
|
if(__stop)
|
||||||
|
@ -142,8 +146,29 @@ int main (int argc, char *argv [])
|
||||||
|
|
||||||
|
|
||||||
void publish(int queue_id){
|
void publish(int queue_id){
|
||||||
for(int i=0;i<queues[queue_id].length;i++){
|
// Build message header:
|
||||||
printf("%d,%ld,%d\n",queues[queue_id].records[i].secs,queues[queue_id].records[i].nsecs,queues[queue_id].records[i].power);
|
char buffer[ZMQ_MSG_SIZE];
|
||||||
fflush(stdout);
|
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
Add a link
Reference in a new issue