Improved time synch handling for GPS based time

This will update the time from GPS on first valid time received by GPS.
This commit is contained in:
Oliver Seiler 2020-09-29 18:59:53 +13:00
parent cbaf705c15
commit 0a510a0c33
3 changed files with 9 additions and 24 deletions

View File

@ -21,9 +21,6 @@ static uint16_t nmea_txDelay_ms =
static uint16_t nmea_txDelay_ms = 0; static uint16_t nmea_txDelay_ms = 0;
#endif #endif
// did the last packet contain a valid time?
bool hasValidTime = false;
// initialize and configure GPS // initialize and configure GPS
int gps_init(void) { int gps_init(void) {
@ -163,16 +160,11 @@ void gps_loop(void *pvParameters) {
} }
#endif #endif
#if !TIME_SYNC_LORASERVER && !TIME_SYNC_LORAWAN // if time hasn't been synchronised yet, and we have a valid GPS time,
if (!hasValidTime) { // update time from GPS.
if (gpstime.isUpdated() && gpstime.isValid()) { if (timeSource == _unsynced && gpstime.isUpdated() && gpstime.isValid()) {
hasValidTime = true; calibrateTime();
if (timeSource == _unsynced) {
calibrateTime();
}
}
} }
#endif
} // if } // if

View File

@ -488,11 +488,6 @@ void setup() {
#warning you did not specify a time source, time will not be synched #warning you did not specify a time source, time will not be synched
#endif #endif
// initialize gps time
#if (HAS_GPS)
get_gpstime();
#endif
#if (defined HAS_IF482 || defined HAS_DCF77) #if (defined HAS_IF482 || defined HAS_DCF77)
ESP_LOGI(TAG, "Starting Clock Controller..."); ESP_LOGI(TAG, "Starting Clock Controller...");
clock_init(); clock_init();

View File

@ -32,7 +32,7 @@ void calibrateTime(void) {
uint16_t t_msec = 0; uint16_t t_msec = 0;
// kick off asychronous lora timesync if we have // kick off asychronous lora timesync if we have
#if (HAS_LORA) && (TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN) #if (HAS_LORA) && ((TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN))
timesync_request(); timesync_request();
#endif #endif
@ -44,19 +44,17 @@ void calibrateTime(void) {
// has RTC -> fallback to RTC time // has RTC -> fallback to RTC time
#ifdef HAS_RTC #ifdef HAS_RTC
t = get_rtctime(); t = get_rtctime();
timeSource = _rtc; // set time from RTC
setMyTime((uint32_t)t, t_msec, _rtc);
#endif #endif
// no RTC -> fallback to GPS time // no RTC -> fallback to GPS time
#if (HAS_GPS) #if (HAS_GPS)
t = get_gpstime(&t_msec); t = get_gpstime(&t_msec);
if (t) { // set time from GPS - method will check if time is valid
timeSource = _gps; setMyTime((uint32_t)t, t_msec, _gps);
}
#endif #endif
setMyTime((uint32_t)t, t_msec, timeSource); // set time
} // fallback } // fallback
else else