summaryrefslogtreecommitdiff
path: root/ao-tools
diff options
context:
space:
mode:
Diffstat (limited to 'ao-tools')
-rw-r--r--ao-tools/Makefile.am3
-rw-r--r--ao-tools/ao-cal-freq/.gitignore1
-rw-r--r--ao-tools/ao-cal-freq/Makefile.am11
-rw-r--r--ao-tools/ao-cal-freq/ao-cal-freq.158
-rw-r--r--ao-tools/ao-cal-freq/ao-cal-freq.c280
-rw-r--r--ao-tools/ao-dump-up/ao-dump-up.c28
-rw-r--r--ao-tools/ao-flash/Makefile.am4
-rwxr-xr-x[-rw-r--r--]ao-tools/ao-flash/ao-flash-stm0
-rwxr-xr-xao-tools/ao-flash/ao-flash-stm32f0x16
-rw-r--r--ao-tools/ao-flash/ao-flash-stm32f0x.136
-rw-r--r--ao-tools/ao-list/ao-list.c4
-rw-r--r--ao-tools/ao-mega/ao-mega.c5
-rw-r--r--ao-tools/ao-usbtrng/ao-usbtrng.122
-rw-r--r--ao-tools/ao-usbtrng/ao-usbtrng.c44
-rw-r--r--ao-tools/lib/cc-usb.c4
-rw-r--r--ao-tools/lib/cc-usbdev.c6
-rw-r--r--ao-tools/lib/cc.h2
17 files changed, 473 insertions, 51 deletions
diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am
index 6a170cbd..66d2560e 100644
--- a/ao-tools/Makefile.am
+++ b/ao-tools/Makefile.am
@@ -2,7 +2,8 @@ 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-gps ao-usbtrng
+ ao-test-flash ao-cal-accel ao-test-gps ao-usbtrng \
+ ao-cal-freq
if LIBSTLINK
SUBDIRS += ao-stmload
endif
diff --git a/ao-tools/ao-cal-freq/.gitignore b/ao-tools/ao-cal-freq/.gitignore
new file mode 100644
index 00000000..4fe14865
--- /dev/null
+++ b/ao-tools/ao-cal-freq/.gitignore
@@ -0,0 +1 @@
+ao-cal-freq
diff --git a/ao-tools/ao-cal-freq/Makefile.am b/ao-tools/ao-cal-freq/Makefile.am
new file mode 100644
index 00000000..e11c2b0a
--- /dev/null
+++ b/ao-tools/ao-cal-freq/Makefile.am
@@ -0,0 +1,11 @@
+bin_PROGRAMS=ao-cal-freq
+
+AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS)
+
+ao_cal_freq_DEPENDENCIES = $(top_builddir)/ao-tools/lib/libao-tools.a
+
+ao_cal_freq_LDADD=$(top_builddir)/ao-tools/lib/libao-tools.a $(LIBUSB_LIBS) -lm
+
+ao_cal_freq_SOURCES=ao-cal-freq.c
+
+man_MANS = ao-cal-freq.1
diff --git a/ao-tools/ao-cal-freq/ao-cal-freq.1 b/ao-tools/ao-cal-freq/ao-cal-freq.1
new file mode 100644
index 00000000..bfc3101c
--- /dev/null
+++ b/ao-tools/ao-cal-freq/ao-cal-freq.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-cal-freq" ""
+.SH NAME
+ao-cal-freq \- Calibrate AltOS flight computer frequency
+.SH SYNOPSIS
+.B "ao-cal-freq"
+[\-T \fItty-device\fP]
+[\--tty \fItty-device\fP]
+[\-D \fIaltos-device\fP]
+[\--device \fIaltos-device\fP]
+.SH DESCRIPTION
+.I ao-cal-freq
+drives the frequency calibration process and saves the result.
+.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
+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-cal-freq
+opens the target device, interactively calibrates the frequency, then
+shows the resulting calibration values and saves them to configuration
+memory.
+.SH AUTHOR
+Keith Packard
diff --git a/ao-tools/ao-cal-freq/ao-cal-freq.c b/ao-tools/ao-cal-freq/ao-cal-freq.c
new file mode 100644
index 00000000..464faf0f
--- /dev/null
+++ b/ao-tools/ao-cal-freq/ao-cal-freq.c
@@ -0,0 +1,280 @@
+/*
+ * 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 <termios.h>
+#include <math.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>]\n", program);
+ exit(1);
+}
+
+void
+done(struct cc_usb *cc, int code)
+{
+ 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 flash {
+ struct flash *next;
+ char line[512];
+ char **strs;
+};
+
+static struct flash *
+flash(struct cc_usb *usb)
+{
+ struct flash *head = NULL, **tail = &head;
+ cc_usb_printf(usb, "c s\nv\n");
+ for (;;) {
+ char line[512];
+ struct flash *b;
+
+ cc_usb_getline(usb, line, sizeof (line));
+ b = malloc (sizeof (struct flash));
+ strcpy(b->line, line);
+ b->strs = tok(line);
+ b->next = NULL;
+ *tail = b;
+ tail = &b->next;
+ if (strstr(line, "software-version"))
+ break;
+ }
+ return head;
+}
+
+static void
+free_flash(struct flash *b) {
+ struct flash *n;
+
+ while (b) {
+ n = b->next;
+ free_strs(b->strs);
+ free(b);
+ b = n;
+ }
+}
+
+char **
+find_flash(struct flash *b, char *word0) {
+ int i;
+ for (;b; b = b->next) {
+ if (strstr(b->line, word0))
+ return b->strs;
+ }
+ return NULL;
+}
+
+void
+await_key(void)
+{
+ struct termios termios, termios_save;
+ char buf[512];
+
+ tcgetattr(0, &termios);
+ termios_save = termios;
+ cfmakeraw(&termios);
+ tcsetattr(0, TCSAFLUSH, &termios);
+ read(0, buf, sizeof (buf));
+ tcsetattr(0, TCSAFLUSH, &termios_save);
+}
+
+int
+do_cal(struct cc_usb *usb) {
+ struct flash *b;
+ char line[1024];
+ double measured_freq;
+ char **cur_freq_words;
+ char **cur_cal_words;
+ char *line_end;
+ int cur_freq;
+ int cur_cal;
+ int new_cal;
+
+ cc_usb_printf(usb, "E 0\n");
+
+ for(;;) {
+ cc_usb_printf(usb, "C 1\n");
+ cc_usb_sync(usb);
+
+ printf("Generating RF carrier. Please enter measured frequency [enter for done]: ");
+ fflush(stdout);
+ fgets(line, sizeof (line) - 1, stdin);
+ cc_usb_printf(usb, "C 0\n");
+ cc_usb_sync(usb);
+
+ measured_freq = strtod(line, &line_end);
+ if (line_end == line)
+ break;
+
+ b = flash(usb);
+
+ cur_cal_words = find_flash(b, "Radio cal:");
+ cur_freq_words = find_flash(b, "Frequency:");
+
+ if (!cur_cal_words || !cur_freq_words) {
+ printf("no response\n");
+ return 0;
+ }
+
+ cur_cal = atoi(cur_cal_words[2]);
+ cur_freq = atoi(cur_freq_words[1]);
+
+ printf ("Current radio calibration %d\n", cur_cal);
+ printf ("Current radio frequency: %d\n", cur_freq);
+
+
+ new_cal = floor ((((double) cur_freq / 1000.0) / measured_freq) * cur_cal + 0.5);
+
+ printf ("Programming flash with cal value %d\n", new_cal);
+
+ cc_usb_printf (usb, "c f %d\nc w\n", new_cal);
+ cc_usb_sync(usb);
+ }
+ 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;
+ int expected_size;
+
+ 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, "AltosFlash");
+ if (!tty)
+ tty = cc_usbdevs_find_by_arg(device, "TeleMega");
+ if (!tty)
+ tty = getenv("ALTOS_TTY");
+ if (!tty)
+ tty="/dev/ttyACM0";
+
+ cc = cc_usb_open(tty);
+
+ if (!cc)
+ exit(1);
+
+ if (!do_cal(cc))
+ ret = 1;
+ done(cc, ret);
+}
diff --git a/ao-tools/ao-dump-up/ao-dump-up.c b/ao-tools/ao-dump-up/ao-dump-up.c
index 6268dc8b..b1f85af6 100644
--- a/ao-tools/ao-dump-up/ao-dump-up.c
+++ b/ao-tools/ao-dump-up/ao-dump-up.c
@@ -29,12 +29,13 @@
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);
}
@@ -134,7 +135,7 @@ 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;
}
}
@@ -165,9 +166,13 @@ main (int argc, char **argv)
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 +184,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)
diff --git a/ao-tools/ao-flash/Makefile.am b/ao-tools/ao-flash/Makefile.am
index 6b7ea6bb..4231dc21 100644
--- a/ao-tools/ao-flash/Makefile.am
+++ b/ao-tools/ao-flash/Makefile.am
@@ -1,3 +1,3 @@
-bin_SCRIPTS=ao-flash-stm ao-flash-lpc
+bin_SCRIPTS=ao-flash-stm ao-flash-lpc ao-flash-stm32f0x
-man_MANS = ao-flash-stm.1 ao-flash-lpc.1 \ No newline at end of file
+man_MANS = ao-flash-stm.1 ao-flash-lpc.1 ao-flash-stm32f0x.1
diff --git a/ao-tools/ao-flash/ao-flash-stm b/ao-tools/ao-flash/ao-flash-stm
index 9eebf5d2..9eebf5d2 100644..100755
--- a/ao-tools/ao-flash/ao-flash-stm
+++ b/ao-tools/ao-flash/ao-flash-stm
diff --git a/ao-tools/ao-flash/ao-flash-stm32f0x b/ao-tools/ao-flash/ao-flash-stm32f0x
new file mode 100755
index 00000000..45643a4f
--- /dev/null
+++ b/ao-tools/ao-flash/ao-flash-stm32f0x
@@ -0,0 +1,16 @@
+#!/bin/sh
+case "$#" in
+0)
+ echo "usage: $0 <filename> ..."
+ exit 1
+ ;;
+esac
+cmds=/tmp/flash$$
+trap "rm $cmds" 0 1 15
+file="$1"
+echo "program $file verify reset" > $cmds
+openocd \
+ -f interface/stlink-v2.cfg \
+ -f target/stm32f0x_stlink.cfg \
+ -f $cmds \
+ -c shutdown
diff --git a/ao-tools/ao-flash/ao-flash-stm32f0x.1 b/ao-tools/ao-flash/ao-flash-stm32f0x.1
new file mode 100644
index 00000000..07ff5b59
--- /dev/null
+++ b/ao-tools/ao-flash/ao-flash-stm32f0x.1
@@ -0,0 +1,36 @@
+.\"
+.\" Copyright © 2013 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-FLASH-LPC 1 "ao-flash-stm32f0x" ""
+.SH NAME
+ao-flash-stm32f0x \- flash a program to a STM32F0x-based AltOS device using openocd
+.SH SYNOPSIS
+.B "ao-flash-stm32f0x"
+\fIfile.elf\fP
+.SH DESCRIPTION
+.I ao-flash-stm32f0x
+loads the specified .elf file into the target device flash memory.
+.SH USAGE
+.I ao-flash-stm32f0x
+is a simple script that passes the correct arguments to openocd to
+load a file into the target device via a connected STlink
+debugging dongle.
+.SH "SEE ALSO"
+openocd(1)
+.SH AUTHOR
+Keith Packard
diff --git a/ao-tools/ao-list/ao-list.c b/ao-tools/ao-list/ao-list.c
index c4b43d8f..4c065e79 100644
--- a/ao-tools/ao-list/ao-list.c
+++ b/ao-tools/ao-list/ao-list.c
@@ -28,12 +28,12 @@ main (int argc, char **argv)
struct cc_usbdev *dev;
int i;
- devs = cc_usbdevs_scan();
+ devs = cc_usbdevs_scan(TRUE);
if (devs) {
for (i = 0; i < devs->ndev; i++) {
dev = devs->dev[i];
printf ("%-20.20s %6d %s\n",
- dev->product, dev->serial, dev->tty);
+ dev->product, dev->serial, dev->tty ? dev->tty : "(none)");
}
cc_usbdevs_free(devs);
}
diff --git a/ao-tools/ao-mega/ao-mega.c b/ao-tools/ao-mega/ao-mega.c
index 523229e6..cfb58bb4 100644
--- a/ao-tools/ao-mega/ao-mega.c
+++ b/ao-tools/ao-mega/ao-mega.c
@@ -85,7 +85,7 @@ main (int argc, char **argv)
if (cc_mega_parse(line, &log)) {
if (log.is_config) {
- printf ("kind %d\n", log.u.config_int.kind);
+ printf ("config %2d %s", log.u.config_int.kind, line);
} else {
printf ("tick %5d ", log.tick);
switch (log.type) {
@@ -126,8 +126,7 @@ main (int argc, char **argv)
printf (" s%d %6d",
j, log.u.volt.sense[j]);
}
- printf ("pyro %04x\n", log.u.volt.pyro);
- printf ("\n");
+ printf (" pyro %04x\n", log.u.volt.pyro);
break;
default:
printf ("type %c\n", log.type, log.tick);
diff --git a/ao-tools/ao-usbtrng/ao-usbtrng.1 b/ao-tools/ao-usbtrng/ao-usbtrng.1
index 7a1311b9..eabdd8a1 100644
--- a/ao-tools/ao-usbtrng/ao-usbtrng.1
+++ b/ao-tools/ao-usbtrng/ao-usbtrng.1
@@ -16,28 +16,28 @@
.\" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
.\"
.\"
-.TH AO-LOAD 1 "ao-usbtrng" ""
+.TH AO-USBTRNG 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
+.B "ao-usbtrng" [OPTION...] [KBYTES]
.SH DESCRIPTION
.I ao-usbtrng
-dumps random numbers from a USBtrng device
+dumps random numbers from a USBtrng device. If provided KBYTES specifies the number of 1024 byte blocks to produce on standard output. Without KBYTES
+.I ao-usbtrng
+produces random bytes continuously until killed.
.SH OPTIONS
.TP
-\-T tty-device | --tty tty-device
+\-v, --verbose
+increase verbosity
+.TP
+\-T, -tty=TTYDEVICE
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
+\-D, --device=ALTOSDEVICE
Search for a connected device. This requires an argument of one of the
following forms:
.IP
@@ -52,7 +52,7 @@ 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
+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
index 232f4e3e..456885d9 100644
--- a/ao-tools/ao-usbtrng/ao-usbtrng.c
+++ b/ao-tools/ao-usbtrng/ao-usbtrng.c
@@ -35,14 +35,13 @@
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' },
+ { .name = "verbose", .has_arg = 0, .val = 'v' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
- fprintf(stderr, "usage: %s [--verbose=<verbose>] [--device=<device>] [-tty=<tty>] <kbytes>\n", program);
+ fprintf(stderr, "usage: %s [--verbose] [--device=<AltOS-device>] [-tty=<tty>] [<kbytes>]\n", program);
exit(1);
}
@@ -58,21 +57,17 @@ 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;
+ int kbytes = 0; /* 0 == continuous */
+ int written;
uint8_t bits[1024];
- while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "vT:D:", options, NULL)) != -1) {
switch (c) {
case 'T':
tty = optarg;
@@ -89,12 +84,8 @@ main (int argc, char **argv)
}
}
- if (!argv[optind])
- usage(argv[0]);
-
- kbytes = atoi(argv[optind]);
- if (kbytes < 1)
- kbytes = 1;
+ if (optind < argc)
+ kbytes = atoi(argv[optind]);
ao_verbose = verbose;
@@ -113,13 +104,22 @@ main (int argc, char **argv)
if (!cc)
exit(1);
- cc_usb_printf(cc, "f %d\n", kbytes);
+ if (kbytes) {
+ 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);
+ while (kbytes--) {
+ for (i = 0; i < 1024; i++)
+ bits[i] = cc_usb_getchar(cc);
+ write(1, bits, 1024);
+ }
+ } else { /* 0 == continuous */
+ written = 0;
+ while (written >= 0) {
+ cc_usb_printf(cc, "f 1\n");
+ for (i = 0; i < 1024; i++)
+ bits[i] = cc_usb_getchar(cc);
+ written = write(1, bits, 1024);
+ }
}
done(cc, ret);
diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c
index 1a4dc7a1..1e023c7e 100644
--- a/ao-tools/lib/cc-usb.c
+++ b/ao-tools/lib/cc-usb.c
@@ -207,8 +207,10 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input, int write_timeout)
write(2, cc->in_buf, cc->in_count);
cc->in_count = 0;
}
- } else if (ret < 0)
+ } else if (ret <= 0) {
perror("read");
+ return -1;
+ }
}
if (fds.revents & POLLOUT) {
ret = write(cc->fd, cc->out_buf,
diff --git a/ao-tools/lib/cc-usbdev.c b/ao-tools/lib/cc-usbdev.c
index 95bfa244..6c3ba591 100644
--- a/ao-tools/lib/cc-usbdev.c
+++ b/ao-tools/lib/cc-usbdev.c
@@ -219,7 +219,7 @@ is_am(int idVendor, int idProduct) {
}
struct cc_usbdevs *
-cc_usbdevs_scan(void)
+cc_usbdevs_scan(int non_tty)
{
int e;
struct dirent **ents;
@@ -241,7 +241,7 @@ cc_usbdevs_scan(void)
dir = cc_fullname(USB_DEVICES, ents[e]->d_name);
dev = usb_scan_device(dir);
free(dir);
- if (is_am(dev->idVendor, dev->idProduct) && dev->tty) {
+ if (is_am(dev->idVendor, dev->idProduct) && (non_tty || dev->tty)) {
if (devs->dev)
devs->dev = realloc(devs->dev,
(devs->ndev + 1) * sizeof (struct usbdev *));
@@ -274,7 +274,7 @@ match_dev(char *product, int serial)
int i;
char *tty = NULL;
- devs = cc_usbdevs_scan();
+ devs = cc_usbdevs_scan(FALSE);
if (!devs)
return NULL;
for (i = 0; i < devs->ndev; i++) {
diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h
index bff4b2c9..ff95e4fc 100644
--- a/ao-tools/lib/cc.h
+++ b/ao-tools/lib/cc.h
@@ -50,7 +50,7 @@ void
cc_usbdevs_free(struct cc_usbdevs *usbdevs);
struct cc_usbdevs *
-cc_usbdevs_scan(void);
+cc_usbdevs_scan(int non_tty);
char *
cc_usbdevs_find_by_arg(char *arg, char *default_product);