From ca4b20f9781b1dc6974d26952973dfe0d607478c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Apr 2014 23:38:40 -0700 Subject: ao-tools: Wait for device to become ready instead of failing For some reason, USB devices take 'a while' to become usable; instead of bailing immediately, sit around waiting to see if the device becomes usable if we get an EBUSY or EACCES error. Signed-off-by: Keith Packard --- ao-tools/lib/cc-usb.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'ao-tools/lib') diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index d7ac138c..a3a19d5c 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -412,19 +412,35 @@ cc_usb_close_remote(struct cc_usb *cc) static struct termios save_termios; +#include + 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; - 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; -- cgit v1.2.3 From fd406000659a11862e05c22dbb20cdb738f56b01 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 30 Apr 2014 22:11:39 -0700 Subject: ao-telem: Dump orientation field from TeleMega sensor telemetry packet Signed-off-by: Keith Packard --- ao-tools/ao-telem/ao-telem.c | 3 ++- ao-tools/lib/cc-telemetry.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'ao-tools/lib') diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c index f1755b82..da873838 100644 --- a/ao-tools/ao-telem/ao-telem.c +++ b/ao-tools/ao-telem/ao-telem.c @@ -158,7 +158,8 @@ main (int argc, char **argv) printf ("\n"); break; case AO_TELEMETRY_MEGA_SENSOR: - printf ("accel %5d pres %9d temp %5d accel_x %5d accel_y %5d accel_z %5d gyro_x %5d gyro_y %5d gyro_z %5d mag_x %5d mag_y %5d mag_z %5d\n", + printf ("orient %3d accel %5d pres %9d temp %5d accel_x %5d accel_y %5d accel_z %5d gyro_x %5d gyro_y %5d gyro_z %5d mag_x %5d mag_y %5d mag_z %5d\n", + telem.mega_sensor.orient, telem.mega_sensor.accel, telem.mega_sensor.pres, telem.mega_sensor.temp, diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h index c28aceb8..d64c4b30 100644 --- a/ao-tools/lib/cc-telemetry.h +++ b/ao-tools/lib/cc-telemetry.h @@ -157,7 +157,7 @@ struct ao_telemetry_mega_sensor { uint16_t tick; /* 2 */ uint8_t type; /* 4 */ - uint8_t pad5; /* 5 */ + uint8_t orient; /* 5 angle from vertical */ int16_t accel; /* 6 Z axis */ int32_t pres; /* 8 Pa * 10 */ -- cgit v1.2.3 From 0223fced2c6d2b9f63ede6258afae46c3f55c200 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 30 Apr 2014 22:13:44 -0700 Subject: ao-tools: Clean up ao-sym structure an initializers Remove unused 'default_addr' field. Use named initializers when setting up the struct. Signed-off-by: Keith Packard --- ao-tools/lib/ao-editaltos.c | 26 ++++++++++++++++++++------ ao-tools/lib/ao-hex.h | 1 - 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'ao-tools/lib') diff --git a/ao-tools/lib/ao-editaltos.c b/ao-tools/lib/ao-editaltos.c index a8b64098..7547c82c 100644 --- a/ao-tools/lib/ao-editaltos.c +++ b/ao-tools/lib/ao-editaltos.c @@ -20,12 +20,26 @@ #include "ao-editaltos.h" struct ao_sym ao_symbols[] = { - - { 0, 0, "ao_romconfig_version", 1 }, - { 0, 0, "ao_romconfig_check", 1 }, - { 0, 0, "ao_serial_number", 1 }, - { 0, 0, "ao_radio_cal", 0 }, - { 0, 0, "ao_usb_descriptors", 0 }, + { + .name = "ao_romconfig_version", + .required = 1 + }, + { + .name = "ao_romconfig_check", + .required = 1 + }, + { + .name = "ao_serial_number", + .required = 1 + }, + { + .name = "ao_radio_cal", + .required = 0 + }, + { + .name = "ao_usb_descriptors", + .required = 0 + }, }; #define NUM_SYMBOLS 5 diff --git a/ao-tools/lib/ao-hex.h b/ao-tools/lib/ao-hex.h index 98497460..eb510ba2 100644 --- a/ao-tools/lib/ao-hex.h +++ b/ao-tools/lib/ao-hex.h @@ -51,7 +51,6 @@ struct ao_hex_image { struct ao_sym { unsigned addr; - unsigned default_addr; char *name; bool required; bool found; -- cgit v1.2.3 From d63319f6f29ef714bb1d5c359c2448f63e7a4534 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 25 May 2014 20:58:24 -0700 Subject: ao-tools: Add cc_usb_write function This writes raw bytes to the USB port; useful for sending binary data for flashing or the upcoming flight test stuff. Signed-off-by: Keith Packard --- ao-tools/lib/cc-usb.c | 40 ++++++++++++++++++++++++++++++++++------ ao-tools/lib/cc-usb.h | 3 +++ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'ao-tools/lib') diff --git a/ao-tools/lib/cc-usb.c b/ao-tools/lib/cc-usb.c index a3a19d5c..38dfff04 100644 --- a/ao-tools/lib/cc-usb.c +++ b/ao-tools/lib/cc-usb.c @@ -53,6 +53,7 @@ struct cc_usb { struct cc_hex_read hex_buf[CC_NUM_HEX_READ]; int hex_count; + int show_input; int remote; }; @@ -156,7 +157,7 @@ cc_usb_dbg(int indent, uint8_t *bytes, int len) */ static int -_cc_usb_sync(struct cc_usb *cc, int wait_for_input) +_cc_usb_sync(struct cc_usb *cc, int wait_for_input, int write_timeout) { int ret; struct pollfd fds; @@ -165,7 +166,7 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input) fds.fd = cc->fd; for (;;) { if (cc->hex_count || cc->out_count) - timeout = 5000; + timeout = write_timeout; else if (wait_for_input && cc->in_pos == cc->in_count) timeout = wait_for_input; else @@ -200,6 +201,10 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input) cc->in_count += ret; if (cc->hex_count) cc_handle_hex_read(cc); + if (cc->show_input && cc->in_count) { + write(2, cc->in_buf, cc->in_count); + cc->in_count = 0; + } } else if (ret < 0) perror("read"); } @@ -222,7 +227,7 @@ _cc_usb_sync(struct cc_usb *cc, int wait_for_input) void cc_usb_sync(struct cc_usb *cc) { - if (_cc_usb_sync(cc, 0) < 0) { + if (_cc_usb_sync(cc, 0, 5000) < 0) { fprintf(stderr, "USB link timeout\n"); exit(1); } @@ -263,7 +268,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) < 0) { + if (_cc_usb_sync(cc, timeout, 5000) < 0) { fprintf(stderr, "USB link timeout\n"); exit(1); } @@ -395,7 +400,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); + _cc_usb_sync(cc, 100, 5000); } while (cc->in_count > 0); cc->remote = 1; } @@ -454,7 +459,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); + _cc_usb_sync(cc, 100, 5000); } while (cc->in_count > 0); return cc; } @@ -468,3 +473,26 @@ cc_usb_close(struct cc_usb *cc) close (cc->fd); free (cc); } + +int +cc_usb_write(struct cc_usb *cc, void *buf, int c) +{ + uint8_t *b; + int this_time; + + b = buf; + cc->show_input = 1; + while (c > 0) { + this_time = c; + if (this_time > CC_OUT_BUF - cc->out_count) + this_time = CC_OUT_BUF - cc->out_count; + memcpy(cc->out_buf + cc->out_count, b, this_time); + cc->out_count += this_time; + c -= this_time; + b += this_time; + while (cc->out_count >= CC_OUT_BUF) { + _cc_usb_sync(cc, 0, -1); + } + } + return 1; +} diff --git a/ao-tools/lib/cc-usb.h b/ao-tools/lib/cc-usb.h index f1193456..e08a956b 100644 --- a/ao-tools/lib/cc-usb.h +++ b/ao-tools/lib/cc-usb.h @@ -65,6 +65,9 @@ cc_usb_getline(struct cc_usb *cc, char *line, int max); void cc_usb_printf(struct cc_usb *cc, char *format, ...); +int +cc_usb_write(struct cc_usb *cc, void *buf, int c); + void cc_usb_open_remote(struct cc_usb *cc, int freq, char *call); -- cgit v1.2.3 From 428d09294ba0395fedd71346ad00fd90a4cdde97 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 7 Jun 2014 21:12:44 -0700 Subject: ao-tools: Parse TeleGPS state value from gps location packet TeleGPS encodes state in a spare gps location packet byte, masking in 0x80 to signify that the state value is valid Signed-off-by: Keith Packard --- ao-tools/ao-telem/ao-telem.c | 2 ++ ao-tools/lib/cc-telemetry.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'ao-tools/lib') diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c index da873838..75f94ec1 100644 --- a/ao-tools/ao-telem/ao-telem.c +++ b/ao-tools/ao-telem/ao-telem.c @@ -145,6 +145,8 @@ main (int argc, char **argv) telem.location.ground_speed / 100.0, telem.location.climb_rate / 100.0, telem.location.course * 2); + if ((telem.location.state & AO_GPS_STATE_VALID)) + printf (" state %1d", telem.location.state & ~(AO_GPS_STATE_VALID)); printf ("\n"); break; case AO_TELEMETRY_SATELLITE: diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h index d64c4b30..35cca13b 100644 --- a/ao-tools/lib/cc-telemetry.h +++ b/ao-tools/lib/cc-telemetry.h @@ -90,6 +90,8 @@ struct ao_telemetry_configuration { #define AO_GPS_MODE_MANUAL 'M' #define AO_GPS_MODE_SIMULATED 'S' +#define AO_GPS_STATE_VALID 0x80 + struct ao_telemetry_location { uint16_t serial; /* 0 */ uint16_t tick; /* 2 */ @@ -112,7 +114,7 @@ struct ao_telemetry_location { uint16_t ground_speed; /* 26 cm/s */ int16_t climb_rate; /* 28 cm/s */ uint8_t course; /* 30 degrees / 2 */ - uint8_t unused[1]; /* 31 */ + uint8_t state; /* 31 */ /* 32 */ }; -- cgit v1.2.3 From f6d633d73a8f826cf2a3128e3e234bd11af49718 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jun 2014 09:44:57 -0700 Subject: Revert "ao-tools: Parse TeleGPS state value from gps location packet" This reverts commit 428d09294ba0395fedd71346ad00fd90a4cdde97. --- ao-tools/ao-telem/ao-telem.c | 2 -- ao-tools/lib/cc-telemetry.h | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'ao-tools/lib') diff --git a/ao-tools/ao-telem/ao-telem.c b/ao-tools/ao-telem/ao-telem.c index 75f94ec1..da873838 100644 --- a/ao-tools/ao-telem/ao-telem.c +++ b/ao-tools/ao-telem/ao-telem.c @@ -145,8 +145,6 @@ main (int argc, char **argv) telem.location.ground_speed / 100.0, telem.location.climb_rate / 100.0, telem.location.course * 2); - if ((telem.location.state & AO_GPS_STATE_VALID)) - printf (" state %1d", telem.location.state & ~(AO_GPS_STATE_VALID)); printf ("\n"); break; case AO_TELEMETRY_SATELLITE: diff --git a/ao-tools/lib/cc-telemetry.h b/ao-tools/lib/cc-telemetry.h index 35cca13b..d64c4b30 100644 --- a/ao-tools/lib/cc-telemetry.h +++ b/ao-tools/lib/cc-telemetry.h @@ -90,8 +90,6 @@ struct ao_telemetry_configuration { #define AO_GPS_MODE_MANUAL 'M' #define AO_GPS_MODE_SIMULATED 'S' -#define AO_GPS_STATE_VALID 0x80 - struct ao_telemetry_location { uint16_t serial; /* 0 */ uint16_t tick; /* 2 */ @@ -114,7 +112,7 @@ struct ao_telemetry_location { uint16_t ground_speed; /* 26 cm/s */ int16_t climb_rate; /* 28 cm/s */ uint8_t course; /* 30 degrees / 2 */ - uint8_t state; /* 31 */ + uint8_t unused[1]; /* 31 */ /* 32 */ }; -- cgit v1.2.3