Minor changes

This commit is contained in:
Loic Guegan 2023-07-15 11:43:41 +02:00
parent be6cfef7d2
commit 83e6235919
2 changed files with 26 additions and 12 deletions

View file

@ -59,12 +59,26 @@ int main (int argc, char *argv [])
char logfilepath[255]="";
regptr=fopen("/home/loic/out.txt","r");
*logfilepath='\0';
sprintf(logfilepath,"%s/%ld",__logdir,INTERVAL(TIMESTAMP(),__loginterval));
logptr=fopen(logfilepath,"w");
fprintf(logptr,"timestamp,power\n");
fclose(logptr);
for(int i=0;i<1;i++){
char buffer[255];
int power;
time_t interval=INTERVAL(__loginterval);
*logfilepath='\0';
sprintf(logfilepath,"%s/%ld",__logdir);
logptr=fopen(logfilepath,"w");
fprintf(logptr,"timestamp,power\n");
// Log current interval
while((TIMESTAMP()-interval)<__loginterval){
fgets(buffer,255,regptr);
power=atoi(buffer);
fprintf(logptr,"%ld,%d\n",TIMESTAMP(),power);
fseek(regptr,0,SEEK_SET);
sleep(1);
printf("Tick\n");
}
fclose(logptr);
}
fclose(regptr);
// Extract bus id and ina260 chip address

View file

@ -13,14 +13,14 @@
#define STR(symbol) #symbol
#define STRINGIFY(symbol) STR(symbol)
#define INTERVAL(timestamp,duration)\
((timestamp) - ((timestamp)%(duration)))
#define INTERVAL_LAST(timestamp,duration)\
(INTERVAL(INTERVAL((timestamp),(duration))-1,(duration)))
#define TIMESTAMP() (time(NULL))
#define INTERVAL(duration)\
((TIMESTAMP()) - ((TIMESTAMP())%(duration)))
#define INTERVAL_LAST(duration)\
(INTERVAL(INTERVAL((TIMESTAMP()),(duration))-1,(duration)))
#define FILE_EXISTS(path) (access((path), F_OK) == 0)
void mkdirp(char *path);