Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 10:11:50 +02:00
parent 4169628e57
commit 4fbfae7044
2 changed files with 34 additions and 6 deletions

View file

@ -13,26 +13,44 @@
#include <time.h>
// Global:
char __client*;
char __logdir*;
int __logfrequency,
char *__client;
char __logdir[255];
char __regpower[100];
int __logfrequency;
void start(char *power_path, char *busid, char *chipaddr);
int main (int argc, char *argv [])
{
if(argc != 3){
if(argc != 4){
printf("Usage: %s <abslogdir> <client> <logfrequency>",argv[0]);
exit(1);
}
//----- Init global variables
__client=argv[2];
__logfrequency=atoi(argv[3]);
// __logdir:
strcat(__logdir,argv[1]);
strcat(__logdir,"/");
strcat(__logdir,__client);
// __regpower:
strcat(__regpower,INA260_SYSFS);
strcat(__regpower,"/");
strcat(__regpower,__client);
strcat(__regpower,"/");
strcat(__regpower,INA260_POWER_REGISTER);
// Extract bus id and ina260 chip address
char busid[10];
/*char busid[10];
char chipaddr[10];
char *base=basename(argv[1]);
sscanf(base,"%[^-]-%[^-]",busid,chipaddr);
start("/home/loic/out.txt", busid,chipaddr);
start("/home/loic/out.txt", busid,chipaddr);*/
// printf("ts=%d, dur=%d, interval=%d\n",15,__logfrequency,INTERVAL(15,__logfrequency));
// printf("ts=%d, dur=%d, interval_last=%d\n",15,__logfrequency,INTERVAL_LAST(15,__logfrequency));
return 0;
}

View file

@ -1,5 +1,15 @@
#include <time.h>
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)
#define INA260_SYSFS "/sys/kernel/ina260"
#define INA260_POWER_REGISTER "registers/power"
#define INTERVAL(timestamp,duration)\
((timestamp) - ((timestamp)%(duration)))
#define INTERVAL_LAST(timestamp,duration)\
(INTERVAL(INTERVAL((timestamp),(duration))-1,(duration)))
#define TIMESTAMP() (time(NULL))