mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-07 03:59:37 +00:00
Fix issue #5193: Optimise GPS probe code - one message per family
This commit is contained in:
parent
295278bb12
commit
a7946b5705
@ -40,6 +40,9 @@ GPS *gps = nullptr;
|
|||||||
|
|
||||||
GPSUpdateScheduling scheduling;
|
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
|
/// Multiple GPS instances might use the same serial port (in sequence), but we can
|
||||||
/// only init that port once.
|
/// only init that port once.
|
||||||
static bool didSerialInit;
|
static bool didSerialInit;
|
||||||
@ -185,6 +188,7 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
|
|||||||
#ifdef GPS_DEBUG
|
#ifdef GPS_DEBUG
|
||||||
LOG_DEBUG("Found: %s", message); // Log the found message
|
LOG_DEBUG("Found: %s", message); // Log the found message
|
||||||
#endif
|
#endif
|
||||||
|
cachedResponseStatus = GNSS_RESPONSE_OK;
|
||||||
return GNSS_RESPONSE_OK;
|
return GNSS_RESPONSE_OK;
|
||||||
} else {
|
} else {
|
||||||
bytesRead = 0;
|
bytesRead = 0;
|
||||||
@ -195,6 +199,7 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cachedResponseStatus = GNSS_RESPONSE_NONE;
|
||||||
return GNSS_RESPONSE_NONE;
|
return GNSS_RESPONSE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1099,13 +1104,26 @@ int GPS::prepareDeepSleep(void *unused)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *PROBE_MESSAGE = "Trying %s (%s)...";
|
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";
|
const char *DETECTED_MESSAGE = "%s detected, using %s Module";
|
||||||
|
|
||||||
#define PROBE_SIMPLE(CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \
|
#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); \
|
LOG_DEBUG(PROBE_MESSAGE, TOWRITE, CHIP); \
|
||||||
clearBuffer(); \
|
clearBuffer(); \
|
||||||
_serial_gps->write(TOWRITE "\r\n"); \
|
_serial_gps->write(TOWRITE "\r\n"); \
|
||||||
if (getACK(RESPONSE, TIMEOUT) == GNSS_RESPONSE_OK) { \
|
lastcmd = TOWRITE; \
|
||||||
|
} \
|
||||||
|
if (getACK(RESPONSE, TIMEOUT) == GNSS_RESPONSE_OK) \
|
||||||
|
{ \
|
||||||
LOG_INFO(DETECTED_MESSAGE, CHIP, #DRIVER); \
|
LOG_INFO(DETECTED_MESSAGE, CHIP, #DRIVER); \
|
||||||
return DRIVER; \
|
return DRIVER; \
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user