Minor changes

This commit is contained in:
Loic Guegan 2023-07-16 17:19:44 +02:00
parent 33c5443794
commit dd12a4b42f
3 changed files with 28 additions and 23 deletions

View file

@ -1,14 +1,10 @@
#include <zmq.h>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <sys/stat.h>
#include "utils.h"
#include <time.h>
#include <signal.h>
#include "utils.h"
#ifndef LOGGER_DELAY
#define LOGGER_DELAY 0
@ -66,7 +62,7 @@ int main (int argc, char *argv [])
FILE *regptr,*logptr;
char logfilepath[STATIC_LEN]="";
regptr=fopen("/home/loic/out.txt","r");
regptr=fopen("/home/loic/out.txt","r"); // TODO UPDATE!!!
char buffer[STATIC_LEN];
int power;
time_t interval;
@ -74,16 +70,20 @@ int main (int argc, char *argv [])
while(!__stop){
interval=INTERVAL(__loginterval);
*logfilepath='\0';
sprintf(logfilepath,"%s/%ld",__logdir,interval);
logptr=fopen(logfilepath,"w");
// Write file header:
fprintf(logptr,"timestamp,ns,power\n");
// Log current interval
while((TIMESTAMP()-interval)<__loginterval){
// Read power:
fgets(buffer,STATIC_LEN,regptr);
power=atoi(buffer);
// Get power measurement timestamp:
clock_gettime(CLOCK_REALTIME,&power_ts);
// Write measurement in file:
fprintf(logptr,"%d,%ld,%d\n",power_ts.tv_sec,power_ts.tv_nsec,power);
// Reset power register file:
fseek(regptr,0,SEEK_SET);
#if LOGGER_DELAY > 0
usleep(LOGGER_DELAY*1000);