From f89a58860e4e3c76ef3c2e85d47ff38eeaaabb55 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sat, 15 Jul 2023 08:38:33 +0200 Subject: Minor changes --- src/logger.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/logger.c (limited to 'src/logger.c') diff --git a/src/logger.c b/src/logger.c new file mode 100644 index 0000000..2245887 --- /dev/null +++ b/src/logger.c @@ -0,0 +1,55 @@ +// Weather update client +// Connects SUB socket to tcp://localhost:5556 +// Collects weather updates and finds avg temp in zipcode +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" +#include + +void start(char *power_path, char *busid, char *chipaddr); + +int main (int argc, char *argv []) +{ + if(argc != 2){ + printf("Usage: %s ",argv[0]); + exit(1); + } + + // Extract bus id and ina260 chip address + char busid[10]; + char chipaddr[10]; + char *base=basename(argv[1]); + sscanf(base,"%[^-]-%[^-]",busid,chipaddr); + + start("/home/loic/out.txt", busid,chipaddr); + + return 0; +} + +void start(char *power_path, char *busid, char *chipaddr){ + if (access(power_path, F_OK) != 0){ + printf("Could not read %s\n",power_path); + exit(2); + } + char outdir[255]; + mkdir(STRINGIFY(LOGGER_DIR),0755); + sprintf(outdir,"%s/%s-%s/",STRINGIFY(LOGGER_DIR), busid,chipaddr); + mkdir(outdir,0755); + + char outfile[255]; + time_t timestamp; + timestamp = time(NULL); + sprintf(outfile,"%s/%d",outdir,timestamp); + printf("aa %s\n",outfile); + + FILE *f; + f=fopen(outfile, "w"); + fclose(f); + +} \ No newline at end of file -- cgit v1.2.3