mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-01 07:11:35 +08:00
Enable single wire via ioctl calls and pull the battery voltage from the battery status topic.
This commit is contained in:
@@ -134,41 +134,8 @@ static int open_uart(const char *device, struct termios *uart_config_original)
|
|||||||
FATAL_MSG(msg);
|
FATAL_MSG(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the appropriate GPIO pin and control register */
|
/* Activate single wire mode */
|
||||||
uint32_t gpio_uart = GPIO_USART2_TX;;
|
ioctl(uart, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED);
|
||||||
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);
|
|
||||||
|
|
||||||
return uart;
|
return uart;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <systemlib/systemlib.h>
|
#include <systemlib/systemlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <uORB/topics/battery_status.h>
|
||||||
#include <uORB/topics/sensor_combined.h>
|
#include <uORB/topics/sensor_combined.h>
|
||||||
|
|
||||||
|
static int battery_sub = -1;
|
||||||
static int sensor_sub = -1;
|
static int sensor_sub = -1;
|
||||||
|
|
||||||
void messages_init(void)
|
void messages_init(void)
|
||||||
{
|
{
|
||||||
|
battery_sub = orb_subscribe(ORB_ID(battery_status));
|
||||||
sensor_sub = orb_subscribe(ORB_ID(sensor_combined));
|
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));
|
memset(&raw, 0, sizeof(raw));
|
||||||
orb_copy(ORB_ID(sensor_combined), sensor_sub, &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;
|
struct eam_module_msg msg;
|
||||||
*size = sizeof(msg);
|
*size = sizeof(msg);
|
||||||
memset(&msg, 0, *size);
|
memset(&msg, 0, *size);
|
||||||
@@ -67,7 +75,7 @@ void build_eam_response(uint8_t *buffer, int *size)
|
|||||||
msg.sensor_id = EAM_SENSOR_ID;
|
msg.sensor_id = EAM_SENSOR_ID;
|
||||||
msg.temperature1 = (uint8_t)(raw.baro_temp_celcius + 20);
|
msg.temperature1 = (uint8_t)(raw.baro_temp_celcius + 20);
|
||||||
msg.temperature2 = TEMP_ZERO_CELSIUS;
|
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);
|
uint16_t alt = (uint16_t)(raw.baro_alt_meter + 500);
|
||||||
msg.altitude_L = (uint8_t)alt & 0xff;
|
msg.altitude_L = (uint8_t)alt & 0xff;
|
||||||
|
|||||||
@@ -177,7 +177,7 @@
|
|||||||
#define TIOCSSINGLEWIRE _TIOC(0x002c) /* Set single-wire mode */
|
#define TIOCSSINGLEWIRE _TIOC(0x002c) /* Set single-wire mode */
|
||||||
#define TIOCGSINGLEWIRE _TIOC(0x002d) /* Get 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 */
|
/* Debugging */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user