]> git.itanic.dy.fi Git - log-plotter/blobdiff - main.c
Add more advanced debug macro
[log-plotter] / main.c
diff --git a/main.c b/main.c
index 847a110c3bdbf2932609b8e8e8e3f4c149670166..d81f7333e25f062c28e15e4b43f3f9e77335c6f6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,30 +2,29 @@
 #include <unistd.h>
 #include <sys/epoll.h>
 
+#include "options.h"
 #include "baud.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) {
+               printf("Failed to set baudrate to %d, only got %d\n",
+                       options.baud_rate, baud);
                close(fd);
                return 1;
        }
@@ -55,6 +54,9 @@ int main(int argc, char *argv[])
                        break;
                }
 
+               if (ret == 0)
+                       break;
+
                ret = write(1, buf, ret);
                if (read < 0) {
                        perror("write");