1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// 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>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <sys/stat.h>
#include "../utils.h"
#include <time.h>
void start(char *power_path, char *busid, char *chipaddr);
int main (int argc, char *argv [])
{
if(argc != 2){
printf("Usage: %s <sysfs-path>",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);
}
|