From 3a3f9bdb8435b76e348e79028cd34fb11d3cb2ab Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 28 Sep 2022 21:40:44 +1000 Subject: [PATCH] AP_GPS: cycle through baud rates for SBF/GSOF/NOVA/SITL --- libraries/AP_GPS/AP_GPS.cpp | 47 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS.cpp b/libraries/AP_GPS/AP_GPS.cpp index a750586899..25aac2affc 100644 --- a/libraries/AP_GPS/AP_GPS.cpp +++ b/libraries/AP_GPS/AP_GPS.cpp @@ -693,6 +693,29 @@ AP_GPS_Backend *AP_GPS::_detect_instance(uint8_t instance) // all remaining drivers automatically cycle through baud rates to detect // the correct baud rate, and should have the selected baud broadcast dstate->auto_detected_baud = true; + const uint32_t now = AP_HAL::millis(); + + if (now - dstate->last_baud_change_ms > GPS_BAUD_TIME_MS) { + // try the next baud rate + // incrementing like this will skip the first element in array of bauds + // this is okay, and relied upon + dstate->current_baud++; + if (dstate->current_baud == ARRAY_SIZE(_baudrates)) { + dstate->current_baud = 0; + } + uint32_t baudrate = _baudrates[dstate->current_baud]; + _port[instance]->begin(baudrate); + _port[instance]->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); + dstate->last_baud_change_ms = now; + + if (_auto_config >= GPS_AUTO_CONFIG_ENABLE_SERIAL_ONLY) { + send_blob_start(instance); + } + } + + if (_auto_config >= GPS_AUTO_CONFIG_ENABLE_SERIAL_ONLY) { + send_blob_update(instance); + } switch (_type[instance]) { #if AP_GPS_SBF_ENABLED @@ -718,30 +741,6 @@ AP_GPS_Backend *AP_GPS::_detect_instance(uint8_t instance) break; } - const uint32_t now = AP_HAL::millis(); - - if (now - dstate->last_baud_change_ms > GPS_BAUD_TIME_MS) { - // try the next baud rate - // incrementing like this will skip the first element in array of bauds - // this is okay, and relied upon - dstate->current_baud++; - if (dstate->current_baud == ARRAY_SIZE(_baudrates)) { - dstate->current_baud = 0; - } - uint32_t baudrate = _baudrates[dstate->current_baud]; - _port[instance]->begin(baudrate); - _port[instance]->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); - dstate->last_baud_change_ms = now; - - if (_auto_config >= GPS_AUTO_CONFIG_ENABLE_SERIAL_ONLY) { - send_blob_start(instance); - } - } - - if (_auto_config >= GPS_AUTO_CONFIG_ENABLE_SERIAL_ONLY) { - send_blob_update(instance); - } - if (initblob_state[instance].remaining != 0) { // don't run detection engines if we haven't sent out the initblobs return nullptr;