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