[mavlink] Parameter to always start on USB (#22234)

* usb: Added parameter to enable always starting mavlink on USB.

    Refactored cdcacm_init into a module and added a paramter to allow always starting mavlink on
    USB, also added a paramter to choose the mode. The current default behavior is to wait and listen
    for data on USB and auto-detect the protocol (mavlink, nsh, ublox). This results in the mavlink
    stream not starting until something else on the mavlink network sends a packet first. The new
    default behavior is to always start mavlink.

    Added parameters
    MAV_USB_ENABLE -- default 1 (always start mavlink on USB)
    MAV_USE_MODE -- default 3 (onboard)

* added 3 retries for opening serial port in mavlink, removed sleep before sercon

* added DRIVERS_CDCACM_AUTOSTART to ark-v6x default.px4board

* added CONFIG_DRIVERS_CDCACM_AUTOSTART=y to default.px4board for boards with CONFIG_CDCACM in their nsh/defconfig

* format

* remove PGA460 from COMMON_DISTANCE_SENSOR to save flash

* remove LIS2MDL from COMMON_MAGNETOMETER to save flash

* disable CONFIG_DRIVERS_CDCACM_AUTOSTART for fmu-v5 protected.px4board

* moved and renamed parameters, removed mode logic in mavlink

* changed parameter names, added mode none

* remove parameters from mavlink
This commit is contained in:
Jacob Dahl
2024-05-20 12:35:29 -06:00
committed by GitHub
parent 6b0ac49daf
commit 70304fe715
67 changed files with 982 additions and 25 deletions
+17 -9
View File
@@ -2094,11 +2094,6 @@ Mavlink::task_main(int argc, char *argv[])
/* USB has no baudrate, but use a magic number for 'fast' */
_baudrate = 2000000;
if (_mode == MAVLINK_MODE_COUNT) {
_mode = MAVLINK_MODE_CONFIG;
}
_ftp_on = true;
_is_usb_uart = true;
@@ -2223,11 +2218,24 @@ Mavlink::task_main(int argc, char *argv[])
/* open the UART device after setting the instance, as it might block */
if (get_protocol() == Protocol::SERIAL) {
_uart_fd = mavlink_open_uart(_baudrate, _device_name, _flow_control);
if (_uart_fd < 0) {
PX4_ERR("could not open %s", _device_name);
return PX4_ERROR;
// NOTE: we attempt to open the port multiple times due to sercon returning before
// the port is ready to be opened. This avoids needing to sleep() after sercon_main.
int attempts = 0;
static const int max_attempts = 3;
while (_uart_fd < 0) {
_uart_fd = mavlink_open_uart(_baudrate, _device_name, _flow_control);
attempts++;
if (_uart_fd < 0 && attempts < max_attempts) {
PX4_ERR("could not open %s, retrying", _device_name);
px4_usleep(1_s);
} else if (_uart_fd < 0) {
PX4_ERR("failed to open %s after %d attempts, exiting!", _device_name, attempts);
return PX4_ERROR;
}
}
}