summaryrefslogtreecommitdiff
path: root/src/utils.h
blob: f27ff9ed51a7bf347c3ab948da8d32337a4fa3ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

#define MIN_INTERVAL 0
#define INA260_SYSFS "/sys/kernel/ina260"
#define INA260_POWER_REGISTER "registers/power"
#define STATIC_LEN 255
#define MAX_QUEUES 1

#ifndef ZMQ_TOKEN
#define ZMQ_TOKEN "ina260-zmq-publisher"
#endif

#ifndef ZMQ_MSG_SIZE
#define ZMQ_MSG_SIZE 5242880
#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)
#define DIR_EXISTS(path) (dir_exists(path))

void mkdirp(char *path);
unsigned char dir_exists(char *path);