diff --git a/libraries/GCS_MAVLink/GCS.h b/libraries/GCS_MAVLink/GCS.h index 3c735b91f4b46b87cf847a58ce0dbddbd850b728..abd541da508a67635d878562e68bdb9e7ce0698b 100644 --- a/libraries/GCS_MAVLink/GCS.h +++ b/libraries/GCS_MAVLink/GCS.h @@ -144,6 +144,7 @@ public: GCS_MAVLINK(); void update(void); void init(AP_HAL::UARTDriver *port); + void setup_uart(AP_HAL::UARTDriver *port, uint32_t baudrate, uint16_t rxS, uint16_t txS); void send_message(enum ap_message id); void send_text(gcs_severity severity, const char *str); void send_text_P(gcs_severity severity, const prog_char_t *str); diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index 98034e5d3be342954094915279d705c013e7e3c8..4d3e2c3564663d818bc9f7b973b25fb431ab94a8 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -54,6 +54,41 @@ GCS_MAVLINK::init(AP_HAL::UARTDriver *port) } +/* + setup a UART, handling begin() and init() + */ +void +GCS_MAVLINK::setup_uart(AP_HAL::UARTDriver *port, uint32_t baudrate, uint16_t rxS, uint16_t txS) +{ + if (port == NULL) { + return; + } + + /* + Now try to cope with SiK radios that may be stuck in bootloader + mode because CTS was held while powering on. This tells the + bootloader to wait for a firmware. It affects any SiK radio with + CTS connected that is externally powered. To cope we send 0x30 + 0x20 at 115200 on startup, which tells the bootloader to reset + and boot normally + */ + port->begin(115200, rxS, txS); + AP_HAL::UARTDriver::flow_control old_flow_control = port->get_flow_control(); + port->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); + for (uint8_t i=0; i<3; i++) { + hal.scheduler->delay(1); + port->write(0x30); + port->write(0x20); + } + port->set_flow_control(old_flow_control); + + // now change to desired baudrate + port->begin(baudrate); + + // and init the gcs instance + init(port); +} + uint16_t GCS_MAVLINK::_count_parameters() {