Fix for NTP update time. Minor refactoring.

This commit is contained in:
2024-04-04 21:37:57 +02:00
parent 73b390d8cd
commit eb4341e05b
3 changed files with 8 additions and 8 deletions

View File

@@ -69,7 +69,7 @@ NtpUpdateState TimeManager::ntp_time_update()
}
// Check if it is time for a NTP sync.
if ((_tm_state != TM_INITIAL_SYNC) && (_tm_state != TM_RETRY_SYNC) && ((system_get_time() - _ntp_sync_timestamp_us) <= (_ntp_update_period_s * 1000000)))
if ((_tm_state != TM_INITIAL_SYNC) && (_tm_state != TM_RETRY_SYNC) && (((system_get_time() - _ntp_sync_timestamp_us) / 1000000) <= _ntp_update_period_s))
{
return NTP_UPDATE_TOO_EARLY;
}
@@ -175,7 +175,7 @@ void TimeManager::_set_up_timer_isr(void)
if (ITimer.attachInterruptInterval(PERIOD_CLOCK_UPDATE_US, TimerHandler))
{
_tm_state = TM_NORMAL;
logger.log_string(String("Timer ISR was initialized!"));
logger.log_string(String("Timer ISR was attached successfully!"));
}
else
{
@@ -195,7 +195,7 @@ void TimeManager::_set_up_ntp(void)
// set up NTP server and timezone at init
configTime(_tz, _ntp_server);
_tm_state = TM_INITIAL_SYNC;
logger.log_string(String("NTP server was initialized!"));
logger.log_string(String("NTP server connection was set up successfully!"));
}
else
{

View File

@@ -251,9 +251,6 @@ void loop()
if ((current_time_us - last_heartbeat_us) >= PERIOD_HEARTBEAT_US)
{
send_heartbeat(); // send heartbeat update
tm_mgr.log_time(); // TODO rm
last_heartbeat_us = system_get_time();
delay(10);
}
@@ -283,7 +280,10 @@ void loop()
if ((current_time_us - last_time_update_us) >= PERIOD_TIME_UPDATE_US)
{
tm_mgr.ntp_time_update(); // NTP time update
if (tm_mgr.ntp_time_update() == NTP_UPDATE_OK) // NTP time update
{
logger.log_string("NTP sync successful!");
}
if (tm_mgr.ntp_update_failed_prolonged() == true)
{