From b2ef9249da3efd08ff2e51e873a32edc7c296f26 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 6 Aug 2019 11:37:58 +0200 Subject: [PATCH] timesync.cpp: comments updated --- src/timesync.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/timesync.cpp b/src/timesync.cpp index 1d3034c3..ef50041d 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -211,11 +211,14 @@ int recv_timesync_ans(uint8_t seq_no, uint8_t buf[], uint8_t buf_len) { void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource) { + // increment t_sec only if t_msec > 1000 time_t time_to_set = (time_t)(t_sec + t_msec / 1000); + // do we have a valid time? if (timeIsValid(time_to_set)) { - // wait until top of second with millisecond precision + // if we have msec fraction, then wait until top of second with + // millisecond precision if (t_msec % 1000) { time_to_set++; vTaskDelay(pdMS_TO_TICKS(1000 - t_msec % 1000)); @@ -224,13 +227,14 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, ESP_LOGD(TAG, "[%0.3f] UTC epoch time: %d.%03d sec", millis() / 1000.0, time_to_set, t_msec % 1000); -// if we got a timesource, set RTC time and RTC_INT pulse on top of second +// if we have got an external timesource, set RTC time and shift RTC_INT pulse +// to top of second #ifdef HAS_RTC if ((mytimesource == _gps) || (mytimesource == _lora)) set_rtctime(time_to_set); #endif -// sync pps timer to top of second +// if we have a software pps timer, shift it to top of second #if (!defined GPS_INT && !defined RTC_INT) timerWrite(ppsIRQ, 0); // reset pps timer CLOCKIRQ(); // fire clock pps, this advances time 1 sec