mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-05 11:26:25 +02:00
Debugging and improvements
This commit is contained in:
parent
d489fa8d6d
commit
ce5597547c
4 changed files with 21 additions and 9 deletions
3
Makefile
3
Makefile
|
@ -6,7 +6,8 @@ CFLAGS=
|
||||||
MACROS=\
|
MACROS=\
|
||||||
-DZMQ_TOKEN=\"$(ZMQ_TOKEN)\" \
|
-DZMQ_TOKEN=\"$(ZMQ_TOKEN)\" \
|
||||||
-DZMQ_MSG_SIZE=$(ZMQ_MSG_SIZE) \
|
-DZMQ_MSG_SIZE=$(ZMQ_MSG_SIZE) \
|
||||||
-DLOG_DELAY=$(LOG_DELAY)
|
-DLOG_DELAY=$(LOG_DELAY) \
|
||||||
|
-DMAX_QUEUE=$(MAX_QUEUE)
|
||||||
|
|
||||||
all: publisher subscriber
|
all: publisher subscriber
|
||||||
|
|
||||||
|
|
|
@ -28,4 +28,9 @@ LOG_INTERVAL=20
|
||||||
# KEY is attached to all the messages published to the subscriber
|
# KEY is attached to all the messages published to the subscriber
|
||||||
# It allows you to filter the messages on the publisher
|
# It allows you to filter the messages on the publisher
|
||||||
# if you are using multiple monitoring nodes (multiple publishers)
|
# if you are using multiple monitoring nodes (multiple publishers)
|
||||||
KEY=node1
|
KEY=node1
|
||||||
|
# MAX_QUEUE Maximum number of queues to use per publisher.
|
||||||
|
# It allows the zmq thread to send the power measurements to the subscriber meanwhile
|
||||||
|
# other measurements are collected. If only 1 queue is used, power measurements can
|
||||||
|
# potentially be missing since parallelism is broken.
|
||||||
|
MAX_QUEUE=2
|
|
@ -4,9 +4,12 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <zmq.h>
|
#include <zmq.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef LOG_DELAY
|
#ifndef LOG_DELAY
|
||||||
#define LOG_DELAY 0
|
#define LOG_DELAY 0
|
||||||
|
@ -82,9 +85,9 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
//----- Init logging variables
|
//----- Init logging variables
|
||||||
pthread_t zmq_thread;
|
pthread_t zmq_thread;
|
||||||
FILE *regptr, *logptr;
|
FILE *logptr;
|
||||||
char logfilepath[STATIC_LEN] = "";
|
char logfilepath[STATIC_LEN] = "";
|
||||||
regptr = fopen(regpower, "r");
|
int regfd = open(regpower, O_RDONLY);
|
||||||
char buffer[STATIC_LEN];
|
char buffer[STATIC_LEN];
|
||||||
time_t interval;
|
time_t interval;
|
||||||
struct timespec power_ts;
|
struct timespec power_ts;
|
||||||
|
@ -116,14 +119,14 @@ int main(int argc, char *argv[]) {
|
||||||
if (__stop)
|
if (__stop)
|
||||||
break;
|
break;
|
||||||
// Read power:
|
// Read power:
|
||||||
fgets(buffer, STATIC_LEN, regptr);
|
read(regfd, buffer, STATIC_LEN);
|
||||||
// Get power measurement timestamp:
|
// Get power measurement timestamp:
|
||||||
clock_gettime(CLOCK_REALTIME, &power_ts);
|
clock_gettime(CLOCK_REALTIME, &power_ts);
|
||||||
// Write measurement into msg buffer:
|
// Write measurement into msg buffer:
|
||||||
char line[MAX_RECORD_LEN];
|
char line[MAX_RECORD_LEN];
|
||||||
if ((queues[queue_id].size + MAX_RECORD_LEN) > ZMQ_MSG_SIZE) {
|
if ((queues[queue_id].size + MAX_RECORD_LEN) > ZMQ_MSG_SIZE) {
|
||||||
printf(
|
printf(
|
||||||
"To many measurements to publish. Please increase ZMQ_MSG_SIZE\n");
|
"Too many measurements to publish. Please increase ZMQ_MSG_SIZE\n");
|
||||||
} else {
|
} else {
|
||||||
sprintf(queues[queue_id].msg + queues[queue_id].size, "%ld,%ld,%d\n",
|
sprintf(queues[queue_id].msg + queues[queue_id].size, "%ld,%ld,%d\n",
|
||||||
power_ts.tv_sec, power_ts.tv_nsec, atoi(buffer));
|
power_ts.tv_sec, power_ts.tv_nsec, atoi(buffer));
|
||||||
|
@ -131,7 +134,7 @@ int main(int argc, char *argv[]) {
|
||||||
strlen(queues[queue_id].msg + queues[queue_id].size);
|
strlen(queues[queue_id].msg + queues[queue_id].size);
|
||||||
}
|
}
|
||||||
// Reset power register file:
|
// Reset power register file:
|
||||||
fseek(regptr, 0, SEEK_SET);
|
lseek(regfd,0,SEEK_SET);
|
||||||
#if LOG_DELAY > 0
|
#if LOG_DELAY > 0
|
||||||
usleep(LOG_DELAY * 1000);
|
usleep(LOG_DELAY * 1000);
|
||||||
#endif
|
#endif
|
||||||
|
@ -140,7 +143,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- Cleaning
|
//----- Cleaning
|
||||||
fclose(regptr);
|
close(regfd);
|
||||||
pthread_join(zmq_thread, NULL);
|
pthread_join(zmq_thread, NULL);
|
||||||
zmq_close(zmq_publisher);
|
zmq_close(zmq_publisher);
|
||||||
zmq_ctx_destroy(zmq_context);
|
zmq_ctx_destroy(zmq_context);
|
||||||
|
|
|
@ -11,9 +11,12 @@
|
||||||
#define INA260_POWER_REGISTER "registers/power"
|
#define INA260_POWER_REGISTER "registers/power"
|
||||||
#define STATIC_LEN 255
|
#define STATIC_LEN 255
|
||||||
#define MAX_RECORD_LEN 100
|
#define MAX_RECORD_LEN 100
|
||||||
#define MAX_QUEUES 1
|
|
||||||
#define CSV_HEADER "timestamp,nsecs,power"
|
#define CSV_HEADER "timestamp,nsecs,power"
|
||||||
|
|
||||||
|
#ifndef MAX_QUEUES
|
||||||
|
#define MAX_QUEUES 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ZMQ_TOKEN
|
#ifndef ZMQ_TOKEN
|
||||||
#define ZMQ_TOKEN "ina260-zmq-publisher"
|
#define ZMQ_TOKEN "ina260-zmq-publisher"
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue