]> git.itanic.dy.fi Git - log-plotter/blobdiff - main.c
Convert all existing prints into appropriate trace print
[log-plotter] / main.c
diff --git a/main.c b/main.c
index dd6c7c090a600705da207112849957a85a221990..065d9dc2b1f20a19ecaf5a07e95409866a16382a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,30 +2,30 @@
 #include <unistd.h>
 #include <sys/epoll.h>
 
+#include "options.h"
 #include "baud.h"
+#include "debug.h"
 
 int main(int argc, char *argv[])
 {
        struct epoll_event ev;
+       struct plotter_options options;
        int fd, baud, ret;
        int epoll_fd;
-       char *device;
        char buf[256];
 
-       if (argc < 2) {
-               printf("Usage: %s SERIAL_DEVICE\n", argv[0]);
-               return 1;
-       }
 
-       baud = 128000;
-       device = argv[1];
+       if (read_args(argc, argv, &options))
+               return 1;
 
-       fd = open_at_baud(device, &baud);
+       baud = options.baud_rate;
+       fd = open_at_baud(options.device_path, &baud);
        if (fd < 0)
                return 1;
 
-       if (baud != 128000) {
-               printf("Failed to set baudrate to 128000, only got %d\n", baud);
+       if (baud != options.baud_rate) {
+               pr_err("Failed to set baudrate to %d, only got %d\n",
+                       options.baud_rate, baud);
                close(fd);
                return 1;
        }
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
        ev.events = EPOLLIN;
        ev.data.fd = fd;
        if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) {
-               perror("epoll_ctl");
+               pr_err("epoll_ctl: %m\n");
                return 1;
        }
 
@@ -45,22 +45,24 @@ int main(int argc, char *argv[])
                        continue;
 
                if (ret < 0) {
-                       perror("epoll");
+                       pr_err("epoll: %m\n");
                        return 1;
                }
 
                ret = read(fd, buf, sizeof(buf));
                if (read < 0) {
-                       perror("read");
+                       pr_err("read: %m\n");
                        break;
                }
 
-               if (ret == 0)
+               if (ret == 0) {
+                       pr_err("Read EOF, stopping\n");
                        break;
+               }
 
                ret = write(1, buf, ret);
                if (read < 0) {
-                       perror("write");
+                       pr_err("write: %m\n");
                        break;
                }
        }