bugfix no GPS time sync after cold start (#376)

This commit is contained in:
Verkehrsrot 2019-07-07 16:00:48 +02:00
parent 194ee9d813
commit fbe0cf3b2e
3 changed files with 21 additions and 14 deletions

View File

@ -41,7 +41,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
[common] [common]
; for release_version use max. 10 chars total, use any decimal format like "a.b.c" ; for release_version use max. 10 chars total, use any decimal format like "a.b.c"
release_version = 1.7.71 release_version = 1.7.8
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 3 debug_level = 3

View File

@ -77,16 +77,24 @@ void gps_storelocation(gpsStatus_t &gps_store) {
// store current GPS timedate in struct // store current GPS timedate in struct
void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store) { void IRAM_ATTR gps_storetime(gpsStatus_t &gps_store) {
gps_store.time_age = gps.time.age(); if (gps.time.isUpdated() && gps.date.isValid() && (gps.time.age() < 1000)) {
if (gps.time.isValid() && gps.date.isValid() && (gps_store.time_age < 1000)) { /* nmea telegram serial delay compensation; not sure if we need this?
if (gps.time.age() > nmea_txDelay_ms)
gps_store.timedate.Second = gps.time.second() + 1;
else
gps_store.timedate.Second = gps.time.second();
*/
gps_store.timedate.Second = gps.time.second();
gps_store.timedate.Minute = gps.time.minute();
gps_store.timedate.Hour = gps.time.hour();
gps_store.timedate.Day = gps.date.day();
gps_store.timedate.Month = gps.date.month();
gps_store.timedate.Year = gps_store.timedate.Year =
CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h CalendarYrToTm(gps.date.year()); // year offset from 1970 in microTime.h
gps_store.timedate.Month = gps.date.month();
gps_store.timedate.Day = gps.date.day();
gps_store.timedate.Hour = gps.time.hour();
gps_store.timedate.Minute = gps.time.minute();
gps_store.timedate.Second = gps.time.second();
} else } else
gps_store.timedate = {0}; gps_store.timedate = {0};
} }
@ -96,11 +104,8 @@ time_t get_gpstime(gpsStatus_t value) {
time_t t = timeIsValid(makeTime(value.timedate)); time_t t = timeIsValid(makeTime(value.timedate));
// if (t)
// t = value.time_age > nmea_txDelay_ms ? t : t - 1;
// show NMEA data in verbose mode, useful for debugging GPS // show NMEA data in verbose mode, useful for debugging GPS
ESP_LOGV( ESP_LOGD(
TAG, TAG,
"GPS time: %d | GPS NMEA data: passed %d / failed: %d / with fix: %d", t, "GPS time: %d | GPS NMEA data: passed %d / failed: %d / with fix: %d", t,
gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix()); gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix());

View File

@ -31,7 +31,7 @@ time_t timeProvider(void) {
time_t t = 0; time_t t = 0;
#if (HAS_GPS) #if (HAS_GPS)
// fetch recent time from last NEMA record // fetch recent time from last NMEA record
t = get_gpstime(gps_pps_status); t = get_gpstime(gps_pps_status);
if (t) { if (t) {
#ifdef HAS_RTC #ifdef HAS_RTC
@ -140,9 +140,11 @@ void IRAM_ATTR CLOCKIRQ(void) {
SyncToPPS(); // advance systime, see microTime.h SyncToPPS(); // advance systime, see microTime.h
// store recent gps time, if we have gps // store recent gps time, and try to get gps time if time is not synced
#if (HAS_GPS) #if (HAS_GPS)
gps_storetime(gps_pps_status); gps_storetime(gps_pps_status);
if (timeSource == _unsynced)
timeSync();
#endif #endif
// advance wall clock, if we have // advance wall clock, if we have