]> git.itanic.dy.fi Git - log-plotter/blob - main.c
data.c: Reset time stamp when starting new log
[log-plotter] / main.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4
5 #include "config.h"
6 #include "baud.h"
7 #include "trace.h"
8 #include "data.h"
9 #include "event.h"
10 #include "plotter_status.h"
11
12 struct log_plotter_status plotter_state;
13
14 int main(int argc, char *argv[])
15 {
16         struct plotter_config cfg;
17         int fd, baud, ret = 0;
18
19         bzero(&cfg, sizeof(cfg));
20
21         if (read_args(argc, argv, &cfg))
22                 return 1;
23
24         if (cfg.config_file_path)
25                 populate_config_data_from_file(cfg.config_file_path, &cfg);
26
27         baud = cfg.baudrate;
28         fd = open_at_baud(cfg.device_path, &baud);
29         if (fd < 0)
30                 return 1;
31
32         if (baud != cfg.baudrate) {
33                 pr_err("Failed to set baudrate to %d, only got %d\n",
34                         cfg.baudrate, baud);
35                 ret = 1;
36                 goto out;
37         }
38
39         init_data_parser(fd, &cfg);
40
41         while (plotter_state.system_status != SYSTEM_STATUS_NO_USB) {
42                 poll_events(10000);
43
44                 if (plotter_state.old_system_status !=
45                         plotter_state.system_status) {
46                         pr_debug("Status changing from %s to %s\n",
47                                 state_to_str(plotter_state.old_system_status),
48                                 state_to_str(plotter_state.system_status));
49
50                         plotter_state.old_system_status =
51                                 plotter_state.system_status;
52                 }
53         }
54
55 out:
56         close(fd);
57         return ret;
58 }