From ccf9e80c01d02efa982d96eeb22d63fc29b55110 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 3 May 2021 19:37:39 +0200 Subject: [PATCH] add COMPILETIME macro --- src/rtctime.cpp | 2 +- src/timekeeper.cpp | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/rtctime.cpp b/src/rtctime.cpp index 29ad18c6..cb87c9de 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -32,7 +32,7 @@ uint8_t rtc_init(void) { if (!Rtc.IsDateTimeValid() || !timeIsValid(t)) { ESP_LOGW(TAG, "RTC has no recent time, setting to compiled time"); Rtc.SetDateTime( - RtcDateTime(compiledUTC() - SECS_YR_2000)); // epoch -> sec2000 + RtcDateTime(_COMPILETIME - SECS_YR_2000)); // epoch -> sec2000 } #endif diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 45f0d153..885716d5 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -8,6 +8,8 @@ #endif #endif +#define _COMPILETIME myTZ.toUTC(RtcDateTime(__DATE__, __TIME__).Epoch32Time()) + // Local logging tag static const char TAG[] = __FILE__; @@ -121,12 +123,11 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, _seconds(), mytimesource); } else { timesyncer.attach(TIME_SYNC_INTERVAL_RETRY * 60, setTimeSyncIRQ); - time_t unix_sec_at_compilation = compiledUTC(); ESP_LOGD(TAG, "[%0.3f] Failed to synchronise time from source %c | unix sec " "obtained from source: %d | unix sec at program compilation: %d", _seconds(), timeSetSymbols[mytimesource], time_to_set, - unix_sec_at_compilation); + _COMPILETIME); } } @@ -215,13 +216,7 @@ void IRAM_ATTR CLOCKIRQ(void) { // helper function to check plausibility of a time time_t timeIsValid(time_t const t) { // is it a time in the past? we use compile date to guess - return (t >= compiledUTC() ? t : 0); -} - -// helper function to convert compile time to UTC time -time_t compiledUTC(void) { - static time_t t = myTZ.toUTC(RtcDateTime(__DATE__, __TIME__).Epoch32Time()); - return t; + return (t >= _COMPILETIME ? t : 0); } // helper function to calculate serial transmit time