Synch time from GPX on first valid GPS time received
This commit is contained in:
parent
19710bae4b
commit
1c40572c9b
@ -21,6 +21,9 @@ static uint16_t nmea_txDelay_ms =
|
||||
static uint16_t nmea_txDelay_ms = 0;
|
||||
#endif
|
||||
|
||||
// did the last packet contain a valid time?
|
||||
bool hasValidTime = false;
|
||||
|
||||
// initialize and configure GPS
|
||||
int gps_init(void) {
|
||||
|
||||
@ -159,6 +162,18 @@ void gps_loop(void *pvParameters) {
|
||||
delay(2); // 2ms delay according L76 datasheet
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !TIME_SYNC_LORASERVER && !TIME_SYNC_LORAWAN
|
||||
if (!hasValidTime) {
|
||||
if (gpstime.isUpdated() && gpstime.isValid()) {
|
||||
hasValidTime = true;
|
||||
if (timeSource == _unsynced) {
|
||||
calibrateTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // if
|
||||
|
||||
// show NMEA data in verbose mode, useful for debugging GPS, bu tvery noisy
|
||||
|
@ -26,7 +26,8 @@ Ticker timesyncer;
|
||||
void timeSync() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
|
||||
|
||||
void calibrateTime(void) {
|
||||
|
||||
ESP_LOGD(TAG, "[%0.3f] calibrateTime, timeSource == %d", millis() / 1000.0,
|
||||
timeSource);
|
||||
time_t t = 0;
|
||||
uint16_t t_msec = 0;
|
||||
|
||||
@ -49,7 +50,9 @@ void calibrateTime(void) {
|
||||
// no RTC -> fallback to GPS time
|
||||
#if (HAS_GPS)
|
||||
t = get_gpstime(&t_msec);
|
||||
if (t) {
|
||||
timeSource = _gps;
|
||||
}
|
||||
#endif
|
||||
|
||||
setMyTime((uint32_t)t, t_msec, timeSource); // set time
|
||||
|
Loading…
Reference in New Issue
Block a user