Add support for fixing GPS_BAUDRATE

If GPS_BAUDRATE is set in variant.h, the deployer knows something we
don't about the GPS. Used especially when the GPS is soldered to a board
in a commercial product :) If we see that, we don't try other baud rates
at all.
This commit is contained in:
Tom Fifield 2024-11-02 10:16:07 +08:00
parent e65b0efb82
commit 3b265f5392
3 changed files with 43 additions and 30 deletions

View File

@ -207,6 +207,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef GPS_BAUDRATE #ifndef GPS_BAUDRATE
#define GPS_BAUDRATE 9600 #define GPS_BAUDRATE 9600
#define GPS_BAUDRATE_FIXED 0
#else
#define GPS_BAUDRATE_FIXED 1
#endif #endif
/* Step #2: follow with defines common to the architecture; /* Step #2: follow with defines common to the architecture;

View File

@ -413,6 +413,13 @@ int GPS::getACK(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t
return 0; 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() bool GPS::setup()
{ {
@ -420,14 +427,17 @@ bool GPS::setup()
int msglen = 0; int msglen = 0;
if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) { if (tx_gpio && gnssModel == GNSS_MODEL_UNKNOWN) {
// if GPS_BAUDRATE is specified in variant (i.e. not 9600), skip to the specified rate. // if GPS_BAUDRATE is specified in variant, skip to the specified rate.
if (probeTries == 0 && speedSelect == 0 && GPS_BAUDRATE != serialSpeeds[speedSelect]) { if (GPS_BAUDRATE_FIXED) {
speedSelect = std::find(serialSpeeds, std::end(serialSpeeds), GPS_BAUDRATE) - serialSpeeds; gnssModel = probe(GPS_BAUDRATE);
if (speedSelect == 0) { if (gnssModel == GNSS_MODEL_UNKNOWN && probeTries == 1) {
speedSelect = std::find(rareSerialSpeeds, std::end(rareSerialSpeeds), GPS_BAUDRATE) - rareSerialSpeeds; LOG_WARN("GPS probe failed, setting to %d", GPS_BAUDRATE);
probeTries = 1; return true;
} } else {
++probeTries;
return false;
} }
} else {
if (probeTries == 0) { if (probeTries == 0) {
LOG_DEBUG("Probing for GPS at %d", serialSpeeds[speedSelect]); LOG_DEBUG("Probing for GPS at %d", serialSpeeds[speedSelect]);
gnssModel = probe(serialSpeeds[speedSelect]); gnssModel = probe(serialSpeeds[speedSelect]);
@ -447,9 +457,10 @@ bool GPS::setup()
LOG_WARN("Giving up on GPS probe and setting to %d", GPS_BAUDRATE); LOG_WARN("Giving up on GPS probe and setting to %d", GPS_BAUDRATE);
return true; return true;
} }
return false;
} }
} }
return false;
}
} else { } else {
gnssModel = GNSS_MODEL_UNKNOWN; gnssModel = GNSS_MODEL_UNKNOWN;
} }

View File

@ -76,9 +76,8 @@ class GPS : private concurrency::OSThread
uint8_t fixType = 0; // fix type from GPGSA uint8_t fixType = 0; // fix type from GPGSA
#endif #endif
private: private:
const int serialSpeeds[3] = {9600, 115200, 38400};
const int serialSpeeds[6] = {9600, 115200, 38400}; const int rareSerialSpeeds[3] = {4800, 57600, GPS_BAUDRATE};
const int rareSerialSpeeds[6] = {4800, 57600, GPS_BAUDRATE};
uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0; uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0;
uint32_t rx_gpio = 0; uint32_t rx_gpio = 0;