diff --git a/Makefile b/Makefile index 7d032f4..692f123 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,20 @@ include $(CONF) CC="gcc" CFLAGS= +MACROS=\ +-DZMQ_TOKEN=\"$(ZMQ_TOKEN)\" \ +-DZMQ_MSG_SIZE=$(ZMQ_MSG_SIZE) + all: publisher subscriber logger publisher: src/publisher.c src/utils.c - $(CC) -lzmq $^ -o $@ + $(CC) -lzmq $^ -o $@ $(MACROS) subscriber: src/subscriber.c src/utils.c - $(CC) -lzmq $^ -o $@ + $(CC) -lzmq $^ -o $@ $(MACROS) logger: src/logger.c src/utils.c - $(CC) $^ -o $@ + $(CC) $^ -o $@ $(MACROS) publish: publisher logger [ -f pid ] && { kill $(shell cat pid); rm pid; } diff --git a/config.mk b/config.mk index 40409b2..020550b 100644 --- a/config.mk +++ b/config.mk @@ -1,6 +1,12 @@ ##### ZeroMQ ZMQ_PORT=5556 SUBSCRIBER_ADDR=localhost +# ZMQ_TOKEN is used by ZeroMQ to detect +# messages from publishers. Leave as is if not sure. +ZMQ_TOKEN="ina260-zmq-publisher" +# ZMQ_MSG_SIZE max number of bytes per ZeroMQ messages +# be careful with this parameter +ZMQ_MSG_SIZE=2550 ##### Logger/Publisher # LOGGERS_DIR will contains all the data generated by the loggers diff --git a/src/publisher.c b/src/publisher.c index 7c401c4..56fea78 100644 --- a/src/publisher.c +++ b/src/publisher.c @@ -17,6 +17,7 @@ void publish(void *publisher, char *filepath, char* client, long int interval); int main (int argc, char *argv []) { + printf("%d\n",ZMQ_MSG_SIZE); if(argc != 6){ printf("Usage: %s ",argv[0]); exit(1); diff --git a/src/utils.h b/src/utils.h index 4fd6b68..d427d01 100644 --- a/src/utils.h +++ b/src/utils.h @@ -8,25 +8,24 @@ #define MIN_INTERVAL 30 #define INA260_SYSFS "/sys/kernel/ina260" #define INA260_POWER_REGISTER "registers/power" + #ifndef ZMQ_TOKEN #define ZMQ_TOKEN "ina260-zmq-publisher" #endif + +#ifndef ZMQ_MSG_SIZE #define ZMQ_MSG_SIZE 255*10 +#endif #define STR(symbol) #symbol #define STRINGIFY(symbol) STR(symbol) - #define TIMESTAMP() (time(NULL)) - #define INTERVAL(duration)\ ((TIMESTAMP()) - ((TIMESTAMP())%(duration))) - #define INTERVAL_NEXT(duration)\ ((INTERVAL(duration))+(duration)) - #define INTERVAL_LAST(duration)\ (INTERVAL(INTERVAL((TIMESTAMP()),(duration))-1,(duration))) - #define FILE_EXISTS(path) (access((path), F_OK) == 0) void mkdirp(char *path); \ No newline at end of file