#include <stdio.h>
#include <unistd.h>
+#include <string.h>
+#include "config.h"
#include "baud.h"
+#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[])
{
- int fd, baud, ret;
- char *device;
- char buf[256];
+ struct plotter_config cfg;
+ int fd, baud, ret = 0;
+
+ bzero(&cfg, sizeof(cfg));
- if (argc < 2) {
- printf("Usage: %s SERIAL_DEVICE\n", argv[0]);
+ if (read_args(argc, argv, &cfg))
return 1;
- }
- baud = 128000;
- device = argv[1];
+ if (cfg.config_file_path)
+ populate_config_data_from_file(cfg.config_file_path, &cfg);
- fd = open_at_baud(device, &baud);
+ baud = cfg.baudrate;
+ fd = open_at_baud(cfg.device_path, &baud);
if (fd < 0)
return 1;
- if (baud != 128000) {
- printf("Failed to set baudrate to 128000, only got %d\n", baud);
- close(fd);
- return 1;
+ if (baud != cfg.baudrate) {
+ pr_err("Failed to set baudrate to %d, only got %d\n",
+ cfg.baudrate, baud);
+ ret = 1;
+ goto out;
}
- while (1) {
- ret = read(fd, buf, sizeof(buf));
- if (read < 0) {
- perror("read");
- break;
- }
+ init_data_parser(fd, &cfg);
+
+ while (plotter_state.system_status != SYSTEM_STATUS_NO_USB) {
+ poll_events(10000);
- if (read == 0)
- break;
+ if (plotter_state.old_system_status !=
+ plotter_state.system_status) {
+ pr_debug("Status changing from %s to %s\n",
+ state_to_str(plotter_state.old_system_status),
+ state_to_str(plotter_state.system_status));
- ret = write(1, buf, ret);
- if (read < 0) {
- perror("write");
- break;
+ plotter_state.old_system_status =
+ plotter_state.system_status;
}
}
+out:
close(fd);
- return 0;
+ return ret;
}