Minor changes

This commit is contained in:
Loic Guegan 2023-07-16 10:46:52 +02:00
parent 9e021f564c
commit 19a77c6fd7
4 changed files with 13 additions and 12 deletions

View file

@ -15,8 +15,8 @@
// Global:
char *__client;
char __logdir[255];
char __regpower[100];
char __logdir[STATIC_LEN];
char __regpower[STATIC_LEN];
int __loginterval;
int main (int argc, char *argv [])
@ -55,9 +55,9 @@ int main (int argc, char *argv [])
printf("Logger started [client=%s,interval=%ds]\n",__client,__loginterval);
FILE *regptr,*logptr;
char logfilepath[255]="";
char logfilepath[STATIC_LEN]="";
regptr=fopen("/home/loic/out.txt","r");
char buffer[255];
char buffer[STATIC_LEN];
int power;
time_t interval;
struct timespec power_ts;
@ -69,7 +69,7 @@ int main (int argc, char *argv [])
fprintf(logptr,"timestamp,ns,power\n");
// Log current interval
while((TIMESTAMP()-interval)<__loginterval){
fgets(buffer,255,regptr);
fgets(buffer,STATIC_LEN,regptr);
power=atoi(buffer);
clock_gettime(CLOCK_REALTIME,&power_ts);
fprintf(logptr,"%d,%ld,%d\n",power_ts.tv_sec,power_ts.tv_nsec,power);

View file

@ -32,7 +32,7 @@ int main (int argc, char *argv [])
//----- Prepare our context and publisher
void *context = zmq_ctx_new ();
void *publisher = zmq_socket (context, ZMQ_PUB);
char bindto[30];
char bindto[STATIC_LEN];
sprintf(bindto,"tcp://%s:%d",__ip,__port);
int rc = zmq_connect (publisher, bindto);
if(rc!=0){
@ -50,8 +50,8 @@ int main (int argc, char *argv [])
while ((de = readdir(dr)) != NULL){
if(strcmp(de->d_name,".") && strcmp(de->d_name,"..")){
char *client=de->d_name;
char logfile[255];
char logfile_next[255];
char logfile[STATIC_LEN];
char logfile_next[STATIC_LEN];
sprintf(logfile,"%s/%s/%ld",__logdir,client,interval);
sprintf(logfile_next,"%s/%s/%ld",__logdir,client,interval_next);
// As long as next logfile is not available, we should wait

View file

@ -22,7 +22,7 @@ int main (int argc, char *argv [])
//----- Init ZMQ
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
char bindto[30];
char bindto[STATIC_LEN];
sprintf(bindto,"tcp://*:%d",port);
int rc = zmq_bind (subscriber, bindto);
if(rc!=0){
@ -40,8 +40,8 @@ int main (int argc, char *argv [])
buffer[size < ZMQ_MSG_SIZE ? size : ZMQ_MSG_SIZE - 1] = '\0';
//----- Read buffer
char *token = strtok(buffer, "\n");
char key[255];
char client[255];
char key[STATIC_LEN];
char client[STATIC_LEN];
long int interval;
FILE *fptr;
int line=1;
@ -55,7 +55,7 @@ int main (int argc, char *argv [])
if(line==4){
printf("Data received with key=%s\n",key);
char path[255]="";
char path[STATIC_LEN]="";
sprintf(path,"%s/%s_%s_%ld",cdatadir,key,client,interval);
fptr=fopen(path,"a");
}

View file

@ -8,6 +8,7 @@
#define MIN_INTERVAL 30
#define INA260_SYSFS "/sys/kernel/ina260"
#define INA260_POWER_REGISTER "registers/power"
#define STATIC_LEN 255
#ifndef ZMQ_TOKEN
#define ZMQ_TOKEN "ina260-zmq-publisher"