12 int main(int argc, char *argv[])
14 struct epoll_event ev;
15 struct plotter_options options;
16 int fd, baud, ret, out_fd = STDOUT_FILENO;
21 if (read_args(argc, argv, &options))
24 baud = options.baud_rate;
25 fd = open_at_baud(options.device_path, &baud);
29 if (baud != options.baud_rate) {
30 pr_err("Failed to set baudrate to %d, only got %d\n",
31 options.baud_rate, baud);
36 if (options.output_path) {
37 pr_debug("Opening %s for writing the log file\n",
40 out_fd = open(options.output_path,
41 O_CREAT | O_APPEND | O_WRONLY, 0664);
43 pr_err("Failed to open file %s for writing: %m\n",
50 epoll_fd = epoll_create(1);
54 if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
55 pr_err("epoll_ctl: %m\n");
60 ret = epoll_wait(epoll_fd, &ev, 1, -1);
65 pr_err("epoll: %m\n");
69 ret = read(fd, buf, sizeof(buf));
76 pr_err("Read EOF, stopping\n");
80 ret = write(1, buf, ret);
82 pr_err("write: %m\n");