Add ability to dump eeprom data over radio link.
authorKeith Packard <keithp@keithp.com>
Tue, 3 Nov 2009 09:27:37 +0000 (01:27 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 3 Nov 2009 09:27:37 +0000 (01:27 -0800)
This adds a '-R' option to ao-dumplog to redirect the connection
through a USB attached TeleDongle over the radio link to a remote
TeleMetrum device.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/ao-dumplog/ao-dumplog.c
ao-tools/lib/cc-usb.c
ao-tools/lib/cc-usb.h

index 158a445b48978eab213c8c3ec0cdd282aea2baef..4bfb7e51857fb1d5355678af4593c4dc35da55c2 100644 (file)
 static const struct option options[] = {
        { .name = "tty", .has_arg = 1, .val = 'T' },
        { .name = "device", .has_arg = 1, .val = 'D' },
+       { .name = "remote", .has_arg = 1, .val = 'R' },
        { 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>] [-R]\n", program);
        exit(1);
 }
 
@@ -80,8 +81,9 @@ main (int argc, char **argv)
        int             data[8];
        int             done;
        int             column;
+       int             remote = 0;
 
-       while ((c = getopt_long(argc, argv, "T:D:", options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "T:D:R", options, NULL)) != -1) {
                switch (c) {
                case 'T':
                        tty = optarg;
@@ -89,13 +91,20 @@ main (int argc, char **argv)
                case 'D':
                        device = optarg;
                        break;
+               case 'R':
+                       remote = 1;
+                       break;
                default:
                        usage(argv[0]);
                        break;
                }
        }
-       if (!tty)
-               tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+       if (!tty) {
+               if (remote)
+                       tty = cc_usbdevs_find_by_arg(device, "TeleDongle");
+               else
+                       tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+       }
        if (!tty)
                tty = getenv("ALTOS_TTY");
        if (!tty)
@@ -103,6 +112,8 @@ main (int argc, char **argv)
        cc = cc_usb_open(tty);
        if (!cc)
                exit(1);
+       if (remote)
+               cc_usb_open_remote(cc);
        /* send a 'version' command followed by a 'log' command */
        cc_usb_printf(cc, "v\n");
        out = NULL;
index 80d9c04f7ec5271074c730b3bf01c17f2845f610..9b3b831f3898e44c5f61f9bb14f70e6f770f78e6 100644 (file)
@@ -53,6 +53,8 @@ struct cc_usb {
 
        struct cc_hex_read      hex_buf[CC_NUM_HEX_READ];
        int                     hex_count;
+
+       int                     remote;
 };
 
 #define NOT_HEX        0xff
@@ -372,6 +374,28 @@ cc_usb_reset(struct cc_usb *cc)
        return 1;
 }
 
+void
+cc_usb_open_remote(struct cc_usb *cc)
+{
+       if (!cc->remote) {
+               cc_usb_printf(cc, "p\nE 0\n");
+               do {
+                       cc->in_count = cc->in_pos = 0;
+                       _cc_usb_sync(cc, 100);
+               } while (cc->in_count > 0);
+               cc->remote = 1;
+       }
+}
+
+void
+cc_usb_close_remote(struct cc_usb *cc)
+{
+       if (cc->remote) {
+               cc_usb_printf(cc, "~");
+               cc->remote = 0;
+       }
+}
+
 static struct termios  save_termios;
 
 struct cc_usb *
@@ -406,6 +430,8 @@ cc_usb_open(char *tty)
 void
 cc_usb_close(struct cc_usb *cc)
 {
+       cc_usb_close_remote(cc);
+       cc_usb_sync(cc);
        tcsetattr(cc->fd, TCSAFLUSH, &save_termios);
        close (cc->fd);
        free (cc);
index 7b6be350f02e6badefe61b5142fdd660f51e8a06..627f1b5d86ad10995f3e62aaae7e604c8bc8ef21 100644 (file)
@@ -62,4 +62,10 @@ cc_usb_getline(struct cc_usb *cc, char *line, int max);
 void
 cc_usb_printf(struct cc_usb *cc, char *format, ...);
 
+void
+cc_usb_open_remote(struct cc_usb *cc);
+
+void
+cc_usb_close_remote(struct cc_usb *cc);
+
 #endif /* _CC_USB_H_ */