2023-07-14 20:42:12 +02:00
|
|
|
// Weather update client
|
|
|
|
// Connects SUB socket to tcp://localhost:5556
|
|
|
|
// Collects weather updates and finds avg temp in zipcode
|
|
|
|
#include <zmq.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <time.h>
|
2023-07-14 22:03:40 +02:00
|
|
|
#include <stdlib.h>
|
2023-07-14 20:42:12 +02:00
|
|
|
#include <string.h>
|
2023-07-14 22:03:40 +02:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <unistd.h>
|
2023-07-14 22:09:39 +02:00
|
|
|
#include <sys/stat.h>
|
2023-07-15 08:38:33 +02:00
|
|
|
#include "utils.h"
|
2023-07-14 22:30:02 +02:00
|
|
|
#include <time.h>
|
2023-07-14 22:03:40 +02:00
|
|
|
|
2023-07-15 09:25:30 +02:00
|
|
|
// Global:
|
2023-07-15 10:11:50 +02:00
|
|
|
char *__client;
|
|
|
|
char __logdir[255];
|
|
|
|
char __regpower[100];
|
|
|
|
int __logfrequency;
|
2023-07-15 09:25:30 +02:00
|
|
|
|
2023-07-14 22:27:53 +02:00
|
|
|
void start(char *power_path, char *busid, char *chipaddr);
|
2023-07-14 20:42:12 +02:00
|
|
|
|
|
|
|
int main (int argc, char *argv [])
|
|
|
|
{
|
2023-07-15 10:11:50 +02:00
|
|
|
if(argc != 4){
|
2023-07-15 09:25:30 +02:00
|
|
|
printf("Usage: %s <abslogdir> <client> <logfrequency>",argv[0]);
|
2023-07-14 22:03:40 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2023-07-15 10:11:50 +02:00
|
|
|
//----- Init global variables
|
|
|
|
__client=argv[2];
|
|
|
|
__logfrequency=atoi(argv[3]);
|
|
|
|
// __logdir:
|
|
|
|
strcat(__logdir,argv[1]);
|
|
|
|
strcat(__logdir,"/");
|
|
|
|
strcat(__logdir,__client);
|
|
|
|
// __regpower:
|
|
|
|
strcat(__regpower,INA260_SYSFS);
|
|
|
|
strcat(__regpower,"/");
|
|
|
|
strcat(__regpower,__client);
|
|
|
|
strcat(__regpower,"/");
|
|
|
|
strcat(__regpower,INA260_POWER_REGISTER);
|
|
|
|
|
2023-07-14 22:03:40 +02:00
|
|
|
// Extract bus id and ina260 chip address
|
2023-07-15 10:11:50 +02:00
|
|
|
/*char busid[10];
|
2023-07-14 22:03:40 +02:00
|
|
|
char chipaddr[10];
|
|
|
|
char *base=basename(argv[1]);
|
|
|
|
sscanf(base,"%[^-]-%[^-]",busid,chipaddr);
|
|
|
|
|
2023-07-15 10:11:50 +02:00
|
|
|
start("/home/loic/out.txt", busid,chipaddr);*/
|
|
|
|
|
|
|
|
// printf("ts=%d, dur=%d, interval=%d\n",15,__logfrequency,INTERVAL(15,__logfrequency));
|
|
|
|
// printf("ts=%d, dur=%d, interval_last=%d\n",15,__logfrequency,INTERVAL_LAST(15,__logfrequency));
|
2023-07-14 22:03:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-07-14 22:27:53 +02:00
|
|
|
void start(char *power_path, char *busid, char *chipaddr){
|
2023-07-14 22:03:40 +02:00
|
|
|
if (access(power_path, F_OK) != 0){
|
|
|
|
printf("Could not read %s\n",power_path);
|
|
|
|
exit(2);
|
|
|
|
}
|
2023-07-14 22:27:53 +02:00
|
|
|
char outdir[255];
|
2023-07-14 22:09:39 +02:00
|
|
|
mkdir(STRINGIFY(LOGGER_DIR),0755);
|
2023-07-14 22:27:53 +02:00
|
|
|
sprintf(outdir,"%s/%s-%s/",STRINGIFY(LOGGER_DIR), busid,chipaddr);
|
|
|
|
mkdir(outdir,0755);
|
|
|
|
|
|
|
|
char outfile[255];
|
2023-07-14 22:30:02 +02:00
|
|
|
time_t timestamp;
|
|
|
|
timestamp = time(NULL);
|
|
|
|
sprintf(outfile,"%s/%d",outdir,timestamp);
|
2023-07-14 22:27:53 +02:00
|
|
|
printf("aa %s\n",outfile);
|
|
|
|
|
|
|
|
FILE *f;
|
|
|
|
f=fopen(outfile, "w");
|
|
|
|
fclose(f);
|
|
|
|
|
2023-07-14 20:42:12 +02:00
|
|
|
}
|