From 2cf4d76745713051c6ee9cf8d4b386c25f822433 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 May 2017 21:30:29 -0700 Subject: altos/telefireone-v1.0: Fix confusing defines about config storage USE_INTERNAL_FLASH is about storing config data in internal flash, and should be on for telefireone. Signed-off-by: Keith Packard --- src/telefireone-v1.0/ao_pins.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/telefireone-v1.0/ao_pins.h b/src/telefireone-v1.0/ao_pins.h index b2f5a5ab..d36d9d82 100644 --- a/src/telefireone-v1.0/ao_pins.h +++ b/src/telefireone-v1.0/ao_pins.h @@ -34,7 +34,7 @@ #define HAS_EEPROM 1 #define HAS_LOG 1 #define HAS_PAD 1 -#define USE_INTERNAL_FLASH 0 +#define USE_INTERNAL_FLASH 1 #define IGNITE_ON_P0 0 #define PACKET_HAS_MASTER 0 #define PACKET_HAS_SLAVE 0 -- cgit v1.2.3 From 6e3b7206f9ab2f76089553d7c881a96e0204a4a3 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 May 2017 21:35:05 -0700 Subject: altos/telebt-v4.0: Remove HAS_POLLCHAR This isn't being used anymore. Signed-off-by: Keith Packard --- src/telebt-v4.0/ao_pins.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/telebt-v4.0/ao_pins.h b/src/telebt-v4.0/ao_pins.h index baf3db69..0082b2b5 100644 --- a/src/telebt-v4.0/ao_pins.h +++ b/src/telebt-v4.0/ao_pins.h @@ -75,7 +75,6 @@ #define HAS_APRS 0 #define HAS_ACCEL 0 #define HAS_AES 0 -#define HAS_POLLCHAR 1 #define HAS_SPI_1 1 #define SPI_1_PA5_PA6_PA7 1 /* CC1200 */ -- cgit v1.2.3 From e37f9719745b7fba5bfb1b1517ce7b70efa7a3a2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 19 May 2017 21:36:01 -0700 Subject: altos/telebt-v3.0: Add send_packet command Useful for doing host-based RF protocols. Signed-off-by: Keith Packard --- src/telebt-v3.0/Makefile | 1 + src/telebt-v3.0/ao_telebt.c | 2 ++ 2 files changed, 3 insertions(+) (limited to 'src') diff --git a/src/telebt-v3.0/Makefile b/src/telebt-v3.0/Makefile index 40d1f6e4..4636c046 100644 --- a/src/telebt-v3.0/Makefile +++ b/src/telebt-v3.0/Makefile @@ -55,6 +55,7 @@ ALTOS_SRC = \ ao_convert_volt.c \ ao_packet_master.c \ ao_packet.c \ + ao_send_packet.c \ ao_monitor.c \ $(PROFILE) \ $(SAMPLE_PROFILE) \ diff --git a/src/telebt-v3.0/ao_telebt.c b/src/telebt-v3.0/ao_telebt.c index 8775d993..63633c90 100644 --- a/src/telebt-v3.0/ao_telebt.c +++ b/src/telebt-v3.0/ao_telebt.c @@ -23,6 +23,7 @@ #include #include #include +#include #if HAS_SAMPLE_PROFILE #include #endif @@ -53,6 +54,7 @@ main(void) ao_radio_init(); ao_packet_master_init(); ao_monitor_init(); + ao_send_packet_init(); ao_config_init(); -- cgit v1.2.3 From fed48732828c85ae56106cd72c5aeaaad47c552f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 11 Jun 2017 22:31:17 -0700 Subject: altos: Update sensor data atomically Read data into a temp variable, block interrupts, then update the published value. The bug is easy to see with the HMC5883 which has to byte-swap the output of the chip, and hence can occasionally get caught with the wrong byte order data. Signed-off-by: Keith Packard --- src/drivers/ao_hmc5883.c | 12 +++++++----- src/drivers/ao_mpu6000.c | 39 +++++++++++++++++++-------------------- src/drivers/ao_ms5607.c | 4 +++- 3 files changed, 29 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/drivers/ao_hmc5883.c b/src/drivers/ao_hmc5883.c index f668fb66..9f1131d6 100644 --- a/src/drivers/ao_hmc5883.c +++ b/src/drivers/ao_hmc5883.c @@ -126,13 +126,15 @@ struct ao_hmc5883_sample ao_hmc5883_current; static void ao_hmc5883(void) { + struct ao_hmc5883_sample sample; ao_hmc5883_setup(); for (;;) { - ao_hmc5883_sample(&ao_hmc5883_current); - ao_arch_critical( - AO_DATA_PRESENT(AO_DATA_HMC5883); - AO_DATA_WAIT(); - ); + ao_hmc5883_sample(&sample); + ao_arch_block_interrupts(); + ao_hmc5883_current = sample; + AO_DATA_PRESENT(AO_DATA_HMC5883); + AO_DATA_WAIT(); + ao_arch_release_interrupts(); } } diff --git a/src/drivers/ao_mpu6000.c b/src/drivers/ao_mpu6000.c index 650407ad..81d3c16c 100644 --- a/src/drivers/ao_mpu6000.c +++ b/src/drivers/ao_mpu6000.c @@ -192,7 +192,7 @@ _ao_mpu6000_setup(void) _ao_mpu6000_wait_alive(); /* Reset the whole chip */ - + _ao_mpu6000_reg_write(MPU6000_PWR_MGMT_1, (1 << MPU6000_PWR_MGMT_1_DEVICE_RESET)); @@ -292,7 +292,7 @@ _ao_mpu6000_setup(void) ao_delay(AO_MS_TO_TICKS(200)); _ao_mpu6000_sample(&normal_mode); - + errors += ao_mpu6000_accel_check(normal_mode.accel_x, test_mode.accel_x); errors += ao_mpu6000_accel_check(normal_mode.accel_y, test_mode.accel_y); errors += ao_mpu6000_accel_check(normal_mode.accel_z, test_mode.accel_z); @@ -315,7 +315,7 @@ _ao_mpu6000_setup(void) /* Set sample rate divider to sample at 200Hz (v = gyro/rate - 1) */ _ao_mpu6000_reg_write(MPU6000_SMPRT_DIV, 1000 / 200 - 1); - + ao_delay(AO_MS_TO_TICKS(100)); ao_mpu6000_configured = 1; } @@ -325,6 +325,7 @@ struct ao_mpu6000_sample ao_mpu6000_current; static void ao_mpu6000(void) { + struct ao_mpu6000_sample sample; /* ao_mpu6000_init already grabbed the SPI bus and mutex */ _ao_mpu6000_setup(); #if AO_MPU6000_SPI @@ -335,14 +336,15 @@ ao_mpu6000(void) #if AO_MPU6000_SPI ao_mpu6000_spi_get(); #endif - _ao_mpu6000_sample(&ao_mpu6000_current); + _ao_mpu6000_sample(&sample); #if AO_MPU6000_SPI ao_mpu6000_spi_put(); -#endif - ao_arch_critical( - AO_DATA_PRESENT(AO_DATA_MPU6000); - AO_DATA_WAIT(); - ); +#endif + ao_arch_block_interrupts(); + ao_mpu6000_current = sample; + AO_DATA_PRESENT(AO_DATA_MPU6000); + AO_DATA_WAIT(); + ao_arch_release_interrupts(); } } @@ -351,16 +353,13 @@ static struct ao_task ao_mpu6000_task; static void ao_mpu6000_show(void) { - struct ao_data sample; - - ao_data_get(&sample); printf ("Accel: %7d %7d %7d Gyro: %7d %7d %7d\n", - sample.mpu6000.accel_x, - sample.mpu6000.accel_y, - sample.mpu6000.accel_z, - sample.mpu6000.gyro_x, - sample.mpu6000.gyro_y, - sample.mpu6000.gyro_z); + ao_mpu6000_current.accel_x, + ao_mpu6000_current.accel_y, + ao_mpu6000_current.accel_z, + ao_mpu6000_current.gyro_x, + ao_mpu6000_current.gyro_y, + ao_mpu6000_current.gyro_z); } static const struct ao_cmds ao_mpu6000_cmds[] = { @@ -374,7 +373,7 @@ ao_mpu6000_init(void) ao_mpu6000_configured = 0; ao_add_task(&ao_mpu6000_task, ao_mpu6000, "mpu6000"); - + #if AO_MPU6000_SPI ao_spi_init_cs(AO_MPU6000_SPI_CS_PORT, (1 << AO_MPU6000_SPI_CS_PIN)); @@ -386,7 +385,7 @@ ao_mpu6000_init(void) ao_cur_task = &ao_mpu6000_task; ao_spi_get(AO_MPU6000_SPI_BUS, AO_SPI_SPEED_1MHz); ao_cur_task = NULL; -#endif +#endif ao_cmd_register(&ao_mpu6000_cmds[0]); } diff --git a/src/drivers/ao_ms5607.c b/src/drivers/ao_ms5607.c index 0afdf012..914e0c1b 100644 --- a/src/drivers/ao_ms5607.c +++ b/src/drivers/ao_ms5607.c @@ -201,11 +201,13 @@ __xdata struct ao_ms5607_sample ao_ms5607_current; static void ao_ms5607(void) { + struct ao_ms5607_sample sample; ao_ms5607_setup(); for (;;) { - ao_ms5607_sample(&ao_ms5607_current); + ao_ms5607_sample(&sample); ao_arch_block_interrupts(); + ao_ms5607_current = sample; AO_DATA_PRESENT(AO_DATA_MS5607); AO_DATA_WAIT(); ao_arch_release_interrupts(); -- cgit v1.2.3 From 2a05849c3bf8c1617409237be48802dd6fc6255b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 11 Jun 2017 22:34:11 -0700 Subject: altos: HMC5883 output order is X Z Y Re-label everything to have the correct names. This doesn't actually change the code at all, so the eeprom and telemetry is all compatible. Matching changes on the host side will be required to actually process the data correctly, of course. Signed-off-by: Keith Packard --- src/drivers/ao_hmc5883.c | 6 ++---- src/drivers/ao_hmc5883.h | 2 +- src/kernel/ao_log.h | 4 ++-- src/kernel/ao_log_mega.c | 2 +- src/kernel/ao_telemetry.c | 2 +- src/kernel/ao_telemetry.h | 4 ++-- 6 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/drivers/ao_hmc5883.c b/src/drivers/ao_hmc5883.c index 9f1131d6..c33aa536 100644 --- a/src/drivers/ao_hmc5883.c +++ b/src/drivers/ao_hmc5883.c @@ -143,10 +143,8 @@ static struct ao_task ao_hmc5883_task; static void ao_hmc5883_show(void) { - struct ao_data sample; - ao_data_get(&sample); - printf ("X: %d Y: %d Z: %d missed irq: %lu\n", - sample.hmc5883.x, sample.hmc5883.y, sample.hmc5883.z, ao_hmc5883_missed_irq); + printf ("X: %d Z: %d Y: %d missed irq: %lu\n", + ao_hmc5883_current.x, ao_hmc5883_current.z, ao_hmc5883_current.y, ao_hmc5883_missed_irq); } static const struct ao_cmds ao_hmc5883_cmds[] = { diff --git a/src/drivers/ao_hmc5883.h b/src/drivers/ao_hmc5883.h index 78637b02..b90733df 100644 --- a/src/drivers/ao_hmc5883.h +++ b/src/drivers/ao_hmc5883.h @@ -77,7 +77,7 @@ #define HMC5883_ID_C 12 struct ao_hmc5883_sample { - int16_t x, y, z; + int16_t x, z, y; }; extern struct ao_hmc5883_sample ao_hmc5883_current; diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h index 5c568c99..241ba7d7 100644 --- a/src/kernel/ao_log.h +++ b/src/kernel/ao_log.h @@ -252,8 +252,8 @@ struct ao_log_mega { int16_t gyro_y; /* 20 */ int16_t gyro_z; /* 22 */ int16_t mag_x; /* 24 */ - int16_t mag_y; /* 26 */ - int16_t mag_z; /* 28 */ + int16_t mag_z; /* 26 */ + int16_t mag_y; /* 28 */ int16_t accel; /* 30 */ } sensor; /* 32 */ /* AO_LOG_TEMP_VOLT */ diff --git a/src/kernel/ao_log_mega.c b/src/kernel/ao_log_mega.c index a0212198..b86abe7a 100644 --- a/src/kernel/ao_log_mega.c +++ b/src/kernel/ao_log_mega.c @@ -135,8 +135,8 @@ ao_log(void) #endif #if HAS_HMC5883 log.u.sensor.mag_x = ao_data_ring[ao_log_data_pos].hmc5883.x; - log.u.sensor.mag_y = ao_data_ring[ao_log_data_pos].hmc5883.y; log.u.sensor.mag_z = ao_data_ring[ao_log_data_pos].hmc5883.z; + log.u.sensor.mag_y = ao_data_ring[ao_log_data_pos].hmc5883.y; #endif log.u.sensor.accel = ao_data_accel(&ao_data_ring[ao_log_data_pos]); ao_log_mega(&log); diff --git a/src/kernel/ao_telemetry.c b/src/kernel/ao_telemetry.c index a4c73a86..2ae1e41b 100644 --- a/src/kernel/ao_telemetry.c +++ b/src/kernel/ao_telemetry.c @@ -160,8 +160,8 @@ ao_send_mega_sensor(void) #if HAS_HMC5883 telemetry.mega_sensor.mag_x = packet->hmc5883.x; - telemetry.mega_sensor.mag_y = packet->hmc5883.y; telemetry.mega_sensor.mag_z = packet->hmc5883.z; + telemetry.mega_sensor.mag_y = packet->hmc5883.y; #endif ao_telemetry_send(); diff --git a/src/kernel/ao_telemetry.h b/src/kernel/ao_telemetry.h index 45aaeb07..23e3ed7d 100644 --- a/src/kernel/ao_telemetry.h +++ b/src/kernel/ao_telemetry.h @@ -198,8 +198,8 @@ struct ao_telemetry_mega_sensor { int16_t gyro_z; /* 24 */ int16_t mag_x; /* 26 */ - int16_t mag_y; /* 28 */ - int16_t mag_z; /* 30 */ + int16_t mag_z; /* 28 */ + int16_t mag_y; /* 30 */ /* 32 */ }; -- cgit v1.2.3 From 9454756f54312381927cb9faf1c4a6f5d8271034 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 11 Jun 2017 22:43:57 -0700 Subject: altos: Create separate log format for EasyMini v2.0 The ADC in the STM32F0 is different than the LPC, with a range of 0-4095 instead of 0-32767. Signed-off-by: Keith Packard --- src/easymini-v1.0/ao_pins.h | 2 +- src/easymini-v2.0/ao_pins.h | 2 +- src/kernel/ao_log.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/easymini-v1.0/ao_pins.h b/src/easymini-v1.0/ao_pins.h index 5983bb9e..45c6891d 100644 --- a/src/easymini-v1.0/ao_pins.h +++ b/src/easymini-v1.0/ao_pins.h @@ -42,7 +42,7 @@ #define PACKET_HAS_SLAVE 0 -#define AO_LOG_FORMAT AO_LOG_FORMAT_EASYMINI +#define AO_LOG_FORMAT AO_LOG_FORMAT_EASYMINI1 /* USART */ diff --git a/src/easymini-v2.0/ao_pins.h b/src/easymini-v2.0/ao_pins.h index c141d1a6..2ec0e90b 100644 --- a/src/easymini-v2.0/ao_pins.h +++ b/src/easymini-v2.0/ao_pins.h @@ -44,7 +44,7 @@ #define AO_PA11_PA12_RMP 1 #define AO_USB_FORCE_IDLE 1 -#define AO_LOG_FORMAT AO_LOG_FORMAT_EASYMINI +#define AO_LOG_FORMAT AO_LOG_FORMAT_EASYMINI2 #define HAS_BOOT_RADIO 0 diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h index 241ba7d7..aca669db 100644 --- a/src/kernel/ao_log.h +++ b/src/kernel/ao_log.h @@ -45,7 +45,7 @@ extern __pdata enum ao_flight_state ao_log_state; #define AO_LOG_FORMAT_TELEMETRY 3 /* 32 byte ao_telemetry records */ #define AO_LOG_FORMAT_TELESCIENCE 4 /* 32 byte typed telescience records */ #define AO_LOG_FORMAT_TELEMEGA_OLD 5 /* 32 byte typed telemega records */ -#define AO_LOG_FORMAT_EASYMINI 6 /* 16-byte MS5607 baro only, 3.0V supply */ +#define AO_LOG_FORMAT_EASYMINI1 6 /* 16-byte MS5607 baro only, 3.0V supply */ #define AO_LOG_FORMAT_TELEMETRUM 7 /* 16-byte typed telemetrum records */ #define AO_LOG_FORMAT_TELEMINI2 8 /* 16-byte MS5607 baro only, 3.3V supply, cc1111 SoC */ #define AO_LOG_FORMAT_TELEGPS 9 /* 32 byte telegps records */ @@ -53,6 +53,7 @@ extern __pdata enum ao_flight_state ao_log_state; #define AO_LOG_FORMAT_DETHERM 11 /* 16-byte MS5607 baro only, no ADC */ #define AO_LOG_FORMAT_TELEMINI3 12 /* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */ #define AO_LOG_FORMAT_TELEFIRETWO 13 /* 32-byte test stand data */ +#define AO_LOG_FORMAT_EASYMINI2 14 /* 16-byte MS5607 baro only, 3.3V supply, stm32f042 SoC */ #define AO_LOG_FORMAT_NONE 127 /* No log at all */ extern __code uint8_t ao_log_format; -- cgit v1.2.3 From cd8b22bef0a88ed6881036b4c6718a4e33c55d41 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 13 Jun 2017 10:34:03 -0700 Subject: altos: Add timeout to RN4678 status message code If we see the start of an RN4678 status message, but then output pauses, assume that this isn't the start of a status message and flush the pending data. Signed-off-by: Keith Packard --- src/drivers/ao_rn4678.c | 178 +++++++++++++++++++++++++----------------------- src/drivers/ao_rn4678.h | 7 +- 2 files changed, 99 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/drivers/ao_rn4678.c b/src/drivers/ao_rn4678.c index 4e3d12cb..ba25e70d 100644 --- a/src/drivers/ao_rn4678.c +++ b/src/drivers/ao_rn4678.c @@ -39,7 +39,7 @@ static void ao_rn_log_char(char c, char dir) { if (dir != ao_rn_dir) { - putchar(dir); + putchar(dir); putchar('\n'); ao_rn_dir = dir; } switch (c) { @@ -106,78 +106,74 @@ static const char *status_strings[] = { #define NUM_STATUS_STRING (sizeof status_strings/sizeof status_strings[0]) +static char ao_rn_buffer[64]; +static int ao_rn_buf_cnt, ao_rn_buf_ptr; +static int ao_rn_draining; +static AO_TICK_TYPE ao_rn_buf_time; + +/* Well, this is annoying. The status strings from the RN4678 can't be + * disabled due to a firmware bug. So, this code finds those in the + * input and strips them out. + */ int _ao_wrap_rn_pollchar(void) { - static char buffer[64]; - static int buf_cnt, buf_ptr; - static int draining; int c = AO_READ_AGAIN; unsigned i; int done = 0; - while (!done && !draining) { + while (!done && !ao_rn_draining) { c = _ao_serial_rn_pollchar(); - if (c == AO_READ_AGAIN) + if (c == AO_READ_AGAIN) { + if (ao_rn_buf_cnt && (ao_time() - ao_rn_buf_time) > AO_MS_TO_TICKS(1000)) { + ao_rn_draining = 1; + continue; + } return AO_READ_AGAIN; + } - if (buf_cnt) { + if (ao_rn_buf_cnt) { /* buffering chars */ if (c == STATUS_CHAR) { /* End of status string, drop it and carry on */ - buffer[buf_cnt] = '\0'; - ao_rn_dbg("discard %s\n", buffer); - buf_cnt = 0; - } else if (buf_cnt == sizeof(buffer)) { + ao_rn_buffer[ao_rn_buf_cnt] = '\0'; +// ao_rn_dbg("discard %s\n", ao_rn_buffer); + ao_rn_buf_cnt = 0; + } else if (ao_rn_buf_cnt == sizeof(ao_rn_buffer)) { /* If we filled the buffer, just give up */ - draining = 1; + ao_rn_draining = 1; } else { - buffer[buf_cnt++] = c; + ao_rn_buffer[ao_rn_buf_cnt++] = c; for (i = 0; i < NUM_STATUS_STRING; i++) { int cmp = strlen(status_strings[i]); - if (cmp >= buf_cnt) - cmp = buf_cnt-1; - if (memcmp(buffer+1, status_strings[i], cmp) == 0) + if (cmp >= ao_rn_buf_cnt) + cmp = ao_rn_buf_cnt-1; + if (memcmp(ao_rn_buffer+1, status_strings[i], cmp) == 0) break; } if (i == NUM_STATUS_STRING) - draining = 1; + ao_rn_draining = 1; } } else if (c == STATUS_CHAR) { - buffer[0] = c; - buf_cnt = 1; - buf_ptr = 0; + ao_rn_buffer[0] = c; + ao_rn_buf_cnt = 1; + ao_rn_buf_ptr = 0; + ao_rn_buf_time = ao_time(); } else done = 1; } - if (draining) { - c = buffer[buf_ptr++] & 0xff; - if (buf_ptr == buf_cnt) { - buf_ptr = buf_cnt = 0; - draining = 0; + if (ao_rn_draining) { + c = ao_rn_buffer[ao_rn_buf_ptr++] & 0xff; + if (ao_rn_buf_ptr == ao_rn_buf_cnt) { + ao_rn_buf_ptr = ao_rn_buf_cnt = 0; + ao_rn_draining = 0; } } -#if AO_RN_DEBUG - ao_arch_release_interrupts(); - ao_usb_putchar(c); ao_usb_flush(); - ao_arch_block_interrupts(); -#endif return c; } -#if AO_RN_DEBUG -static void -ao_wrap_rn_putchar(char c) -{ - ao_usb_putchar(c); ao_usb_flush(); - ao_serial_rn_putchar(c); -} -#else -#define ao_wrap_rn_putchar ao_serial_rn_putchar -#endif - static void ao_rn_puts(char *s) { @@ -192,7 +188,7 @@ ao_rn_drain(void) { int timeout = 0; - ao_rn_dbg("drain...\n"); +// ao_rn_dbg("drain...\n"); ao_serial_rn_drain(); while (!timeout) { ao_arch_block_interrupts(); @@ -204,13 +200,13 @@ ao_rn_drain(void) } ao_arch_release_interrupts(); } - ao_rn_dbg("drain done\n"); +// ao_rn_dbg("drain done\n"); } static void ao_rn_send_cmd(char *cmd, char *param) { - ao_rn_dbg("send_cmd %s%s\n", cmd, param ? param : ""); +// ao_rn_dbg("send_cmd %s%s\n", cmd, param ? param : ""); ao_rn_drain(); ao_rn_puts(cmd); if (param) @@ -244,20 +240,20 @@ ao_rn_wait_for(int timeout, char *match) AO_TICK_TYPE giveup_time = ao_time() + timeout; int c; - ao_rn_dbg("wait for %d, \"%s\"\n", timeout, match); +// ao_rn_dbg("wait for %d, \"%s\"\n", timeout, match); memset(reply, ' ', sizeof(reply)); while (memcmp(reply, match, match_len) != 0) { c = ao_rn_wait_char(giveup_time); if (c == AO_READ_AGAIN) { - ao_rn_dbg("\twait for timeout\n"); +// ao_rn_dbg("\twait for timeout\n"); return AO_RN_TIMEOUT; } reply[match_len] = (char) c; memmove(reply, reply+1, match_len); reply[match_len] = '\0'; - ao_rn_dbg("\tmatch now \"%s\"\n", reply); +// ao_rn_dbg("\tmatch now \"%s\"\n", reply); } - ao_rn_dbg("\twait for ok\n"); +// ao_rn_dbg("\twait for ok\n"); return AO_RN_OK; } @@ -266,20 +262,20 @@ ao_rn_wait_line(AO_TICK_TYPE giveup_time, char *line, int len) { char *l = line; - ao_rn_dbg("wait line\n"); +// ao_rn_dbg("wait line\n"); for (;;) { int c = ao_rn_wait_char(giveup_time); /* timeout */ if (c == AO_READ_AGAIN) { - ao_rn_dbg("\twait line timeout\n"); +// ao_rn_dbg("\twait line timeout\n"); return AO_RN_TIMEOUT; } /* done */ if (c == '\r') { *l = '\0'; - ao_rn_dbg("\twait line \"%s\"\n", line); +// ao_rn_dbg("\twait line \"%s\"\n", line); return AO_RN_OK; } @@ -302,7 +298,7 @@ ao_rn_wait_status(void) AO_TICK_TYPE giveup_time = ao_time() + AO_RN_CMD_TIMEOUT; int status; - ao_rn_dbg("wait status\n"); +// ao_rn_dbg("wait status\n"); status = ao_rn_wait_line(giveup_time, message, sizeof (message)); if (status == AO_RN_OK) if (strncmp(message, "AOK", 3) != 0) @@ -317,7 +313,7 @@ ao_rn_set_name(void) char *s = sn + 8; int n; - ao_rn_dbg("set name...\n"); +// ao_rn_dbg("set name...\n"); *--s = '\0'; n = ao_serial_number; do { @@ -330,7 +326,7 @@ ao_rn_set_name(void) static int ao_rn_get_name(char *name, int len) { - ao_rn_dbg("get name...\n"); +// ao_rn_dbg("get name...\n"); ao_rn_send_cmd(AO_RN_GET_NAME_CMD, NULL); return ao_rn_wait_line(ao_time() + AO_RN_CMD_TIMEOUT, name, len); } @@ -404,12 +400,18 @@ ao_rn(void) continue; } - ao_rn_puts("$$$"); - /* After it reboots, it can take a moment before it responds * to commands */ - (void) ao_rn_wait_for(AO_RN_REBOOT_TIMEOUT, "CMD> "); + status = ao_rn_wait_for(AO_RN_REBOOT_TIMEOUT, "CMD> "); + + if (status == AO_RN_TIMEOUT) { + ao_rn_puts("$$$"); + (void) ao_rn_wait_for(AO_RN_REBOOT_TIMEOUT, "CMD> "); + } + + ao_rn_send_cmd(AO_RN_VERSION_CMD, NULL); + (void) ao_rn_wait_status(); /* Check to see if the name is already set and assume * that the device is ready to go @@ -417,7 +419,9 @@ ao_rn(void) status = ao_rn_get_name(name, sizeof (name)); if (status != AO_RN_OK) { ao_rn_dbg("get name failed\n"); - continue; + status = ao_rn_get_name(name, sizeof (name)); + if (status != AO_RN_OK) + continue; } if (strncmp(name, "TeleBT-", 7) == 0) { @@ -433,6 +437,12 @@ ao_rn(void) continue; } + ao_rn_send_cmd(AO_RN_SET_STATUS_STRING, AO_RN_STATUS_STRING_ENABLE); + if (ao_rn_wait_status() != AO_RN_OK) { + ao_rn_dbg("set status string\n"); + continue; + } + /* Select 'fast' mode to ignore command sequence (more or less) */ ao_rn_send_cmd(AO_RN_SET_FAST_MODE, NULL); if (ao_rn_wait_status() != AO_RN_OK) { @@ -465,17 +475,27 @@ ao_rn(void) ao_exti_enable(AO_RN_CONNECTED_PORT, AO_RN_CONNECTED_PIN); -#if 1 +#if AO_RN_DEBUG + + /* + * Separate debug code when things aren't working. Just dump + * inbound bluetooth characters to stdout + */ + for (;;) { + int c; + + ao_arch_block_interrupts(); + while ((c = _ao_rn_pollchar()) == AO_READ_AGAIN) + ao_sleep(&ao_serial_rn_rx_fifo); + ao_arch_release_interrupts(); + } +#else ao_rn_stdio = ao_add_stdio(_ao_wrap_rn_pollchar, - ao_wrap_rn_putchar, + ao_serial_rn_putchar, NULL); ao_rn_echo(0); - ao_rn_check_link(); - - ao_rn_dbg("RN running\n"); - /* * Now just hang around and flash the blue LED when we've got * a connection @@ -487,27 +507,11 @@ ao_rn(void) ao_arch_release_interrupts(); while (ao_rn_connected) { ao_led_for(AO_BT_LED, AO_MS_TO_TICKS(20)); + if (ao_rn_buf_cnt != 0) + ao_wakeup(&ao_stdin_ready); ao_delay(AO_SEC_TO_TICKS(3)); } } -#else - - /* - * Separate debug code when things aren't working. Just dump - * inbound bluetooth characters to stdout - */ - for (;;) { - int c; - - while (rn_cmd_running) - ao_delay(AO_MS_TO_TICKS(1000)); - - ao_arch_block_interrupts(); - while ((c = _ao_wrap_rn_pollchar()) == AO_READ_AGAIN) - ao_sleep(&ao_serial_rn_rx_fifo); - ao_arch_release_interrupts(); - putchar(c); flush(); - } #endif } @@ -539,15 +543,21 @@ ao_rn_factory(void) /* Right after power on, poke P3_1 five times to force a * factory reset */ - for (i = 0; i < 10; i++) { + for (i = 0; i < 20; i++) { v = 1-v; - ao_delay(AO_MS_TO_TICKS(100)); + ao_delay(AO_MS_TO_TICKS(50)); ao_gpio_set(AO_RN_P3_1_PORT, AO_RN_P3_1_PIN, foo, v); ao_led_toggle(AO_BT_LED); } /* And let P3_1 float again */ ao_enable_input(AO_RN_P3_1_PORT, AO_RN_P3_1_PIN, AO_EXTI_MODE_PULL_NONE); + + printf("Reboot BT\n"); flush(); + ao_delay(AO_MS_TO_TICKS(100)); + ao_gpio_set(AO_RN_RST_N_PORT, AO_RN_RST_N_PIN, foo, 0); + ao_delay(AO_MS_TO_TICKS(100)); + ao_gpio_set(AO_RN_RST_N_PORT, AO_RN_RST_N_PIN, foo, 1); } static const struct ao_cmds rn_cmds[] = { diff --git a/src/drivers/ao_rn4678.h b/src/drivers/ao_rn4678.h index d6fea23a..a4dcea38 100644 --- a/src/drivers/ao_rn4678.h +++ b/src/drivers/ao_rn4678.h @@ -56,7 +56,7 @@ */ -#define AO_RN_REBOOT_MSG "%REBOOT%" +#define AO_RN_REBOOT_MSG "REBOOT" #define AO_RN_CMD_TIMEOUT AO_MS_TO_TICKS(200) @@ -67,11 +67,14 @@ #define AO_RN_SET_NAME_CMD "SN," #define AO_RN_GET_NAME_CMD "GN" -#define AO_RN_SET_STATUS_STRING "SO," +#define AO_RN_SET_STATUS_STRING "so," #define AO_RN_STATUS_STRING_DISABLE " " +#define AO_RN_STATUS_STRING_ENABLE "%,%" #define AO_RN_REBOOT_CMD "R,1" +#define AO_RN_VERSION_CMD "V" + #define AO_RN_TIMEOUT -1 #define AO_RN_ERROR 0 #define AO_RN_OK 1 -- cgit v1.2.3 From 672889659fb2c1a63f5ef199173719a606a9f343 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 13 Jun 2017 10:35:39 -0700 Subject: altos/telebt-4.0: Add dependency on RN4678 header Signed-off-by: Keith Packard --- src/telebt-v4.0/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/telebt-v4.0/Makefile b/src/telebt-v4.0/Makefile index 31651120..38ac7513 100644 --- a/src/telebt-v4.0/Makefile +++ b/src/telebt-v4.0/Makefile @@ -14,6 +14,7 @@ INC = \ ao_product.h \ ao_cc1200_CC1200.h \ ao_task.h \ + ao_rn4678.h \ stm32f0.h \ Makefile -- cgit v1.2.3 From ea7e236e75452e27f3af6730a0542850851eb23d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 20 Jun 2017 11:19:40 -0700 Subject: altos/rn4678: Add BLE support This just means ignoring the BLE connect status message. Signed-off-by: Keith Packard --- src/drivers/ao_rn4678.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/drivers/ao_rn4678.c b/src/drivers/ao_rn4678.c index ba25e70d..98dc35b5 100644 --- a/src/drivers/ao_rn4678.c +++ b/src/drivers/ao_rn4678.c @@ -100,6 +100,7 @@ static const char *status_strings[] = { "RFCOMM_CLOSE", "RFCOMM_OPEN", "CONNECT", + "LCONNECT", "DISCONN", "BONDED", }; @@ -560,8 +561,22 @@ ao_rn_factory(void) ao_gpio_set(AO_RN_RST_N_PORT, AO_RN_RST_N_PIN, foo, 1); } +#if AO_RN_DEBUG +static void +ao_rn_send(void) +{ + int c; + + while ((c = getchar()) != '~') + ao_rn_putchar(c); +} +#endif + static const struct ao_cmds rn_cmds[] = { { ao_rn_factory, "F\0Factory reset rn4678" }, +#if AO_RN_DEBUG + { ao_rn_send, "B\0Send data to rn4678. End with ~" }, +#endif { 0 }, }; -- cgit v1.2.3 From e64438271e481ca9f9eeb0ce2b1f9eca071b7ad4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jun 2017 23:37:49 -0700 Subject: altos/stmf0: Initialize UART RTS/CTS before turning it on If you try this after the UART is running, it won't work. Signed-off-by: Keith Packard --- src/micropeak-v2.0/ao_pins.h | 3 +- src/stm/ao_serial_stm.c | 17 +++++----- src/stmf0/ao_serial_stm.c | 74 +++++++++++++++++++------------------------- 3 files changed, 42 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/micropeak-v2.0/ao_pins.h b/src/micropeak-v2.0/ao_pins.h index 13a4fd10..fa2ed804 100644 --- a/src/micropeak-v2.0/ao_pins.h +++ b/src/micropeak-v2.0/ao_pins.h @@ -53,7 +53,8 @@ extern uint8_t ao_on_battery; #define HAS_SERIAL_1 0 #define HAS_SERIAL_2 1 #define USE_SERIAL_2_STDIN 0 -#define HAS_SERIAL_SW_FLOW 0 +#define USE_SERIAL_2_FLOW 0 +#define USE_SERIAL_2_SW_FLOW 0 #define SERIAL_2_PA2_PA3 1 #define SERIAL_2_PA14_PA15 0 #define USE_SERIAL2_FLOW 0 diff --git a/src/stm/ao_serial_stm.c b/src/stm/ao_serial_stm.c index c625471e..ef562313 100644 --- a/src/stm/ao_serial_stm.c +++ b/src/stm/ao_serial_stm.c @@ -195,7 +195,7 @@ ao_usart_set_speed(struct ao_stm_usart *usart, uint8_t speed) } static void -ao_usart_init(struct ao_stm_usart *usart) +ao_usart_init(struct ao_stm_usart *usart, int hw_flow) { usart->reg->cr1 = ((0 << STM_USART_CR1_OVER8) | (1 << STM_USART_CR1_UE) | @@ -236,6 +236,10 @@ ao_usart_init(struct ao_stm_usart *usart) (0 << STM_USART_CR3_IREN) | (0 << STM_USART_CR3_EIE)); + if (hw_flow) + usart->reg->cr3 |= ((1 << STM_USART_CR3_CTSE) | + (1 << STM_USART_CR3_RTSE)); + /* Pick a 9600 baud rate */ ao_usart_set_speed(usart, AO_SERIAL_SPEED_9600); } @@ -244,8 +248,6 @@ ao_usart_init(struct ao_stm_usart *usart) static void ao_usart_set_flow(struct ao_stm_usart *usart) { - usart->reg->cr3 |= ((1 << STM_USART_CR3_CTSE) | - (1 << STM_USART_CR3_RTSE)); } #endif @@ -441,7 +443,7 @@ ao_serial_init(void) stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_USART1EN); ao_stm_usart1.reg = &stm_usart1; - ao_usart_init(&ao_stm_usart1); + ao_usart_init(&ao_stm_usart1, 0); stm_nvic_set_enable(STM_ISR_USART1_POS); stm_nvic_set_priority(STM_ISR_USART1_POS, AO_STM_NVIC_MED_PRIORITY); @@ -494,10 +496,7 @@ ao_serial_init(void) stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_USART2EN); ao_stm_usart2.reg = &stm_usart2; - ao_usart_init(&ao_stm_usart2); -#if USE_SERIAL_2_FLOW && !USE_SERIAL_2_SW_FLOW - ao_usart_set_flow(&ao_stm_usart2); -#endif + ao_usart_init(&ao_stm_usart2, USE_SERIAL_2_FLOW && !USE_SERIAL_2_SW_FLOW); stm_nvic_set_enable(STM_ISR_USART2_POS); stm_nvic_set_priority(STM_ISR_USART2_POS, AO_STM_NVIC_MED_PRIORITY); @@ -541,7 +540,7 @@ ao_serial_init(void) stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_USART3EN); ao_stm_usart3.reg = &stm_usart3; - ao_usart_init(&ao_stm_usart3); + ao_usart_init(&ao_stm_usart3, 0); stm_nvic_set_enable(STM_ISR_USART3_POS); stm_nvic_set_priority(STM_ISR_USART3_POS, AO_STM_NVIC_MED_PRIORITY); diff --git a/src/stmf0/ao_serial_stm.c b/src/stmf0/ao_serial_stm.c index e20b5755..59cfde2e 100644 --- a/src/stmf0/ao_serial_stm.c +++ b/src/stmf0/ao_serial_stm.c @@ -180,7 +180,7 @@ ao_usart_set_speed(struct ao_stm_usart *usart, uint8_t speed) } static void -ao_usart_init(struct ao_stm_usart *usart) +ao_usart_init(struct ao_stm_usart *usart, int hw_flow) { usart->reg->cr1 = ((0 << STM_USART_CR1_M1) | (0 << STM_USART_CR1_EOBIE) | @@ -223,44 +223,39 @@ ao_usart_init(struct ao_stm_usart *usart) (0 << STM_USART_CR2_LBDL) | (0 << STM_USART_CR2_ADDM7)); - usart->reg->cr3 = ((0 << STM_USART_CR3_WUFIE) | - (0 << STM_USART_CR3_WUS) | - (0 << STM_USART_CR3_SCARCNT) | - (0 << STM_USART_CR3_DEP) | - (0 << STM_USART_CR3_DEM) | - (0 << STM_USART_CR3_DDRE) | - (0 << STM_USART_CR3_OVRDIS) | - (0 << STM_USART_CR3_ONEBIT) | - (0 << STM_USART_CR3_CTIIE) | - (0 << STM_USART_CR3_CTSE) | - (0 << STM_USART_CR3_RTSE) | - (0 << STM_USART_CR3_DMAT) | - (0 << STM_USART_CR3_DMAR) | - (0 << STM_USART_CR3_SCEN) | - (0 << STM_USART_CR3_NACK) | - (0 << STM_USART_CR3_HDSEL) | - (0 << STM_USART_CR3_IRLP) | - (0 << STM_USART_CR3_IREN) | - (0 << STM_USART_CR3_EIE)); - + uint32_t cr3 = ((0 << STM_USART_CR3_WUFIE) | + (0 << STM_USART_CR3_WUS) | + (0 << STM_USART_CR3_SCARCNT) | + (0 << STM_USART_CR3_DEP) | + (0 << STM_USART_CR3_DEM) | + (0 << STM_USART_CR3_DDRE) | + (0 << STM_USART_CR3_OVRDIS) | + (0 << STM_USART_CR3_ONEBIT) | + (0 << STM_USART_CR3_CTIIE) | + (0 << STM_USART_CR3_CTSE) | + (0 << STM_USART_CR3_RTSE) | + (0 << STM_USART_CR3_DMAT) | + (0 << STM_USART_CR3_DMAR) | + (0 << STM_USART_CR3_SCEN) | + (0 << STM_USART_CR3_NACK) | + (0 << STM_USART_CR3_HDSEL) | + (0 << STM_USART_CR3_IRLP) | + (0 << STM_USART_CR3_IREN) | + (0 << STM_USART_CR3_EIE)); + + if (hw_flow) + cr3 |= ((1 << STM_USART_CR3_CTSE) | + (1 << STM_USART_CR3_RTSE)); + + usart->reg->cr3 = cr3; /* Pick a 9600 baud rate */ ao_usart_set_speed(usart, AO_SERIAL_SPEED_9600); /* Enable the usart */ usart->reg->cr1 |= (1 << STM_USART_CR1_UE); - } -#if HAS_SERIAL_HW_FLOW -static void -ao_usart_set_flow(struct ao_stm_usart *usart) -{ - usart->reg->cr3 |= ((1 << STM_USART_CR3_CTSE) | - (1 << STM_USART_CR3_RTSE)); -} -#endif - #if HAS_SERIAL_1 struct ao_stm_usart ao_stm_usart1; @@ -391,13 +386,13 @@ ao_serial_init(void) */ #if SERIAL_1_PA9_PA10 - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPAEN); + ao_enable_port(&stm_gpioa); stm_afr_set(&stm_gpioa, 9, STM_AFR_AF1); stm_afr_set(&stm_gpioa, 10, STM_AFR_AF1); #else #if SERIAL_1_PB6_PB7 - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPBEN); + ao_enable_port(&stm_gpiob); stm_afr_set(&stm_gpiob, 6, STM_AFR_AF0); stm_afr_set(&stm_gpiob, 7, STM_AFR_AF0); @@ -409,7 +404,7 @@ ao_serial_init(void) stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_USART1EN); ao_stm_usart1.reg = &stm_usart1; - ao_usart_init(&ao_stm_usart1); + ao_usart_init(&ao_stm_usart1, 0); stm_nvic_set_enable(STM_ISR_USART1_POS); stm_nvic_set_priority(STM_ISR_USART1_POS, 4); @@ -428,8 +423,7 @@ ao_serial_init(void) */ # if SERIAL_2_PA2_PA3 - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPAEN); - + ao_enable_port(&stm_gpioa); stm_afr_set(&stm_gpioa, 2, STM_AFR_AF1); stm_afr_set(&stm_gpioa, 3, STM_AFR_AF1); # if USE_SERIAL_2_FLOW @@ -447,8 +441,7 @@ ao_serial_init(void) # endif # else # if SERIAL_2_PA14_PA15 - stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPAEN); - + ao_enable_port(&stm_gpioa); stm_afr_set(&stm_gpioa, 14, STM_AFR_AF1); stm_afr_set(&stm_gpioa, 15, STM_AFR_AF1); # if USE_SERIAL_2_FLOW @@ -472,10 +465,7 @@ ao_serial_init(void) stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_USART2EN); ao_stm_usart2.reg = &stm_usart2; - ao_usart_init(&ao_stm_usart2); -# if USE_SERIAL_2_FLOW && !USE_SERIAL_2_SW_FLOW - ao_usart_set_flow(&ao_stm_usart2); -# endif + ao_usart_init(&ao_stm_usart2, USE_SERIAL_2_FLOW && !USE_SERIAL_2_SW_FLOW); stm_nvic_set_enable(STM_ISR_USART2_POS); stm_nvic_set_priority(STM_ISR_USART2_POS, 4); -- cgit v1.2.3 From b923e25a8a49dda40e62070dd2df6ff9130d4b38 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 27 Jun 2017 23:39:16 -0700 Subject: altos/telebt-v4.0: Use HW flow control to BT module Now that the stmf0 HW flow control works... Signed-off-by: Keith Packard --- src/telebt-v4.0/ao_pins.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/telebt-v4.0/ao_pins.h b/src/telebt-v4.0/ao_pins.h index 0082b2b5..f3d70d1a 100644 --- a/src/telebt-v4.0/ao_pins.h +++ b/src/telebt-v4.0/ao_pins.h @@ -54,7 +54,7 @@ #define USE_SERIAL_2_STDIN 1 #define DELAY_SERIAL_2_STDIN 1 #define USE_SERIAL_2_FLOW 1 -#define USE_SERIAL_2_SW_FLOW 1 +#define USE_SERIAL_2_SW_FLOW 0 #define SERIAL_2_PA2_PA3 1 #define SERIAL_2_PD5_PD6 0 #define SERIAL_2_PORT_RTS (&stm_gpioa) -- cgit v1.2.3 From 545bdc1f8046b08e237307d97d0044ddae9095b8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 21 Jul 2017 16:14:31 -0700 Subject: altos/test: Add EasyMini test mode Use baro-only mode, parse easymini logs. Signed-off-by: Keith Packard --- src/test/Makefile | 5 ++- src/test/ao_flight_test.c | 101 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/test/Makefile b/src/test/Makefile index a22abe46..a0c2d5fe 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -1,7 +1,7 @@ vpath % ..:../kernel:../drivers:../util:../micropeak:../aes:../product:../lisp PROGS=ao_flight_test ao_flight_test_baro ao_flight_test_accel ao_flight_test_noisy_accel ao_flight_test_mm \ - ao_flight_test_metrum \ + ao_flight_test_metrum ao_flight_test_mini \ ao_gps_test ao_gps_test_skytraq ao_gps_test_ublox ao_convert_test ao_convert_pa_test ao_fec_test \ ao_aprs_test ao_micropeak_test ao_fat_test ao_aes_test ao_int64_test \ ao_ms5607_convert_test ao_quaternion_test ao_lisp_test @@ -37,6 +37,9 @@ ao_flight_test_mm: ao_flight_test.c ao_host.h ao_flight.c ao_sample.c ao_kalman. ao_flight_test_metrum: ao_flight_test.c ao_host.h ao_flight.c ao_sample.c ao_kalman.c ao_pyro.c ao_pyro.h $(INCS) cc -DTELEMETRUM_V2=1 $(CFLAGS) -o $@ $< -lm +ao_flight_test_mini: ao_flight_test.c ao_host.h ao_flight.c ao_sample.c ao_kalman.c ao_pyro.c ao_pyro.h $(INCS) + cc -DEASYMINI=1 -DHAS_ACCEL=0 $(CFLAGS) -o $@ $< -lm + ao_gps_test: ao_gps_test.c ao_gps_sirf.c ao_gps_print.c ao_host.h cc $(CFLAGS) -o $@ $< diff --git a/src/test/ao_flight_test.c b/src/test/ao_flight_test.c index 25ddb48f..d3d39f2a 100644 --- a/src/test/ao_flight_test.c +++ b/src/test/ao_flight_test.c @@ -46,7 +46,7 @@ int ao_gps_new; -#if !defined(TELEMEGA) && !defined(TELEMETRUM_V2) +#if !defined(TELEMEGA) && !defined(TELEMETRUM_V2) && !defined(EASYMINI) #define TELEMETRUM_V1 1 #endif @@ -84,6 +84,18 @@ struct ao_adc { }; #endif +#if EASYMINI +#define AO_ADC_NUM_SENSE 2 +#define HAS_MS5607 1 +#define HAS_BEEP 1 +#define AO_CONFIG_MAX_SIZE 1024 + +struct ao_adc { + int16_t sense_a; + int16_t sense_m; + int16_t v_batt; +}; +#endif #if TELEMETRUM_V1 /* @@ -323,7 +335,7 @@ struct ao_cmds { #define ao_xmemcmp(d,s,c) memcmp(d,s,c) #define AO_NEED_ALTITUDE_TO_PRES 1 -#if TELEMEGA || TELEMETRUM_V2 +#if TELEMEGA || TELEMETRUM_V2 || EASYMINI #include "ao_convert_pa.c" #include struct ao_ms5607_prom ao_ms5607_prom; @@ -475,7 +487,7 @@ ao_insert(void) #else double accel = 0.0; #endif -#if TELEMEGA || TELEMETRUM_V2 +#if TELEMEGA || TELEMETRUM_V2 || EASYMINI double height; ao_ms5607_convert(&ao_data_static.ms5607_raw, &ao_data_static.ms5607_cooked); @@ -670,6 +682,19 @@ int32(uint8_t *bytes, int off) return (int32_t) uint32(bytes, off); } +uint32_t +uint24(uint8_t *bytes, int off) +{ + return (uint32_t) bytes[off] | (((uint32_t) bytes[off+1]) << 8) | + (((uint32_t) bytes[off+2]) << 16); +} + +int32_t +int24(uint8_t *bytes, int off) +{ + return (int32_t) uint24(bytes, off); +} + static int log_format; void @@ -694,12 +719,14 @@ ao_sleep(void *wchan) for (;;) { if (ao_records_read > 2 && ao_flight_state == ao_flight_startup) { + #if TELEMEGA ao_data_static.mpu6000 = ao_ground_mpu6000; #endif #if TELEMETRUM_V1 ao_data_static.adc.accel = ao_flight_ground_accel; #endif + ao_insert(); return; } @@ -829,6 +856,72 @@ ao_sleep(void *wchan) } } #endif +#if EASYMINI + if ((log_format == AO_LOG_FORMAT_EASYMINI1 || log_format == AO_LOG_FORMAT_EASYMINI2) && nword == 14 && strlen(words[0]) == 1) { + int i; + struct ao_ms5607_value value; + + type = words[0][0]; + tick = strtoul(words[1], NULL, 16); +// printf ("%c %04x", type, tick); + for (i = 2; i < nword; i++) { + bytes[i - 2] = strtoul(words[i], NULL, 16); +// printf(" %02x", bytes[i-2]); + } +// printf ("\n"); + switch (type) { + case 'F': + ao_flight_started = 1; + ao_ground_pres = uint32(bytes, 4); + ao_ground_height = ao_pa_to_altitude(ao_ground_pres); +#if 0 + printf("ground pres %d height %d\n", ao_ground_pres, ao_ground_height); + printf("sens %d off %d tcs %d tco %d tref %d tempsens %d crc %d\n", + ao_ms5607_prom.sens, + ao_ms5607_prom.off, + ao_ms5607_prom.tcs, + ao_ms5607_prom.tco, + ao_ms5607_prom.tref, + ao_ms5607_prom.tempsens, + ao_ms5607_prom.crc); +#endif + break; + case 'A': + ao_data_static.tick = tick; + ao_data_static.ms5607_raw.pres = int24(bytes, 0); + ao_data_static.ms5607_raw.temp = int24(bytes, 3); +#if 0 + printf("raw pres %d temp %d\n", + ao_data_static.ms5607_raw.pres, + ao_data_static.ms5607_raw.temp); +#endif + ao_ms5607_convert(&ao_data_static.ms5607_raw, &value); +// printf("pres %d height %d\n", value.pres, ao_pa_to_altitude(value.pres)); + ao_records_read++; + ao_insert(); + return; + } + continue; + } else if (nword == 3 && strcmp(words[0], "ms5607") == 0) { + if (strcmp(words[1], "reserved:") == 0) + ao_ms5607_prom.reserved = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "sens:") == 0) + ao_ms5607_prom.sens = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "off:") == 0) + ao_ms5607_prom.off = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "tcs:") == 0) + ao_ms5607_prom.tcs = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "tco:") == 0) + ao_ms5607_prom.tco = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "tref:") == 0) + ao_ms5607_prom.tref = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "tempsens:") == 0) + ao_ms5607_prom.tempsens = strtoul(words[2], NULL, 10); + else if (strcmp(words[1], "crc:") == 0) + ao_ms5607_prom.crc = strtoul(words[2], NULL, 10); + continue; + } +#endif #if TELEMETRUM_V2 if (log_format == AO_LOG_FORMAT_TELEMETRUM && nword == 14 && strlen(words[0]) == 1) { int i; @@ -1007,7 +1100,7 @@ ao_sleep(void *wchan) if (type != 'F' && !ao_flight_started) continue; -#if TELEMEGA || TELEMETRUM_V2 +#if TELEMEGA || TELEMETRUM_V2 || EASYMINI (void) a; (void) b; #else -- cgit v1.2.3