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 fe0668e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion 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 @@ -172,14 +173,20 @@ bool TimeServiceClass::sync()
} else {
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
utc = getRemoteTime();
<<<<<<< HEAD
#elif defined(HAS_LORA)
/* Just keep incrementing stored RTC value*/
=======
#endif
#ifdef HAS_LORA
/* Just keep incrementing stored RTC value starting from EPOCH_AT_COMPILE_TIME */
>>>>>>> 012b73e6 (TimeService: improve debug prints and comments)
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 +314,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 +324,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 fe0668e

Please sign in to comment.