Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 10:31:36 +02:00
parent 4fbfae7044
commit cb13d2982c
4 changed files with 32 additions and 6 deletions

View file

@ -5,13 +5,13 @@ CFLAGS=
all: publisher client logger
publisher: src/publisher.c
publisher: src/publisher.c src/utils.c
$(CC) -lzmq $^ -o $@
client: src/client.c
$(CC) -lzmq $^ -o $@
logger: src/logger.c
logger: src/logger.c src/utils.c
$(CC) $^ -o $@
clean:

View file

@ -16,20 +16,20 @@
char *__client;
char __logdir[255];
char __regpower[100];
int __logfrequency;
int __loginterval;
void start(char *power_path, char *busid, char *chipaddr);
int main (int argc, char *argv [])
{
if(argc != 4){
printf("Usage: %s <abslogdir> <client> <logfrequency>",argv[0]);
printf("Usage: %s <abslogdir> <client> <loginterval>",argv[0]);
exit(1);
}
//----- Init global variables
__client=argv[2];
__logfrequency=atoi(argv[3]);
__loginterval=atoi(argv[3]);
// __logdir:
strcat(__logdir,argv[1]);
strcat(__logdir,"/");
@ -41,6 +41,16 @@ int main (int argc, char *argv [])
strcat(__regpower,"/");
strcat(__regpower,INA260_POWER_REGISTER);
//----- Sanity checks
mkdirp(__logdir);
if(!FILE_EXISTS(__regpower)){
printf("Logger cannot access to %s\n",__regpower);
exit(2);
}
//----- Start logging
printf("Logger started [client=%s,interval=%ds]\n",__client,__loginterval);
// Extract bus id and ina260 chip address
/*char busid[10];
char chipaddr[10];
@ -56,7 +66,7 @@ int main (int argc, char *argv [])
}
void start(char *power_path, char *busid, char *chipaddr){
if (access(power_path, F_OK) != 0){
if (!FILE_EXISTS(power_path)){
printf("Could not read %s\n",power_path);
exit(2);
}

7
src/utils.c Normal file
View file

@ -0,0 +1,7 @@
#include "utils.h"
void mkdirp(char *path){
char buffer[255]="mkdir -p ";
strcat(buffer,path);
system(buffer);
}

View file

@ -1,4 +1,9 @@
#pragma once
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)
@ -13,3 +18,7 @@
(INTERVAL(INTERVAL((timestamp),(duration))-1,(duration)))
#define TIMESTAMP() (time(NULL))
#define FILE_EXISTS(path) (access((path), F_OK) == 0)
void mkdirp(char *path);