summaryrefslogtreecommitdiff
path: root/ao-tools
diff options
context:
space:
mode:
Diffstat (limited to 'ao-tools')
-rw-r--r--ao-tools/Makefile.am2
-rw-r--r--ao-tools/ao-send-telem/ao-send-telem.c121
-rw-r--r--ao-tools/ao-test-gps/.gitignore1
-rw-r--r--ao-tools/ao-test-gps/Makefile.am11
-rw-r--r--ao-tools/ao-test-gps/ao-test-gps.155
-rw-r--r--ao-tools/ao-test-gps/ao-test-gps.c241
-rw-r--r--ao-tools/ao-test-igniter/ao-test-igniter.c1
-rw-r--r--ao-tools/ao-usbload/ao-usbload.c12
-rw-r--r--ao-tools/ao-usbtrng/.gitignore1
-rw-r--r--ao-tools/ao-usbtrng/Makefile.am11
-rw-r--r--ao-tools/ao-usbtrng/ao-usbtrng.158
-rw-r--r--ao-tools/ao-usbtrng/ao-usbtrng.c126
-rw-r--r--ao-tools/lib/cc-usb.c12
-rw-r--r--ao-tools/lib/cc-usb.h2
14 files changed, 610 insertions, 44 deletions
diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am
index 2d873e50..6a170cbd 100644
--- a/ao-tools/Makefile.am
+++ b/ao-tools/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list \
ao-load ao-telem ao-send-telem ao-sky-flash \
ao-dumpflash ao-edit-telem ao-dump-up ao-elftohex \
ao-flash ao-usbload ao-test-igniter ao-test-baro \
- ao-test-flash ao-cal-accel
+ ao-test-flash ao-cal-accel ao-test-gps ao-usbtrng
if LIBSTLINK
SUBDIRS += ao-stmload
endif
diff --git a/ao-tools/ao-send-telem/ao-send-telem.c b/ao-tools/ao-send-telem/ao-send-telem.c
index 26c3263e..ef6f892c 100644
--- a/ao-tools/ao-send-telem/ao-send-telem.c
+++ b/ao-tools/ao-send-telem/ao-send-telem.c
@@ -29,12 +29,14 @@ static const struct option options[] = {
{ .name = "device", .has_arg = 1, .val = 'D' },
{ .name = "frequency", .has_arg = 1, .val = 'F' },
{ .name = "realtime", .has_arg = 0, .val = 'R' },
+ { .name = "verbose", .has_arg = 0, .val = 'v' },
+ { .name = "fake", .has_arg = 0, .val = 'f' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
- fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] [--frequency <kHz>] [--realtime] file.telem ...\n", program);
+ fprintf(stderr, "usage: %s [--tty <tty-name>] [--device <device-name>] [--frequency <kHz>] [--realtime] [--verbose] [--fake] file.telem ...\n", program);
exit(1);
}
@@ -126,7 +128,7 @@ send_telem(struct cc_usb *cc, union ao_telemetry_all *telem)
for (i = 0; i < 0x20; i++)
cc_usb_printf(cc, "%02x", b[i]);
cc_usb_sync(cc);
-}
+}
static void
do_delay(uint16_t now, uint16_t then)
@@ -173,9 +175,11 @@ main (int argc, char **argv)
uint16_t last_tick;
int started;
int realtime = 0;
-
+ int verbose = 0;
+ int fake = 0;
+ int rate = 0;
- while ((c = getopt_long(argc, argv, "RT:D:F:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "vRfT:D:F:r:", options, NULL)) != -1) {
switch (c) {
case 'T':
tty = optarg;
@@ -189,6 +193,30 @@ main (int argc, char **argv)
case 'R':
realtime = 1;
break;
+ case 'v':
+ verbose++;
+ break;
+ case 'f':
+ fake++;
+ break;
+ case 'r':
+ rate = atoi(optarg);
+ switch (rate) {
+ case 38400:
+ rate = 0;
+ break;
+ case 9600:
+ rate = 1;
+ break;
+ case 2400:
+ rate = 2;
+ break;
+ default:
+ fprintf(stderr, "Rate %d isn't 38400, 9600 or 2400\n", rate);
+ usage(argv[0]);
+ break;
+ }
+ break;
default:
usage(argv[0]);
break;
@@ -206,42 +234,65 @@ main (int argc, char **argv)
cc_usb_printf(cc, "m 0\n");
cc_usb_printf(cc, "c F %d\n", freq);
- for (i = optind; i < argc; i++) {
- file = fopen(argv[i], "r");
- if (!file) {
- perror(argv[i]);
- ret++;
- continue;
+ cc_usb_printf(cc, "c T %d\n", rate);
+
+ if (fake) {
+ union ao_telemetry_all telem;
+ uint16_t tick;
+ int i;
+
+ memset(&telem, '\0', sizeof (telem));
+ telem.generic.serial = 1;
+ telem.generic.type = 0;
+ for (i = 0; i < sizeof (telem.generic.payload); i++)
+ telem.generic.payload[i] = i & 7;
+ for (;;) {
+ telem.generic.tick += 50;
+ send_telem(cc, &telem);
+ do_delay(50, 0);
}
- started = 0;
- last_tick = 0;
- while (fgets(line, sizeof (line), file)) {
- union ao_telemetry_all telem;
-
- if (cc_telemetry_parse(line, &telem)) {
- /*
- * Skip packets with CRC errors.
- */
- if ((telem.generic.status & (1 << 7)) == 0)
- continue;
-
- if (started) {
- do_delay(telem.generic.tick, last_tick);
- last_tick = telem.generic.tick;
- send_telem(cc, &telem);
- } else {
- enum ao_flight_state state = packet_state(&telem);
- add_telem(&telem);
- if (ao_flight_pad < state && state < ao_flight_landed) {
- printf ("started\n");
- started = 1;
- last_tick = send_queued(cc, realtime);
+ } else {
+ for (i = optind; i < argc; i++) {
+ file = fopen(argv[i], "r");
+ if (!file) {
+ perror(argv[i]);
+ ret++;
+ continue;
+ }
+ started = 0;
+ last_tick = 0;
+ while (fgets(line, sizeof (line), file)) {
+ union ao_telemetry_all telem;
+
+ if (cc_telemetry_parse(line, &telem)) {
+ /*
+ * Skip packets with CRC errors.
+ */
+ if ((telem.generic.status & (1 << 7)) == 0)
+ continue;
+
+ if (verbose)
+ printf ("type %4d\n", telem.generic.type);
+
+ if (started || realtime) {
+ do_delay(telem.generic.tick, last_tick);
+ last_tick = telem.generic.tick;
+ send_telem(cc, &telem);
+ } else {
+ enum ao_flight_state state = packet_state(&telem);
+ printf ("\tstate %4d\n", state);
+ add_telem(&telem);
+ if (ao_flight_pad < state && state < ao_flight_landed) {
+ printf ("started\n");
+ started = 1;
+ last_tick = send_queued(cc, realtime);
+ }
}
}
}
- }
- fclose (file);
+ fclose (file);
+ }
}
return ret;
}
diff --git a/ao-tools/ao-test-gps/.gitignore b/ao-tools/ao-test-gps/.gitignore
new file mode 100644
index 00000000..ac203bce
--- /dev/null
+++ b/ao-tools/ao-test-gps/.gitignore
@@ -0,0 +1 @@
+ao-test-gps
diff --git a/ao-tools/ao-test-gps/Makefile.am b/ao-tools/ao-test-gps/Makefile.am
new file mode 100644
index 00000000..d89ddddd
--- /dev/null
+++ b/ao-tools/ao-test-gps/Makefile.am
@@ -0,0 +1,11 @@
+bin_PROGRAMS=ao-test-gps
+
+AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS)
+
+ao_test_gps_DEPENDENCIES = $(top_builddir)/ao-tools/lib/libao-tools.a
+
+ao_test_gps_LDADD=$(top_builddir)/ao-tools/lib/libao-tools.a $(LIBUSB_LIBS)
+
+ao_test_gps_SOURCES=ao-test-gps.c
+
+man_MANS = ao-test-gps.1
diff --git a/ao-tools/ao-test-gps/ao-test-gps.1 b/ao-tools/ao-test-gps/ao-test-gps.1
new file mode 100644
index 00000000..3d99c24d
--- /dev/null
+++ b/ao-tools/ao-test-gps/ao-test-gps.1
@@ -0,0 +1,55 @@
+.\"
+.\" Copyright © 2009 Keith Packard <keithp@keithp.com>
+.\"
+.\" This program is free software; you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" This program is distributed in the hope that it will be useful, but
+.\" WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+.\" General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License along
+.\" with this program; if not, write to the Free Software Foundation, Inc.,
+.\" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+.\"
+.\"
+.TH AO-LOAD 1 "ao-test-gps" ""
+.SH NAME
+ao-test-baro \- test AltOS tracker GPS receiver
+.SH SYNOPSIS
+.B "ao-test-gps"
+[\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
+\fIgps-name...\fP
+.SH DESCRIPTION
+.I ao-test-gps
+Waits for the GPS receiver to report lock.
+.SH OPTIONS
+.TP
+\-T tty-device | --tty tty-device
+This selects which tty device the debugger uses to communicate with
+the target device.
+.TP
+\-D AltOS-device | --device AltOS-device
+Search for a connected device. This requires an argument of one of the
+following forms:
+.IP
+TeleMega:2
+.br
+TeleMega
+.br
+2
+.IP
+Leaving out the product name will cause the tool to select a suitable
+product, leaving out the serial number will cause the tool to match
+one of the available devices.
+.SH USAGE
+.I ao-test-gps
+opens the target device and waits for it to report GPS lock.
+.SH AUTHOR
+Keith Packard
diff --git a/ao-tools/ao-test-gps/ao-test-gps.c b/ao-tools/ao-test-gps/ao-test-gps.c
new file mode 100644
index 00000000..84ed713d
--- /dev/null
+++ b/ao-tools/ao-test-gps/ao-test-gps.c
@@ -0,0 +1,241 @@
+/*
+ * Copyright © 2014 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <err.h>
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <string.h>
+#include <stdbool.h>
+#include "ao-elf.h"
+#include "ccdbg.h"
+#include "cc-usb.h"
+#include "cc.h"
+#include "ao-verbose.h"
+
+static const struct option options[] = {
+ { .name = "tty", .has_arg = 1, .val = 'T' },
+ { .name = "device", .has_arg = 1, .val = 'D' },
+ { .name = "raw", .has_arg = 0, .val = 'r' },
+ { .name = "verbose", .has_arg = 1, .val = 'v' },
+ { 0, 0, 0, 0},
+};
+
+static void usage(char *program)
+{
+ fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] main|drogue\n", program);
+ exit(1);
+}
+
+void
+done(struct cc_usb *cc, int code)
+{
+/* cc_usb_printf(cc, "a\n"); */
+ cc_usb_close(cc);
+ exit (code);
+}
+
+static int
+ends_with(char *whole, char *suffix)
+{
+ int whole_len = strlen(whole);
+ int suffix_len = strlen(suffix);
+
+ if (suffix_len > whole_len)
+ return 0;
+ return strcmp(whole + whole_len - suffix_len, suffix) == 0;
+}
+
+static int
+starts_with(char *whole, char *prefix)
+{
+ int whole_len = strlen(whole);
+ int prefix_len = strlen(prefix);
+
+ if (prefix_len > whole_len)
+ return 0;
+ return strncmp(whole, prefix, prefix_len) == 0;
+}
+
+static char **
+tok(char *line) {
+ char **strs = malloc (sizeof (char *)), *str;
+ int n = 0;
+
+ while ((str = strtok(line, " \t"))) {
+ line = NULL;
+ strs = realloc(strs, (n + 2) * sizeof (char *));
+ strs[n] = strdup(str);
+ n++;
+ }
+ strs[n] = '\0';
+ return strs;
+}
+
+static void
+free_strs(char **strs) {
+ char *str;
+ int i;
+
+ for (i = 0; (str = strs[i]) != NULL; i++)
+ free(str);
+ free(strs);
+}
+
+struct gps {
+ struct gps *next;
+ char **strs;
+};
+
+static struct gps *
+gps(struct cc_usb *usb)
+{
+ struct gps *head = NULL, **tail = &head;
+ cc_usb_printf(usb, "g\nv\n");
+ for (;;) {
+ char line[512];
+ struct gps *b;
+
+ cc_usb_getline(usb, line, sizeof (line));
+ b = malloc (sizeof (struct gps));
+ b->strs = tok(line);
+ b->next = NULL;
+ *tail = b;
+ tail = &b->next;
+ if (strstr(line, "software-version"))
+ break;
+ }
+ return head;
+}
+
+static void
+free_gps(struct gps *b) {
+ struct gps *n;
+
+ while (b) {
+ n = b->next;
+ free_strs(b->strs);
+ free(b);
+ b = n;
+ }
+}
+
+char **
+find_gps(struct gps *b, char *word0) {
+ int i;
+ for (;b; b = b->next)
+ if (b->strs[0] && !strcmp(b->strs[0], word0))
+ return b->strs;
+ return NULL;
+}
+
+int
+do_gps(struct cc_usb *usb) {
+ int count = 0;
+
+ for (;;) {
+ struct gps *b = gps(usb);
+ char **flags = find_gps(b, "Flags:");
+ char **sats = find_gps(b, "Sats:");
+ int actual_flags = strtol(flags[1], NULL, 0);
+ int actual_sats = strtol(sats[1], NULL, 0);
+
+ if (actual_flags & (1 << 4)) {
+ printf("\n");
+ printf("Flags: %s (0x%x)\n", flags[1], actual_flags);
+ printf("Sats: %s (%d)\n", sats[1], actual_sats);
+ break;
+ }
+
+ free_gps(b);
+ printf("%d", actual_sats);
+ ++count;
+ if (count >= 50) {
+ putchar('\n');
+ count = 0;
+ }
+ else if (count % 10 == 0)
+ putchar(' ');
+ fflush(stdout);
+ sleep(1);
+ }
+ return 1;
+}
+
+int
+main (int argc, char **argv)
+{
+ char *device = NULL;
+ char *filename;
+ Elf *e;
+ unsigned int s;
+ int i;
+ int c;
+ int tries;
+ struct cc_usb *cc = NULL;
+ char *tty = NULL;
+ int success;
+ int verbose = 0;
+ int ret = 0;
+
+ while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
+ switch (c) {
+ case 'T':
+ tty = optarg;
+ break;
+ case 'D':
+ device = optarg;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ ao_verbose = verbose;
+
+ if (verbose > 1)
+ ccdbg_add_debug(CC_DEBUG_BITBANG);
+
+ if (!tty)
+ tty = cc_usbdevs_find_by_arg(device, "TeleGPS");
+ if (!tty)
+ tty = cc_usbdevs_find_by_arg(device, "TeleMega");
+ if (!tty)
+ tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+ if (!tty)
+ tty = getenv("ALTOS_TTY");
+ if (!tty)
+ tty="/dev/ttyACM0";
+
+ cc = cc_usb_open(tty);
+
+ if (!cc)
+ exit(1);
+
+ if (!do_gps(cc))
+ ret = 1;
+ done(cc, ret);
+}
diff --git a/ao-tools/ao-test-igniter/ao-test-igniter.c b/ao-tools/ao-test-igniter/ao-test-igniter.c
index 6a699fe8..419c8948 100644
--- a/ao-tools/ao-test-igniter/ao-test-igniter.c
+++ b/ao-tools/ao-test-igniter/ao-test-igniter.c
@@ -190,7 +190,6 @@ main (int argc, char **argv)
if (verbose > 1)
ccdbg_add_debug(CC_DEBUG_BITBANG);
- printf ("device %s\n", device);
if (!tty)
tty = cc_usbdevs_find_by_arg(device, "TeleMega-v1.0");
if (!tty)
diff --git a/ao-tools/ao-usbload/ao-usbload.c b/ao-tools/ao-usbload/ao-usbload.c
index fd34fbdc..1b217e55 100644
--- a/ao-tools/ao-usbload/ao-usbload.c
+++ b/ao-tools/ao-usbload/ao-usbload.c
@@ -86,12 +86,13 @@ static const struct option options[] = {
{ .name = "cal", .has_arg = 1, .val = 'c' },
{ .name = "serial", .has_arg = 1, .val = 's' },
{ .name = "verbose", .has_arg = 1, .val = 'v' },
+ { .name = "wait", .has_arg = 0, .val = 'w' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
- fprintf(stderr, "usage: %s [--raw] [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] file.{elf,ihx}\n", program);
+ fprintf(stderr, "usage: %s [--raw] [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] [--cal=<radio-cal>] [--serial=<serial>] [--wait] file.{elf,ihx}\n", program);
exit(1);
}
@@ -145,7 +146,7 @@ main (int argc, char **argv)
uint32_t flash_base, flash_bound;
int has_flash_size = 0;
- while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "wrT:D:c:s:v:", options, NULL)) != -1) {
switch (c) {
case 'T':
tty = optarg;
@@ -156,6 +157,9 @@ main (int argc, char **argv)
case 'r':
raw = 1;
break;
+ case 'w':
+ cc_default_timeout = -1;
+ break;
case 'c':
cal = strtoul(optarg, &cal_end, 10);
if (cal_end == optarg || *cal_end != '\0')
@@ -209,6 +213,10 @@ main (int argc, char **argv)
if (!this_tty)
this_tty = cc_usbdevs_find_by_arg(device, "TeleMega");
if (!this_tty)
+ this_tty = cc_usbdevs_find_by_arg(device, "TeleMetrum");
+ if (!this_tty)
+ this_tty = cc_usbdevs_find_by_arg(device, "TeleGPS");
+ if (!this_tty)
this_tty = getenv("ALTOS_TTY");
if (!this_tty)
this_tty="/dev/ttyACM0";
diff --git a/ao-tools/ao-usbtrng/.gitignore b/ao-tools/ao-usbtrng/.gitignore
new file mode 100644
index 00000000..54833a2b
--- /dev/null
+++ b/ao-tools/ao-usbtrng/.gitignore
@@ -0,0 +1 @@
+ao-usbtrng
diff --git a/ao-tools/ao-usbtrng/Makefile.am b/ao-tools/ao-usbtrng/Makefile.am
new file mode 100644
index 00000000..5cbab5cf
--- /dev/null
+++ b/ao-tools/ao-usbtrng/Makefile.am
@@ -0,0 +1,11 @@
+bin_PROGRAMS=ao-usbtrng
+
+AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS)
+
+ao_usbtrng_DEPENDENCIES = $(top_builddir)/ao-tools/lib/libao-tools.a
+
+ao_usbtrng_LDADD=$(top_builddir)/ao-tools/lib/libao-tools.a $(LIBUSB_LIBS)
+
+ao_usbtrng_SOURCES=ao-usbtrng.c
+
+man_MANS = ao-usbtrng.1
diff --git a/ao-tools/ao-usbtrng/ao-usbtrng.1 b/ao-tools/ao-usbtrng/ao-usbtrng.1
new file mode 100644
index 00000000..7a1311b9
--- /dev/null
+++ b/ao-tools/ao-usbtrng/ao-usbtrng.1
@@ -0,0 +1,58 @@
+.\"
+.\" Copyright © 2009 Keith Packard <keithp@keithp.com>
+.\"
+.\" This program is free software; you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" This program is distributed in the hope that it will be useful, but
+.\" WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+.\" General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License along
+.\" with this program; if not, write to the Free Software Foundation, Inc.,
+.\" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+.\"
+.\"
+.TH AO-LOAD 1 "ao-usbtrng" ""
+.SH NAME
+ao-usbtrng \- dump random numbers from USBtrng
+.SH SYNOPSIS
+.B "ao-usbtrng"
+[\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
+\fIkbytes\fP
+.SH DESCRIPTION
+.I ao-usbtrng
+dumps random numbers from a USBtrng device
+.SH OPTIONS
+.TP
+\-T tty-device | --tty tty-device
+This selects which tty device the debugger uses to communicate with
+the target device. The special name 'BITBANG' directs ao-dbg to use
+the cp2103 connection, otherwise this should be a usb serial port
+connected to a suitable cc1111 debug node.
+.TP
+\-D AltOS-device | --device AltOS-device
+Search for a connected device. This requires an argument of one of the
+following forms:
+.IP
+usbtrng:2
+.br
+usbtrng
+.br
+2
+.IP
+Leaving out the product name will cause the tool to select a suitable
+product, leaving out the serial number will cause the tool to match
+one of the available devices.
+.SH USAGE
+.I ao-usbtrng
+opens the target device and reads the specified number of kbytes of
+random data.
+.SH AUTHOR
+Keith Packard
diff --git a/ao-tools/ao-usbtrng/ao-usbtrng.c b/ao-tools/ao-usbtrng/ao-usbtrng.c
new file mode 100644
index 00000000..232f4e3e
--- /dev/null
+++ b/ao-tools/ao-usbtrng/ao-usbtrng.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2014 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <err.h>
+#include <fcntl.h>
+#include <gelf.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <string.h>
+#include <stdbool.h>
+#include "ao-elf.h"
+#include "ccdbg.h"
+#include "cc-usb.h"
+#include "cc.h"
+#include "ao-verbose.h"
+
+static const struct option options[] = {
+ { .name = "tty", .has_arg = 1, .val = 'T' },
+ { .name = "device", .has_arg = 1, .val = 'D' },
+ { .name = "raw", .has_arg = 0, .val = 'r' },
+ { .name = "verbose", .has_arg = 1, .val = 'v' },
+ { 0, 0, 0, 0},
+};
+
+static void usage(char *program)
+{
+ fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] <kbytes>\n", program);
+ exit(1);
+}
+
+void
+done(struct cc_usb *cc, int code)
+{
+ cc_usb_close(cc);
+ exit (code);
+}
+
+int
+main (int argc, char **argv)
+{
+ char *device = NULL;
+ char *filename;
+ Elf *e;
+ unsigned int s;
+ int i;
+ int c;
+ int tries;
+ struct cc_usb *cc = NULL;
+ char *tty = NULL;
+ int success;
+ int verbose = 0;
+ int ret = 0;
+ int expected_size;
+ int kbytes;
+ uint8_t bits[1024];
+
+ while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
+ switch (c) {
+ case 'T':
+ tty = optarg;
+ break;
+ case 'D':
+ device = optarg;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ if (!argv[optind])
+ usage(argv[0]);
+
+ kbytes = atoi(argv[optind]);
+ if (kbytes < 1)
+ kbytes = 1;
+
+ ao_verbose = verbose;
+
+ if (verbose > 1)
+ ccdbg_add_debug(CC_DEBUG_BITBANG);
+
+ if (!tty)
+ tty = cc_usbdevs_find_by_arg(device, "usbtrng");
+ if (!tty)
+ tty = getenv("ALTOS_TTY");
+ if (!tty)
+ tty="/dev/ttyACM0";
+
+ cc = cc_usb_open(tty);
+
+ if (!cc)
+ exit(1);
+
+ cc_usb_printf(cc, "f %d\n", kbytes);
+
+ while (kbytes--) {
+ int i;
+ for (i = 0; i < 1024; i++)
+ bits[i] = cc_usb_getchar(cc);
+ write(1, bits, 1024);
+ }
+
+ done(cc, ret);
+}
diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c
index 38dfff04..1a4dc7a1 100644
--- a/ao-tools/lib/cc-usb.c
+++ b/ao-tools/lib/cc-usb.c
@@ -152,6 +152,8 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len)
}
}
+int cc_default_timeout = 5000;
+
/*
* Flush pending writes, fill pending reads
*/
@@ -227,7 +229,7 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input, int write_timeout)
void
cc_usb_sync(struct cc_usb *cc)
{
- if (_cc_usb_sync(cc, 0, 5000) < 0) {
+ if (_cc_usb_sync(cc, 0, cc_default_timeout) < 0) {
fprintf(stderr, "USB link timeout\n");
exit(1);
}
@@ -268,7 +270,7 @@ int
cc_usb_getchar_timeout(struct cc_usb *cc, int timeout)
{
while (cc->in_pos == cc->in_count) {
- if (_cc_usb_sync(cc, timeout, 5000) < 0) {
+ if (_cc_usb_sync(cc, timeout, cc_default_timeout) < 0) {
fprintf(stderr, "USB link timeout\n");
exit(1);
}
@@ -279,7 +281,7 @@ cc_usb_getchar_timeout(struct cc_usb *cc, int timeout)
int
cc_usb_getchar(struct cc_usb *cc)
{
- return cc_usb_getchar_timeout(cc, 5000);
+ return cc_usb_getchar_timeout(cc, cc_default_timeout);
}
void
@@ -400,7 +402,7 @@ cc_usb_open_remote(struct cc_usb *cc, int freq, char *call)
cc_usb_printf(cc, "\nc F %d\nc c %s\np\nE 0\n", freq, call);
do {
cc->in_count = cc->in_pos = 0;
- _cc_usb_sync(cc, 100, 5000);
+ _cc_usb_sync(cc, 100, cc_default_timeout);
} while (cc->in_count > 0);
cc->remote = 1;
}
@@ -459,7 +461,7 @@ cc_usb_open(char *tty)
cc_usb_printf(cc, "\nE 0\nm 0\n");
do {
cc->in_count = cc->in_pos = 0;
- _cc_usb_sync(cc, 100, 5000);
+ _cc_usb_sync(cc, 100, cc_default_timeout);
} while (cc->in_count > 0);
return cc;
}
diff --git a/ao-tools/lib/cc-usb.h b/ao-tools/lib/cc-usb.h
index e08a956b..9ed198cd 100644
--- a/ao-tools/lib/cc-usb.h
+++ b/ao-tools/lib/cc-usb.h
@@ -23,6 +23,8 @@
struct cc_usb;
+extern int cc_default_timeout;
+
struct cc_usb *
cc_usb_open(char *tty);