ina260-zmq-publisher/src/utils.h

30 lines
705 B
C
Raw Normal View History

2023-07-15 10:31:36 +02:00
#pragma once
2023-07-15 10:11:50 +02:00
#include <time.h>
2023-07-15 10:31:36 +02:00
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
2023-07-15 10:11:50 +02:00
2023-07-15 10:34:20 +02:00
#define MIN_INTERVAL 30
2023-07-15 09:25:30 +02:00
#define INA260_SYSFS "/sys/kernel/ina260"
#define INA260_POWER_REGISTER "registers/power"
2023-07-15 14:02:43 +02:00
#define ZMQ_TOKEN "ina260-zmq-publisher"
2023-07-15 14:58:40 +02:00
#define ZMQ_MSG_SIZE 255*10
2023-07-15 10:11:50 +02:00
2023-07-15 10:34:20 +02:00
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)
2023-07-15 11:43:41 +02:00
#define TIMESTAMP() (time(NULL))
2023-07-15 10:11:50 +02:00
2023-07-15 11:43:41 +02:00
#define INTERVAL(duration)\
((TIMESTAMP()) - ((TIMESTAMP())%(duration)))
2023-07-15 10:11:50 +02:00
2023-07-15 12:14:22 +02:00
#define INTERVAL_NEXT(duration)\
((INTERVAL(duration))+(duration))
2023-07-15 11:43:41 +02:00
#define INTERVAL_LAST(duration)\
(INTERVAL(INTERVAL((TIMESTAMP()),(duration))-1,(duration)))
2023-07-15 10:31:36 +02:00
#define FILE_EXISTS(path) (access((path), F_OK) == 0)
void mkdirp(char *path);