]> git.itanic.dy.fi Git - log-plotter/blob - main.c
05e3390968d01a9f3c0801509b04b2406dffe2a3
[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
12 int main(int argc, char *argv[])
13 {
14         struct plotter_options options;
15         struct plotter_config cfg;
16         int fd, baud, ret = 0, out_fd = 0;
17
18         bzero(&cfg, sizeof(cfg));
19
20         if (read_args(argc, argv, &options))
21                 return 1;
22
23         if (options.config_file_path)
24                 populate_config_data_from_file(options.config_file_path, &cfg);
25
26         baud = options.baud_rate;
27         fd = open_at_baud(options.device_path, &baud);
28         if (fd < 0)
29                 return 1;
30
31         if (baud != options.baud_rate) {
32                 pr_err("Failed to set baudrate to %d, only got %d\n",
33                         options.baud_rate, baud);
34                 ret = 1;
35                 goto out;
36         }
37
38         if (options.output_path) {
39                 pr_debug("Opening %s for writing the log file\n",
40                         options.output_path);
41
42                 out_fd = open(options.output_path,
43                         O_CREAT | O_APPEND | O_WRONLY, 0664);
44                 if (out_fd < 0) {
45                         pr_err("Failed to open file %s for writing: %m\n",
46                                 options.output_path);
47                         ret = 1;
48                         goto out;
49                 }
50         }
51
52         read_data(fd, out_fd);
53
54 out:
55         close(fd);
56         return ret;
57 }