]> git.itanic.dy.fi Git - log-plotter/blobdiff - main.c
Implement state machine based architecture
[log-plotter] / main.c
diff --git a/main.c b/main.c
index 1057d09ad71b145d0c4a06cd0c83f5ed41391c55..9356d91b2ee7d7aa8097f6747d705c0a549dbe94 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,6 +1,5 @@
 #include <stdio.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
 
 #include "options.h"
@@ -9,12 +8,15 @@
 #include "trace.h"
 #include "data.h"
 #include "event.h"
+#include "plotter_status.h"
+
+struct log_plotter_status plotter_state;
 
 int main(int argc, char *argv[])
 {
        struct plotter_options options;
        struct plotter_config cfg;
-       int fd, baud, ret = 0, out_fd = 0;
+       int fd, baud, ret = 0;
 
        bzero(&cfg, sizeof(cfg));
 
@@ -36,25 +38,20 @@ int main(int argc, char *argv[])
                goto out;
        }
 
-       if (options.output_path) {
-               pr_debug("Opening %s for writing the log file\n",
-                       options.output_path);
-
-               out_fd = open(options.output_path,
-                       O_CREAT | O_APPEND | O_WRONLY, 0664);
-               if (out_fd < 0) {
-                       pr_err("Failed to open file %s for writing: %m\n",
-                               options.output_path);
-                       ret = 1;
-                       goto out;
-               }
-       }
+       init_data_parser(fd, &cfg);
 
+       while (plotter_state.system_status != SYSTEM_STATUS_NO_USB) {
+               poll_events(10000);
 
-       init_data_parser(fd, out_fd);
+               if (plotter_state.old_system_status !=
+                       plotter_state.system_status) {
+                       pr_debug("Status changing from %s to %s",
+                               state_to_str(plotter_state.old_system_status),
+                               state_to_str(plotter_state.system_status));
 
-       while (1) {
-               poll_events(10000);
+                       plotter_state.old_system_status =
+                               plotter_state.system_status;
+               }
        }
 
 out: