diff --git a/src/configuration.h b/src/configuration.h index cb2326470c..33f11bd766 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -207,6 +207,9 @@ along with this program. If not, see . #ifndef GPS_BAUDRATE #define GPS_BAUDRATE 9600 +#define GPS_BAUDRATE_FIXED 0 +#else +#define GPS_BAUDRATE_FIXED 1 #endif /* Step #2: follow with defines common to the architecture; diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 2302e200de..530e67c82a 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -413,6 +413,13 @@ int GPS::getACK(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t return 0; } +/** + * @brief Setup the GPS based on the model detected. + * We detect the GPS by cyling through a set of baud rates, first common then rare. + * For each baud rate, we run GPS::Probe to send commands and match the responses + * to known GPS responses. + * @retval Whether setup reached the end of its potential to configure the GPS. + */ bool GPS::setup() { @@ -420,34 +427,35 @@ bool GPS::setup() int msglen = 0; if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { - // if GPS_BAUDRATE is specified in variant (i.e. not 9600), skip to the specified rate. - if (probeTries == 0 && speedSelect == 0 && GPS_BAUDRATE != serialSpeeds[speedSelect]) { - speedSelect = std::find(serialSpeeds, std::end(serialSpeeds), GPS_BAUDRATE) - serialSpeeds; - if (speedSelect == 0) { - speedSelect = std::find(rareSerialSpeeds, std::end(rareSerialSpeeds), GPS_BAUDRATE) - rareSerialSpeeds; - probeTries = 1; + // if GPS_BAUDRATE is specified in variant, skip to the specified rate. + if (GPS_BAUDRATE_FIXED) { + gnssModel = probe(GPS_BAUDRATE); + if (gnssModel == GNSS_MODEL_UNKNOWN && probeTries == 1) { + LOG_WARN("GPS probe failed, setting to %d", GPS_BAUDRATE); + return true; } - } - if (probeTries == 0) { - LOG_DEBUG("Probing for GPS at %d", serialSpeeds[speedSelect]); - gnssModel = probe(serialSpeeds[speedSelect]); - if (gnssModel == GNSS_MODEL_UNKNOWN) { - if (++speedSelect == sizeof(serialSpeeds) / sizeof(int)) { - speedSelect = 0; - ++probeTries; + } else { + if (probeTries == 0) { + LOG_DEBUG("Probing for GPS at %d", serialSpeeds[speedSelect]); + gnssModel = probe(serialSpeeds[speedSelect]); + if (gnssModel == GNSS_MODEL_UNKNOWN) { + if (++speedSelect == sizeof(serialSpeeds) / sizeof(int)) { + speedSelect = 0; + ++probeTries; + } } } - } - // Rare Serial Speeds - if (probeTries == 1) { - LOG_DEBUG("Probing for GPS at %d", rareSerialSpeeds[speedSelect]); - gnssModel = probe(rareSerialSpeeds[speedSelect]); - if (gnssModel == GNSS_MODEL_UNKNOWN) { - if (++speedSelect == sizeof(rareSerialSpeeds) / sizeof(int)) { - LOG_WARN("Giving up on GPS probe and setting to %d", GPS_BAUDRATE); - return true; + // Rare Serial Speeds + if (probeTries == 1) { + LOG_DEBUG("Probing for GPS at %d", rareSerialSpeeds[speedSelect]); + gnssModel = probe(rareSerialSpeeds[speedSelect]); + if (gnssModel == GNSS_MODEL_UNKNOWN) { + if (++speedSelect == sizeof(rareSerialSpeeds) / sizeof(int)) { + LOG_WARN("Giving up on GPS probe and setting to %d", GPS_BAUDRATE); + return true; + } + return false; } - return false; } } } else { diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 808c4008b7..62de0b2b8b 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -76,7 +76,6 @@ class GPS : private concurrency::OSThread uint8_t fixType = 0; // fix type from GPGSA #endif private: - const int serialSpeeds[6] = {9600, 115200, 38400}; const int rareSerialSpeeds[6] = {4800, 57600, GPS_BAUDRATE};