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 1cdf6e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 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
56 changes: 32 additions & 24 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,41 +413,49 @@ 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;
}
}
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 {
Expand Down
1 change: 0 additions & 1 deletion src/gps/GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit 1cdf6e4

Please sign in to comment.