ao-tools: Fix warnings in ao-tools
[fw/altos] / ao-tools / ao-dump-up / ao-dump-up.c
index 6268dc8b75b9540bc69af66059ebbc2d76b3bfcb..6866ef592997e7fe24bf9954d5c6fa81c3b56faa 100644 (file)
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <string.h>
+#include <ctype.h>
 #include "cc-usb.h"
 #include "cc.h"
 
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
        { .name = "device", .has_arg = 1, .val = 'D' },
+       { .name = "wait", .has_arg = 0, .val = 'w' },
        { 0, 0, 0, 0},
 };
 
 static void usage(char *program)
 {
-       fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>]\n", program);
+       fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] [--wait]\n", program);
        exit(1);
 }
 
-static uint8_t
-log_checksum(int d[8])
-{
-       uint8_t sum = 0x5a;
-       int     i;
-
-       for (i = 0; i < 8; i++)
-               sum += (uint8_t) d[i];
-       return -sum;
-}
-
 static int get_nonwhite(struct cc_usb *cc, int timeout)
 {
        int     c;
@@ -134,25 +125,11 @@ static int swap16(int i)
 static int find_header(struct cc_usb *cc)
 {
        for (;;) {
-               if (get_nonwhite(cc, 0) == 'M' && get_nonwhite(cc, 1000) == 'P')
+               if (get_nonwhite(cc, -1) == 'M' && get_nonwhite(cc, 1000) == 'P')
                        return 1;
        }
 }
 
-static const char *state_names[] = {
-       "startup",
-       "idle",
-       "pad",
-       "boost",
-       "fast",
-       "coast",
-       "drogue",
-       "main",
-       "landed",
-       "invalid"
-};
-
-
 int
 main (int argc, char **argv)
 {
@@ -160,14 +137,17 @@ main (int argc, char **argv)
        char            *tty = NULL;
        char            *device = NULL;
        int             c;
-       char            line[8192];
        int             nsamples;
        int             i;
        int             crc;
        int             current_crc;
+       int             wait = 0;
 
-       while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "wT:D:", options, NULL)) != -1) {
                switch (c) {
+               case 'w':
+                       wait = 1;
+                       break;
                case 'T':
                        tty = optarg;
                        break;
@@ -179,8 +159,21 @@ main (int argc, char **argv)
                        break;
                }
        }
-       if (!tty)
-               tty = cc_usbdevs_find_by_arg(device, "FT230X Basic UART");
+       if (!tty) {
+               for (;;) {
+                       tty = cc_usbdevs_find_by_arg(device, "FT230X Basic UART");
+                       if (tty) {
+                               if (wait) {
+                                       printf("tty is %s\n", tty);
+                                       sleep(1);
+                               }
+                               break;
+                       }
+                       if (!wait)
+                               break;
+                       sleep(1);
+               }
+       }
        if (!tty)
                tty = getenv("ALTOS_TTY");
        if (!tty)