mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 15:43:35 +08:00
Additions to the Serial UART API (#22953)
- Added an empty constructor, setPort, and validatePort functions for Serial API - Changed GPS to not allocate Serial object dynamically - Moved access check on serial port name into the Serial API - Improved the Qurt platform validatePort Serial function to implement a more rigorous check. Added safety check to the setPort Serial function to make sure it isn't called after the port has been already opened.
This commit is contained in:
@@ -25,19 +25,32 @@ void configure_uart_callbacks(open_uart_func_t open_func,
|
||||
}
|
||||
}
|
||||
|
||||
int qurt_uart_open(const char *dev, speed_t speed)
|
||||
int qurt_uart_get_port(const char *dev)
|
||||
{
|
||||
if (_callbacks_configured) {
|
||||
if (dev != NULL) {
|
||||
// Convert device string into a uart port number
|
||||
char *endptr = NULL;
|
||||
uint8_t port_number = (uint8_t) strtol(dev, &endptr, 10);
|
||||
int port_number = strtol(dev, &endptr, 10);
|
||||
|
||||
if ((port_number == 0) && (endptr == dev)) {
|
||||
PX4_ERR("Could not convert %s into a valid uart port number", dev);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return _open_uart(port_number, speed);
|
||||
} else {
|
||||
return port_number;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qurt_uart_open(const char *dev, speed_t speed)
|
||||
{
|
||||
int port_number = qurt_uart_get_port(dev);
|
||||
|
||||
if (_callbacks_configured && (port_number >= 0)) {
|
||||
|
||||
return _open_uart((uint8_t) port_number, speed);
|
||||
|
||||
} else {
|
||||
PX4_ERR("Cannot open uart until callbacks have been configured");
|
||||
|
||||
@@ -7,6 +7,7 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <termios.h>
|
||||
|
||||
int qurt_uart_get_port(const char *dev);
|
||||
int qurt_uart_open(const char *dev, speed_t speed);
|
||||
int qurt_uart_write(int fd, const char *buf, size_t len);
|
||||
int qurt_uart_read(int fd, char *buf, size_t len, uint32_t timeout_us);
|
||||
|
||||
Reference in New Issue
Block a user