mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 15:43:33 +08:00
Code formatting cleanup.
Fixed code style with Tools/fix_code_style.sh
This commit is contained in:
@@ -107,6 +107,7 @@ static int open_uart(const char *device, struct termios *uart_config_original)
|
|||||||
|
|
||||||
/* Back up the original uart configuration to restore it after exit */
|
/* Back up the original uart configuration to restore it after exit */
|
||||||
char msg[80];
|
char msg[80];
|
||||||
|
|
||||||
if ((termios_state = tcgetattr(uart, uart_config_original)) < 0) {
|
if ((termios_state = tcgetattr(uart, uart_config_original)) < 0) {
|
||||||
sprintf(msg, "Error getting baudrate / termios config for %s: %d\n", device, termios_state);
|
sprintf(msg, "Error getting baudrate / termios config for %s: %d\n", device, termios_state);
|
||||||
close(uart);
|
close(uart);
|
||||||
@@ -136,24 +137,28 @@ static int open_uart(const char *device, struct termios *uart_config_original)
|
|||||||
/* Get the appropriate GPIO pin and control register */
|
/* Get the appropriate GPIO pin and control register */
|
||||||
uint32_t gpio_uart;
|
uint32_t gpio_uart;
|
||||||
uint32_t uart_cr3;
|
uint32_t uart_cr3;
|
||||||
switch(device[strlen(device) - 1]) {
|
|
||||||
case '0':
|
switch (device[strlen(device) - 1]) {
|
||||||
gpio_uart = GPIO_USART1_TX;
|
case '0':
|
||||||
uart_cr3 = STM32_USART1_CR3;
|
gpio_uart = GPIO_USART1_TX;
|
||||||
break;
|
uart_cr3 = STM32_USART1_CR3;
|
||||||
case '1':
|
break;
|
||||||
gpio_uart = GPIO_USART2_TX;
|
|
||||||
uart_cr3 = STM32_USART2_CR3;
|
case '1':
|
||||||
break;
|
gpio_uart = GPIO_USART2_TX;
|
||||||
case '2':
|
uart_cr3 = STM32_USART2_CR3;
|
||||||
sprintf(msg, "/dev/ttyS3 is not supported.\n", device);
|
break;
|
||||||
close(uart);
|
|
||||||
FATAL_MSG(msg);
|
case '2':
|
||||||
break;
|
sprintf(msg, "/dev/ttyS3 is not supported.\n", device);
|
||||||
case '3':
|
close(uart);
|
||||||
gpio_uart = GPIO_USART6_TX;
|
FATAL_MSG(msg);
|
||||||
uart_cr3 = STM32_USART6_CR3;
|
break;
|
||||||
break;
|
|
||||||
|
case '3':
|
||||||
|
gpio_uart = GPIO_USART6_TX;
|
||||||
|
uart_cr3 = STM32_USART6_CR3;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Change the TX port to be open-drain */
|
/* Change the TX port to be open-drain */
|
||||||
@@ -174,6 +179,7 @@ int read_data(int uart, int *id)
|
|||||||
struct pollfd fds[] = { { .fd = uart, .events = POLLIN } };
|
struct pollfd fds[] = { { .fd = uart, .events = POLLIN } };
|
||||||
|
|
||||||
char mode;
|
char mode;
|
||||||
|
|
||||||
if (poll(fds, 1, timeout) > 0) {
|
if (poll(fds, 1, timeout) > 0) {
|
||||||
/* Get the mode: binary or text */
|
/* Get the mode: binary or text */
|
||||||
read(uart, &mode, 1);
|
read(uart, &mode, 1);
|
||||||
@@ -184,10 +190,12 @@ int read_data(int uart, int *id)
|
|||||||
if (mode != BINARY_MODE_REQUEST_ID) {
|
if (mode != BINARY_MODE_REQUEST_ID) {
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ERROR_MSG("UART timeout on TX/RX port");
|
ERROR_MSG("UART timeout on TX/RX port");
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,13 +204,16 @@ int send_data(int uart, uint8_t *buffer, int size)
|
|||||||
usleep(POST_READ_DELAY_IN_USECS);
|
usleep(POST_READ_DELAY_IN_USECS);
|
||||||
|
|
||||||
uint16_t checksum = 0;
|
uint16_t checksum = 0;
|
||||||
for(int i = 0; i < size; i++) {
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
if (i == size - 1) {
|
if (i == size - 1) {
|
||||||
/* Set the checksum: the first uint8_t is taken as the checksum. */
|
/* Set the checksum: the first uint8_t is taken as the checksum. */
|
||||||
buffer[i] = checksum & 0xff;
|
buffer[i] = checksum & 0xff;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
checksum += buffer[i];
|
checksum += buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
write(uart, &buffer[i], 1);
|
write(uart, &buffer[i], 1);
|
||||||
|
|
||||||
/* Sleep before sending the next byte. */
|
/* Sleep before sending the next byte. */
|
||||||
@@ -255,15 +266,18 @@ int hott_telemetry_thread_main(int argc, char *argv[])
|
|||||||
uint8_t buffer[MESSAGE_BUFFER_SIZE];
|
uint8_t buffer[MESSAGE_BUFFER_SIZE];
|
||||||
int size = 0;
|
int size = 0;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
while (!thread_should_exit) {
|
while (!thread_should_exit) {
|
||||||
if (read_data(uart, &id) == OK) {
|
if (read_data(uart, &id) == OK) {
|
||||||
switch(id) {
|
switch (id) {
|
||||||
case ELECTRIC_AIR_MODULE:
|
case ELECTRIC_AIR_MODULE:
|
||||||
build_eam_response(buffer, &size);
|
build_eam_response(buffer, &size);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
continue; // Not a module we support.
|
default:
|
||||||
|
continue; // Not a module we support.
|
||||||
}
|
}
|
||||||
|
|
||||||
send_data(uart, buffer, size);
|
send_data(uart, buffer, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,9 +327,11 @@ int hott_telemetry_main(int argc, char *argv[])
|
|||||||
if (!strcmp(argv[1], "status")) {
|
if (!strcmp(argv[1], "status")) {
|
||||||
if (thread_running) {
|
if (thread_running) {
|
||||||
INFO_MSG("daemon is running");
|
INFO_MSG("daemon is running");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
INFO_MSG("daemon not started");
|
INFO_MSG("daemon not started");
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user