39 #include <px4_platform_common/time.h> 40 #include <px4_platform_common/px4_config.h> 41 #include <px4_platform_common/defines.h> 42 #include <px4_platform_common/log.h> 43 #include <px4_platform_common/posix.h> 44 #include <sys/ioctl.h> 45 #include <sys/types.h> 64 int uart = open(device, O_RDWR | O_NOCTTY);
67 PX4_ERR(
"FAIL: Error opening port");
72 struct termios uart_config;
75 tcgetattr(uart, &uart_config);
78 uart_config.c_oflag &= ~ONLCR;
81 if (cfsetispeed(&uart_config, speed) < 0 || cfsetospeed(&uart_config, speed) < 0) {
82 PX4_ERR(
"FAIL: Error setting baudrate / termios config for cfsetispeed, cfsetospeed");
86 if (tcsetattr(uart, TCSANOW, &uart_config) < 0) {
87 PX4_ERR(
"FAIL: Error setting baudrate / termios config for tcsetattr");
96 PX4_INFO(
"HoTT Telemetry Test Requirements:");
97 PX4_INFO(
"- Radio on and Electric Air. Mod on (telemetry -> sensor select).");
98 PX4_INFO(
"- Receiver telemetry port must be in telemetry mode.");
99 PX4_INFO(
"- Connect telemetry wire to /dev/ttyS1 (USART2).");
100 PX4_INFO(
"Testing...");
102 const char device[] =
"/dev/ttyS1";
110 #ifdef TIOCSSINGLEWIRE 112 ioctl(fd, TIOCSSINGLEWIRE, SER_SINGLEWIRE_ENABLED);
119 const int timeout = 1000;
120 struct pollfd fds[] = { { .fd =
fd, .events = POLLIN } };
122 if (poll(fds, 1, timeout) == 0) {
123 PX4_ERR(
"FAIL: Could not read sent data.");
128 read(fd, &receive, 1);
129 PX4_INFO(
"PASS: Single wire enabled. Sent %x and received %x", send, receive);
133 int received_count = 0;
135 const int max_polls = 5;
138 for (; received_count < 5; received_count++) {
139 if (poll(fds, 1, timeout) == 0) {
140 PX4_ERR(
"FAIL: Could not read sent data. Is your HoTT receiver plugged in on %s?", device);
155 if (received_count > 0 && valid_count > 0) {
156 if (received_count == max_polls && valid_count == max_polls) {
157 PX4_INFO(
"PASS: Received %d out of %d valid byte pairs from the HoTT receiver device.", received_count, max_polls);
160 PX4_WARN(
"WARN: Received %d out of %d byte pairs of which %d were valid from the HoTT receiver device.", received_count,
161 max_polls, valid_count);
166 if (received_count == 0) {
167 PX4_ERR(
"FAIL: Could not read any polls from HoTT receiver device.");
171 if (valid_count == 0) {
172 PX4_ERR(
"FAIL: Received unexpected values from the HoTT receiver device.");
179 uint8_t response[] = {0x7c, 0x8e, 0x00, 0xe0, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, \
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, \
182 0x19, 0x00, 0x00, 0x00, 0x30, 0x75, 0x78, 0x00, 0x00, 0x00, \
183 0x00, 0x00, 0x00, 0x7d, 0x12
188 for (
unsigned int i = 0; i <
sizeof(response); i++) {
189 write(fd, &response[i], 1);
193 PX4_INFO(
"PASS: Response sent to the HoTT receiver device. Voltage should now show 2.5V.");
196 #ifdef TIOCSSINGLEWIRE 198 ioctl(fd, TIOCSSINGLEWIRE, ~SER_SINGLEWIRE_ENABLED);
204 if (poll(fds, 1, timeout) == 0) {
205 PX4_ERR(
"FAIL: timeout expected.");
209 PX4_INFO(
"PASS: Single wire disabled.");
static int open_uart(const char *device)
Namespace encapsulating all device framework classes, functions and data.
static void read(bootloader_app_shared_t *pshared)
static void write(bootloader_app_shared_t *pshared)
int test_hott_telemetry(int argc, char *argv[])