// 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 // Global: char *__client; char __logdir[255]; char __regpower[100]; int __logfrequency; void start(char *power_path, char *busid, char *chipaddr); int main (int argc, char *argv []) { if(argc != 4){ printf("Usage: %s ",argv[0]); exit(1); } //----- 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); // 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);*/ // 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)); 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); }