Skip to content

Commit

Permalink
TimeService: improve debug prints and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Sep 16, 2024
1 parent cf78d4e commit 278f653
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utility/time/TimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ unsigned long TimeServiceClass::getTime()
unsigned long const current_tick = millis();
bool const is_ntp_sync_timeout = (current_tick - _last_sync_tick) > _sync_interval_ms;
if(!_is_rtc_configured || is_ntp_sync_timeout) {
/* Try to sync time from NTP or connection handler */
sync();
}

Expand Down Expand Up @@ -173,13 +174,13 @@ bool TimeServiceClass::sync()
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
utc = getRemoteTime();
#elif defined(HAS_LORA)
/* Just keep incrementing stored RTC value*/
/* Just keep incrementing stored RTC value starting from EPOCH_AT_COMPILE_TIME */
utc = getRTC();
#endif
}

if(isTimeValid(utc)) {
DEBUG_DEBUG("TimeServiceClass::%s Drift: %d RTC value: %u", __FUNCTION__, getRTC() - utc, utc);
DEBUG_DEBUG("TimeServiceClass::%s done. Drift: %d RTC value: %u", __FUNCTION__, getRTC() - utc, utc);
setRTC(utc);
_last_sync_tick = millis();
_is_rtc_configured = true;
Expand Down Expand Up @@ -307,6 +308,7 @@ unsigned long TimeServiceClass::getRemoteTime()
return ntp_time;
}
}
DEBUG_WARNING("TimeServiceClass::%s cannot get time from NTP, fallback on connection handler", __FUNCTION__);
#endif /* HAS_TCP */

/* As fallback if NTP request fails try to obtain the
Expand All @@ -316,6 +318,7 @@ unsigned long TimeServiceClass::getRemoteTime()
if(isTimeValid(connection_time)) {
return connection_time;
}
DEBUG_WARNING("TimeServiceClass::%s cannot get time from connection handler", __FUNCTION__);
}

/* Return known invalid value because we are not connected */
Expand Down

0 comments on commit 278f653

Please sign in to comment.