Skip to content

Commit 6c09cf9

Browse files
jp-bennettfifieldt
andauthored
Gps reset detect (#8302)
* Properly format timestamp in log message * Better formatting of GPS_DEBUG logging in gps probe * Reset GPS after serial speed change, and look for magic string to identify chip * Add UC6580 to boot message detection, for Heltec Tracker * Add L76K detect from boot string, for Heltec-v4 * Slightly more useful GPS debugging * Back out detection of L76K via startup messages. * Ignore PIN_GPS_RESET = -1 and rename passive_detect array. --------- Co-authored-by: Tom Fifield <[email protected]>
1 parent 79a9157 commit 6c09cf9

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/gps/GPS.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,16 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis)
240240
buffer[bytesRead] = b;
241241
bytesRead++;
242242
if ((bytesRead == 767) || (b == '\r')) {
243+
#ifdef GPS_DEBUG
244+
LOG_DEBUG(debugmsg.c_str());
245+
#endif
243246
if (strnstr((char *)buffer, message, bytesRead) != nullptr) {
244247
#ifdef GPS_DEBUG
245248
LOG_DEBUG("Found: %s", message); // Log the found message
246249
#endif
247250
return GNSS_RESPONSE_OK;
248251
} else {
249252
bytesRead = 0;
250-
#ifdef GPS_DEBUG
251-
LOG_DEBUG(debugmsg.c_str());
252-
#endif
253253
}
254254
}
255255
}
@@ -1275,6 +1275,24 @@ GnssModel_t GPS::probe(int serialSpeed)
12751275
memset(&ublox_info, 0, sizeof(ublox_info));
12761276
delay(100);
12771277

1278+
#if defined(PIN_GPS_RESET) && PIN_GPS_RESET != -1
1279+
digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms
1280+
delay(10);
1281+
digitalWrite(PIN_GPS_RESET, !GPS_RESET_MODE);
1282+
1283+
// attempt to detect the chip based on boot messages
1284+
std::vector<ChipInfo> passive_detect = {
1285+
{"AG3335", "$PAIR021,AG3335", GNSS_MODEL_AG3335},
1286+
{"AG3352", "$PAIR021,AG3352", GNSS_MODEL_AG3352},
1287+
{"RYS3520", "$PAIR021,REYAX_RYS3520_V2", GNSS_MODEL_AG3352},
1288+
{"UC6580", "UC6580", GNSS_MODEL_UC6580},
1289+
// as L76K is sort of a last ditch effort, we won't attempt to detect it by startup messages for now.
1290+
/*{"L76K", "SW=URANUS", GNSS_MODEL_MTK}*/};
1291+
GnssModel_t detectedDriver = getProbeResponse(500, passive_detect, serialSpeed);
1292+
if (detectedDriver != GNSS_MODEL_UNKNOWN) {
1293+
return detectedDriver;
1294+
}
1295+
#endif
12781296
// Close all NMEA sentences, valid for L76K, ATGM336H (and likely other AT6558 devices)
12791297
_serial_gps->write("$PCAS03,0,0,0,0,0,0,0,0,0,0,,,0,0*02\r\n");
12801298
delay(20);
@@ -1473,19 +1491,22 @@ GnssModel_t GPS::getProbeResponse(unsigned long timeout, const std::vector<ChipI
14731491
}
14741492

14751493
if (c == ',' || (responseLen >= 2 && response[responseLen - 2] == '\r' && response[responseLen - 1] == '\n')) {
1476-
#ifdef GPS_DEBUG
1477-
LOG_DEBUG(response);
1478-
#endif
14791494
// check if we can see our chips
14801495
for (const auto &chipInfo : responseMap) {
14811496
if (strstr(response, chipInfo.detectionString.c_str()) != nullptr) {
1497+
#ifdef GPS_DEBUG
1498+
LOG_DEBUG(response);
1499+
#endif
14821500
LOG_INFO("%s detected", chipInfo.chipName.c_str());
14831501
delete[] response; // Cleanup before return
14841502
return chipInfo.driver;
14851503
}
14861504
}
14871505
}
14881506
if (responseLen >= 2 && response[responseLen - 2] == '\r' && response[responseLen - 1] == '\n') {
1507+
#ifdef GPS_DEBUG
1508+
LOG_DEBUG(response);
1509+
#endif
14891510
// Reset the response buffer for the next potential message
14901511
responseLen = 0;
14911512
response[0] = '\0';
@@ -1572,8 +1593,6 @@ GPS *GPS::createGps()
15721593

15731594
#ifdef PIN_GPS_RESET
15741595
pinMode(PIN_GPS_RESET, OUTPUT);
1575-
digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms
1576-
delay(10);
15771596
digitalWrite(PIN_GPS_RESET, !GPS_RESET_MODE);
15781597
#endif
15791598

src/gps/RTC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ RTCSetResult perhapsSetRTC(RTCQuality q, struct tm &t)
310310
#ifdef BUILD_EPOCH
311311
if (tv.tv_sec < BUILD_EPOCH) {
312312
if (Throttle::isWithinTimespanMs(lastTimeValidationWarning, TIME_VALIDATION_WARNING_INTERVAL_MS) == false) {
313-
LOG_WARN("Ignore time (%ld) before build epoch (%ld)!", printableEpoch, BUILD_EPOCH);
313+
LOG_WARN("Ignore time (%lu) before build epoch (%lu)!", printableEpoch, BUILD_EPOCH);
314314
lastTimeValidationWarning = millis();
315315
}
316316
return RTCSetResultInvalidTime;
@@ -319,7 +319,7 @@ RTCSetResult perhapsSetRTC(RTCQuality q, struct tm &t)
319319
// Calculate max allowed time safely to avoid overflow in logging
320320
uint64_t maxAllowedTime = (uint64_t)BUILD_EPOCH + FORTY_YEARS;
321321
uint32_t maxAllowedPrintable = (maxAllowedTime > UINT32_MAX) ? UINT32_MAX : (uint32_t)maxAllowedTime;
322-
LOG_WARN("Ignore time (%ld) too far in the future (build epoch: %ld, max allowed: %ld)!", printableEpoch,
322+
LOG_WARN("Ignore time (%lu) too far in the future (build epoch: %lu, max allowed: %lu)!", printableEpoch,
323323
(uint32_t)BUILD_EPOCH, maxAllowedPrintable);
324324
lastTimeValidationWarning = millis();
325325
}

0 commit comments

Comments
 (0)