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