diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2023-07-15 11:43:41 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2023-07-15 11:43:41 +0200 |
| commit | 83e6235919e649b45d36ebdc0eedc2d8d0ce309e (patch) | |
| tree | a8069fd5d9a1e4e8088a1f1b0583b3b87b2d8706 /src | |
| parent | be6cfef7d259af98eda694537a85e692afa97aa1 (diff) | |
Minor changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/logger.c | 26 | ||||
| -rw-r--r-- | src/utils.h | 10 |
2 files changed, 25 insertions, 11 deletions
diff --git a/src/logger.c b/src/logger.c index c65c3da..30f7f62 100644 --- a/src/logger.c +++ b/src/logger.c @@ -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 diff --git a/src/utils.h b/src/utils.h index 5acdedc..01e0c33 100644 --- a/src/utils.h +++ b/src/utils.h @@ -13,13 +13,13 @@ #define STR(symbol) #symbol #define STRINGIFY(symbol) STR(symbol) -#define INTERVAL(timestamp,duration)\ - ((timestamp) - ((timestamp)%(duration))) +#define TIMESTAMP() (time(NULL)) -#define INTERVAL_LAST(timestamp,duration)\ - (INTERVAL(INTERVAL((timestamp),(duration))-1,(duration))) +#define INTERVAL(duration)\ + ((TIMESTAMP()) - ((TIMESTAMP())%(duration))) -#define TIMESTAMP() (time(NULL)) +#define INTERVAL_LAST(duration)\ + (INTERVAL(INTERVAL((TIMESTAMP()),(duration))-1,(duration))) #define FILE_EXISTS(path) (access((path), F_OK) == 0) |
