projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
altosui/altosuilib/altoslib: Move more stuff out of autosui. Reduce site map memory
[fw/altos]
/
ao-tools
/
lib
/
cc-usb.c
diff --git
a/ao-tools/lib/cc-usb.c
b/ao-tools/lib/cc-usb.c
index f82752435d03c48126253541e8b5af8d5a653b63..a3a19d5cda58c875fce4c0dc90d54d15013fa3a2 100644
(file)
--- a/
ao-tools/lib/cc-usb.c
+++ b/
ao-tools/lib/cc-usb.c
@@
-123,9
+123,10
@@
cc_handle_hex_read(struct cc_usb *cc)
static void
cc_usb_dbg(int indent, uint8_t *bytes, int len)
{
static void
cc_usb_dbg(int indent, uint8_t *bytes, int len)
{
-
int
eol = 1;
+
static int
eol = 1;
int i;
uint8_t c;
int i;
uint8_t c;
+ ccdbg_debug(CC_DEBUG_BITBANG, "<<<%d bytes>>>", len);
while (len--) {
c = *bytes++;
if (eol) {
while (len--) {
c = *bytes++;
if (eol) {
@@
-135,12
+136,17
@@
cc_usb_dbg(int indent, uint8_t *bytes, int len)
}
switch (c) {
case '\r':
}
switch (c) {
case '\r':
- ccdbg_debug(CC_DEBUG_BITBANG, "
^M
");
+ ccdbg_debug(CC_DEBUG_BITBANG, "
\\r
");
break;
case '\n':
eol = 1;
break;
case '\n':
eol = 1;
+ ccdbg_debug(CC_DEBUG_BITBANG, "\\n\n");
+ break;
default:
default:
- ccdbg_debug(CC_DEBUG_BITBANG, "%c", c);
+ if (c < ' ' || c > '~')
+ ccdbg_debug(CC_DEBUG_BITBANG, "\\%02x", c);
+ else
+ ccdbg_debug(CC_DEBUG_BITBANG, "%c", c);
}
}
}
}
}
}
@@
-406,19
+412,35
@@
cc_usb_close_remote(struct cc_usb *cc)
static struct termios save_termios;
static struct termios save_termios;
+#include <errno.h>
+
struct cc_usb *
cc_usb_open(char *tty)
{
struct cc_usb *cc;
struct termios termios;
struct cc_usb *
cc_usb_open(char *tty)
{
struct cc_usb *cc;
struct termios termios;
+ int i;
if (!tty)
tty = DEFAULT_TTY;
cc = calloc (sizeof (struct cc_usb), 1);
if (!cc)
return NULL;
if (!tty)
tty = DEFAULT_TTY;
cc = calloc (sizeof (struct cc_usb), 1);
if (!cc)
return NULL;
- cc->fd = open(tty, O_RDWR | O_NONBLOCK);
- if (cc->fd < 0) {
+ i = 0;
+ for (;;) {
+ cc->fd = open(tty, O_RDWR | O_NONBLOCK);
+ if (cc->fd >= 0)
+ break;
+ i++;
+ if (errno == EBUSY || errno == EPERM || errno == EACCES) {
+ fprintf(stderr, "open failed, pausing");
+ perror(tty);
+ if (i < 20) {
+ sleep(3);
+ continue;
+ }
+ }
+
perror(tty);
free (cc);
return NULL;
perror(tty);
free (cc);
return NULL;