mirror of
https://gitlab.com/manzerbredes/ina260-zmq-publisher.git
synced 2025-04-19 12:19:46 +00:00
Minor changes
This commit is contained in:
parent
33c5443794
commit
dd12a4b42f
3 changed files with 28 additions and 23 deletions
14
src/logger.c
14
src/logger.c
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue