diff options
author | Simon Wilks <sjwilks@gmail.com> | 2013-01-25 01:41:11 +0100 |
---|---|---|
committer | Simon Wilks <sjwilks@gmail.com> | 2013-01-25 01:41:11 +0100 |
commit | 0246842c8854fcb49ffa34bcf46c61f2b7da95b2 (patch) | |
tree | e7548ad0b60ee181ed9c4804e68a2ca820f12c80 | |
parent | 23f0be6b025d84a721b9e08682da728f69d79238 (diff) | |
download | px4-firmware-0246842c8854fcb49ffa34bcf46c61f2b7da95b2.tar.gz px4-firmware-0246842c8854fcb49ffa34bcf46c61f2b7da95b2.tar.bz2 px4-firmware-0246842c8854fcb49ffa34bcf46c61f2b7da95b2.zip |
Enable single wire via ioctl calls and pull the battery voltage from the battery status topic.
-rw-r--r-- | apps/hott_telemetry/hott_telemetry_main.c | 37 | ||||
-rw-r--r-- | apps/hott_telemetry/messages.c | 10 | ||||
-rw-r--r-- | nuttx/include/nuttx/serial/tioctl.h | 2 |
3 files changed, 12 insertions, 37 deletions
diff --git a/apps/hott_telemetry/hott_telemetry_main.c b/apps/hott_telemetry/hott_telemetry_main.c index ae6c69b99..d67ab06a9 100644 --- a/apps/hott_telemetry/hott_telemetry_main.c +++ b/apps/hott_telemetry/hott_telemetry_main.c @@ -134,41 +134,8 @@ static int open_uart(const char *device, struct termios *uart_config_original) FATAL_MSG(msg); } - /* Get the appropriate GPIO pin and control register */ - uint32_t gpio_uart = GPIO_USART2_TX;; - uint32_t uart_cr3 = STM32_USART2_CR3; - - switch (device[strlen(device) - 1]) { - case '0': - gpio_uart = GPIO_USART1_TX; - uart_cr3 = STM32_USART1_CR3; - break; - - case '1': - gpio_uart = GPIO_USART2_TX; - uart_cr3 = STM32_USART2_CR3; - break; - - case '3': - gpio_uart = GPIO_USART6_TX; - uart_cr3 = STM32_USART6_CR3; - break; - - default: - sprintf(msg, "%s is not supported.\n", device); - close(uart); - FATAL_MSG(msg); - break; - } - - /* Change the TX port to be open-drain */ - stm32_configgpio(gpio_uart | GPIO_OPENDRAIN); - - /* Turn on half-duplex mode */ - uint32_t cr; - cr = getreg32(uart_cr3); - cr |= (USART_CR3_HDSEL); - putreg32(cr, uart_cr3); + /* Activate single wire mode */ + ioctl(uart, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED); return uart; } diff --git a/apps/hott_telemetry/messages.c b/apps/hott_telemetry/messages.c index dce16f371..8bfb99773 100644 --- a/apps/hott_telemetry/messages.c +++ b/apps/hott_telemetry/messages.c @@ -42,12 +42,15 @@ #include <string.h> #include <systemlib/systemlib.h> #include <unistd.h> +#include <uORB/topics/battery_status.h> #include <uORB/topics/sensor_combined.h> +static int battery_sub = -1; static int sensor_sub = -1; void messages_init(void) { + battery_sub = orb_subscribe(ORB_ID(battery_status)); sensor_sub = orb_subscribe(ORB_ID(sensor_combined)); } @@ -58,6 +61,11 @@ void build_eam_response(uint8_t *buffer, int *size) memset(&raw, 0, sizeof(raw)); orb_copy(ORB_ID(sensor_combined), sensor_sub, &raw); + /* get a local copy of the battery data */ + struct battery_status_s battery; + memset(&battery, 0, sizeof(battery)); + orb_copy(ORB_ID(battery_status), battery_sub, &battery); + struct eam_module_msg msg; *size = sizeof(msg); memset(&msg, 0, *size); @@ -67,7 +75,7 @@ void build_eam_response(uint8_t *buffer, int *size) msg.sensor_id = EAM_SENSOR_ID; msg.temperature1 = (uint8_t)(raw.baro_temp_celcius + 20); msg.temperature2 = TEMP_ZERO_CELSIUS; - msg.main_voltage_L = (uint8_t)(raw.battery_voltage_v * 10); + msg.main_voltage_L = (uint8_t)(battery.voltage_v * 10); uint16_t alt = (uint16_t)(raw.baro_alt_meter + 500); msg.altitude_L = (uint8_t)alt & 0xff; diff --git a/nuttx/include/nuttx/serial/tioctl.h b/nuttx/include/nuttx/serial/tioctl.h index 9edc7e87f..a98b487a6 100644 --- a/nuttx/include/nuttx/serial/tioctl.h +++ b/nuttx/include/nuttx/serial/tioctl.h @@ -177,7 +177,7 @@ #define TIOCSSINGLEWIRE _TIOC(0x002c) /* Set single-wire mode */ #define TIOCGSINGLEWIRE _TIOC(0x002d) /* Get single-wire mode */ -# define SER_SINGLEWIRE_ENABLED (1 << 0) /* Enable/disble single-wire support */ +# define SER_SINGLEWIRE_ENABLED (1 << 0) /* Enable/disable single-wire support */ /* Debugging */ |