timesync.cpp: comments updated

This commit is contained in:
Verkehrsrot 2019-08-06 11:37:58 +02:00
parent 64222bf8b3
commit b2ef9249da

View File

@ -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, void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec,
timesource_t mytimesource) { timesource_t mytimesource) {
// increment t_sec only if t_msec > 1000
time_t time_to_set = (time_t)(t_sec + 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)) { 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) { if (t_msec % 1000) {
time_to_set++; time_to_set++;
vTaskDelay(pdMS_TO_TICKS(1000 - t_msec % 1000)); 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, ESP_LOGD(TAG, "[%0.3f] UTC epoch time: %d.%03d sec", millis() / 1000.0,
time_to_set, t_msec % 1000); 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 #ifdef HAS_RTC
if ((mytimesource == _gps) || (mytimesource == _lora)) if ((mytimesource == _gps) || (mytimesource == _lora))
set_rtctime(time_to_set); set_rtctime(time_to_set);
#endif #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) #if (!defined GPS_INT && !defined RTC_INT)
timerWrite(ppsIRQ, 0); // reset pps timer timerWrite(ppsIRQ, 0); // reset pps timer
CLOCKIRQ(); // fire clock pps, this advances time 1 sec CLOCKIRQ(); // fire clock pps, this advances time 1 sec