Skip to content

Commit

Permalink
Add support for fixing GPS_BAUDRATE
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fifieldt committed Nov 2, 2024
1 parent e65b0ef commit 3b265f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#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;
Expand Down
59 changes: 35 additions & 24 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,42 +413,53 @@ 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()
{

if (!didSerialInit) {
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;
} else {
++probeTries;
return false;
}
}
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 {
gnssModel = GNSS_MODEL_UNKNOWN;
Expand Down
5 changes: 2 additions & 3 deletions src/gps/GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ 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};
const int serialSpeeds[3] = {9600, 115200, 38400};
const int rareSerialSpeeds[3] = {4800, 57600, GPS_BAUDRATE};

uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0;
uint32_t rx_gpio = 0;
Expand Down

0 comments on commit 3b265f5

Please sign in to comment.