Skip to content

Commit

Permalink
Fix issue #5193: Optimise GPS probe code - one message per family
Browse files Browse the repository at this point in the history
  • Loading branch information
absolut3ego committed Nov 4, 2024
1 parent 8c99f91 commit eb3df6a
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ GPS *gps = nullptr;

GPSUpdateScheduling scheduling;

static const char *lastcmd = nullptr;
static GPS_RESPONSE cachedResponseStatus = GNSS_RESPONSE_NONE;

/// Multiple GPS instances might use the same serial port (in sequence), but we can
/// only init that port once.
static bool didSerialInit;
Expand Down Expand Up @@ -185,6 +188,7 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
#ifdef GPS_DEBUG
LOG_DEBUG("Found: %s", message); // Log the found message
#endif
cachedResponseStatus = GNSS_RESPONSE_OK;
return GNSS_RESPONSE_OK;
} else {
bytesRead = 0;
Expand All @@ -195,6 +199,7 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
}
}
}
cachedResponseStatus = GNSS_RESPONSE_NONE;
return GNSS_RESPONSE_NONE;
}

Expand Down Expand Up @@ -1109,15 +1114,28 @@ int GPS::prepareDeepSleep(void *unused)
}

const char *PROBE_MESSAGE = "Trying %s (%s)...";
const char *PROBE_MESSAGE_PREVIOUS = "Using previous buffer for command: %s";
const char *DETECTED_MESSAGE = "%s detected, using %s Module";

#define PROBE_SIMPLE(CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
LOG_DEBUG(PROBE_MESSAGE, TOWRITE, CHIP); \
clearBuffer(); \
_serial_gps->write(TOWRITE "\r\n"); \
if (getACK(RESPONSE, TIMEOUT) == GNSS_RESPONSE_OK) { \
LOG_INFO(DETECTED_MESSAGE, CHIP, #DRIVER); \
return DRIVER; \
#define PROBE_SIMPLE(CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
if (lastcmd && strcmp(TOWRITE, lastcmd) == 0) \
{ \
LOG_DEBUG(PROBE_MESSAGE_PREVIOUS, TOWRITE); \
if (cachedResponseStatus) \
{ \
LOG_INFO(DETECTED_MESSAGE, CHIP, #DRIVER); \
return DRIVER; \
} \
} else { \
LOG_DEBUG(PROBE_MESSAGE, TOWRITE, CHIP); \
clearBuffer(); \
_serial_gps->write(TOWRITE "\r\n"); \
lastcmd = TOWRITE; \
} \
if (getACK(RESPONSE, TIMEOUT) == GNSS_RESPONSE_OK) \
{ \
LOG_INFO(DETECTED_MESSAGE, CHIP, #DRIVER); \
return DRIVER; \
}

GnssModel_t GPS::probe(int serialSpeed)
Expand Down

0 comments on commit eb3df6a

Please sign in to comment.