mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-07 04:16:26 +02:00
Minor changes
This commit is contained in:
parent
e0fdde7cd0
commit
33c5443794
4 changed files with 37 additions and 6 deletions
2
Makefile
2
Makefile
|
@ -20,12 +20,12 @@ logger: src/logger.c src/utils.c config.mk
|
||||||
$(CC) $(filter-out config.mk,$^) -o $@ $(MACROS)
|
$(CC) $(filter-out config.mk,$^) -o $@ $(MACROS)
|
||||||
|
|
||||||
publish: publisher logger
|
publish: publisher logger
|
||||||
[ -f pid ] && { kill $(shell cat pid); rm pid; }
|
|
||||||
for client in $$(basename -a /home/loic/registers/*); \
|
for client in $$(basename -a /home/loic/registers/*); \
|
||||||
do \
|
do \
|
||||||
./logger $(LOGGERS_DIR) $$client $(LOG_INTERVAL) &> logger_$${client}.log & echo $$! >> pid; \
|
./logger $(LOGGERS_DIR) $$client $(LOG_INTERVAL) &> logger_$${client}.log & echo $$! >> pid; \
|
||||||
done
|
done
|
||||||
./publisher $(LOGGERS_DIR) $(LOG_INTERVAL) $(SUBSCRIBER_ADDR) $(ZMQ_PORT) $(KEY)
|
./publisher $(LOGGERS_DIR) $(LOG_INTERVAL) $(SUBSCRIBER_ADDR) $(ZMQ_PORT) $(KEY)
|
||||||
|
[ -f pid ] && { kill -INT $(shell cat pid); rm pid; }
|
||||||
|
|
||||||
subscribe: subscriber
|
subscribe: subscriber
|
||||||
./subscriber $(ZMQ_PORT) $(SUBSCRIBER_DIR)
|
./subscriber $(ZMQ_PORT) $(SUBSCRIBER_DIR)
|
||||||
|
|
12
src/logger.c
12
src/logger.c
|
@ -8,6 +8,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#ifndef LOGGER_DELAY
|
#ifndef LOGGER_DELAY
|
||||||
#define LOGGER_DELAY 0
|
#define LOGGER_DELAY 0
|
||||||
|
@ -18,6 +19,14 @@ char *__client;
|
||||||
char __logdir[STATIC_LEN];
|
char __logdir[STATIC_LEN];
|
||||||
char __regpower[STATIC_LEN];
|
char __regpower[STATIC_LEN];
|
||||||
int __loginterval;
|
int __loginterval;
|
||||||
|
unsigned char __stop=0;
|
||||||
|
|
||||||
|
void sighandler(int signo){
|
||||||
|
if (signo == SIGINT){
|
||||||
|
printf("Stopping...\n");
|
||||||
|
__stop=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv [])
|
int main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
|
@ -41,6 +50,7 @@ int main (int argc, char *argv [])
|
||||||
strcat(__regpower,INA260_POWER_REGISTER);
|
strcat(__regpower,INA260_POWER_REGISTER);
|
||||||
|
|
||||||
//----- Sanity checks
|
//----- Sanity checks
|
||||||
|
signal(SIGINT,sighandler);
|
||||||
mkdirp(__logdir);
|
mkdirp(__logdir);
|
||||||
if(__loginterval<MIN_INTERVAL){
|
if(__loginterval<MIN_INTERVAL){
|
||||||
printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL);
|
printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL);
|
||||||
|
@ -62,7 +72,7 @@ int main (int argc, char *argv [])
|
||||||
time_t interval;
|
time_t interval;
|
||||||
struct timespec power_ts;
|
struct timespec power_ts;
|
||||||
|
|
||||||
while(1){
|
while(!__stop){
|
||||||
interval=INTERVAL(__loginterval);
|
interval=INTERVAL(__loginterval);
|
||||||
*logfilepath='\0';
|
*logfilepath='\0';
|
||||||
sprintf(logfilepath,"%s/%ld",__logdir,interval);
|
sprintf(logfilepath,"%s/%ld",__logdir,interval);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
@ -12,9 +13,17 @@ char *__interface;
|
||||||
char *__ip;
|
char *__ip;
|
||||||
int __loginterval;
|
int __loginterval;
|
||||||
int __port;
|
int __port;
|
||||||
|
unsigned char __stop=0;
|
||||||
|
|
||||||
void publish(void *publisher, char *filepath, char* client, long int interval);
|
void publish(void *publisher, char *filepath, char* client, long int interval);
|
||||||
|
|
||||||
|
void sighandler(int signo){
|
||||||
|
if (signo == SIGINT){
|
||||||
|
printf("Stopping...\n");
|
||||||
|
__stop=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv [])
|
int main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
if(argc != 6){
|
if(argc != 6){
|
||||||
|
@ -30,6 +39,7 @@ int main (int argc, char *argv [])
|
||||||
__key=argv[5];
|
__key=argv[5];
|
||||||
|
|
||||||
//----- Sanity checks
|
//----- Sanity checks
|
||||||
|
signal(SIGINT,sighandler);
|
||||||
if(__loginterval<MIN_INTERVAL){
|
if(__loginterval<MIN_INTERVAL){
|
||||||
printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL);
|
printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL);
|
||||||
exit(2);
|
exit(2);
|
||||||
|
@ -48,7 +58,7 @@ int main (int argc, char *argv [])
|
||||||
|
|
||||||
//----- Start publisher
|
//----- Start publisher
|
||||||
struct dirent *de; // Pointer for directory entry
|
struct dirent *de; // Pointer for directory entry
|
||||||
while(1){
|
while(!__stop){
|
||||||
int interval=INTERVAL(__loginterval);
|
int interval=INTERVAL(__loginterval);
|
||||||
int interval_next=INTERVAL_NEXT(__loginterval);
|
int interval_next=INTERVAL_NEXT(__loginterval);
|
||||||
DIR *dr = opendir(__logdir);
|
DIR *dr = opendir(__logdir);
|
||||||
|
@ -63,7 +73,7 @@ int main (int argc, char *argv [])
|
||||||
// As long as next logfile is not available, we should wait
|
// As long as next logfile is not available, we should wait
|
||||||
// for sending the current one
|
// for sending the current one
|
||||||
printf("Waiting for %s logger measurements...\n",client);
|
printf("Waiting for %s logger measurements...\n",client);
|
||||||
while(!FILE_EXISTS(logfile_next)){
|
while(!FILE_EXISTS(logfile_next) && (!__stop)){
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
// Send current one
|
// Send current one
|
||||||
|
|
|
@ -2,9 +2,17 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
unsigned char __stop=0;
|
||||||
|
void sighandler(int signo){
|
||||||
|
if (signo == SIGINT){
|
||||||
|
printf("Stopping...\n");
|
||||||
|
__stop=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv [])
|
int main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
if(argc != 3){
|
if(argc != 3){
|
||||||
|
@ -18,6 +26,7 @@ int main (int argc, char *argv [])
|
||||||
|
|
||||||
//----- Various inits
|
//----- Various inits
|
||||||
mkdirp(cdatadir);
|
mkdirp(cdatadir);
|
||||||
|
signal(SIGINT,sighandler);
|
||||||
|
|
||||||
//----- Init ZMQ
|
//----- Init ZMQ
|
||||||
void *context = zmq_ctx_new ();
|
void *context = zmq_ctx_new ();
|
||||||
|
@ -35,8 +44,10 @@ int main (int argc, char *argv [])
|
||||||
//----- Listen
|
//----- Listen
|
||||||
char buffer[ZMQ_MSG_SIZE];
|
char buffer[ZMQ_MSG_SIZE];
|
||||||
int size;
|
int size;
|
||||||
while(1){
|
while(!__stop){
|
||||||
size=zmq_recv (subscriber, buffer, ZMQ_MSG_SIZE-1, 0);
|
size=zmq_recv (subscriber, buffer, ZMQ_MSG_SIZE-1, 0);
|
||||||
|
if(size<=0)
|
||||||
|
continue;
|
||||||
buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0';
|
buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0';
|
||||||
//----- Read buffer
|
//----- Read buffer
|
||||||
char *token = strtok(buffer, "\n");
|
char *token = strtok(buffer, "\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue