summaryrefslogtreecommitdiff
path: root/ao-tools
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-05-19 10:14:43 -0700
committerKeith Packard <keithp@keithp.com>2015-05-19 10:14:43 -0700
commitb67e6ae8ce34ef119da96b442776bb3d78b4f874 (patch)
treede6284b5dae4399f6372392787fa723f60b3c882 /ao-tools
parent2b57158737f85c7009658b3e923c66794f01bbdf (diff)
ao-dump-up: Add --wait option to make testing µPusb easier
The --wait option hangs around until a suitable device appears, so that you can test a pile of µPusb devices without needing to constantly interact with the command line. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools')
-rw-r--r--ao-tools/ao-dump-up/ao-dump-up.c28
-rw-r--r--ao-tools/lib/cc-usb.c4
2 files changed, 26 insertions, 6 deletions
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/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,