timekeeper fixes
This commit is contained in:
parent
a676658977
commit
c20ef02ce8
@ -5,7 +5,7 @@
|
||||
#include "cyclic.h"
|
||||
|
||||
extern uint8_t DisplayState;
|
||||
extern char timeSource;
|
||||
extern timesource_t timeSource;
|
||||
|
||||
extern HAS_DISPLAY u8x8;
|
||||
|
||||
|
@ -97,6 +97,7 @@ typedef struct {
|
||||
} bmeStatus_t;
|
||||
|
||||
enum sendprio_t { prio_low, prio_normal, prio_high };
|
||||
enum timesource_t { _gps, _rtc, _lora, _unsynced };
|
||||
|
||||
extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
|
||||
extern std::array<uint64_t, 0xff>::iterator it;
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "dcf77.h"
|
||||
#endif
|
||||
|
||||
enum timesources { _gps, _rtc, _lora, _unsynced };
|
||||
extern const char timeSetSymbols[];
|
||||
|
||||
void IRAM_ATTR CLOCKIRQ(void);
|
||||
void clock_init(void);
|
||||
@ -21,9 +21,10 @@ void clock_loop(void *pvParameters);
|
||||
void time_sync(void);
|
||||
void timepulse_start(void);
|
||||
uint8_t wait_for_pulse(void);
|
||||
uint8_t syncTime(time_t const t, uint8_t const caller);
|
||||
uint8_t syncTime(time_t const t, timesource_t const caller);
|
||||
uint8_t timepulse_init(void);
|
||||
uint8_t TimeIsValid(time_t const t);
|
||||
time_t syncProvider_CB(void);
|
||||
time_t compiledUTC(void);
|
||||
time_t tmConvert(uint16_t YYYY, uint8_t MM, uint8_t DD, uint8_t hh,
|
||||
uint8_t mm, uint8_t ss);
|
||||
|
@ -46,7 +46,7 @@ const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
uint8_t DisplayState = 0;
|
||||
char timeSource = '?';
|
||||
timesource_t timeSource = _unsynced;
|
||||
|
||||
// helper function, prints a hex key on display
|
||||
void DisplayKey(const uint8_t *key, uint8_t len, bool lsb) {
|
||||
@ -217,7 +217,7 @@ void refreshtheDisplay() {
|
||||
u8x8.printf("%-16s", display_line6);
|
||||
#else // we want a systime display instead LoRa status
|
||||
t = myTZ.toLocal(now());
|
||||
timeState = TimePulseTick ? ' ' : timeSource;
|
||||
timeState = TimePulseTick ? ' ' : timeSetSymbols[timeSource];
|
||||
TimePulseTick = false;
|
||||
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t),
|
||||
timeState, day(t), printmonth[month(t)]);
|
||||
|
@ -361,10 +361,11 @@ void setup() {
|
||||
ESP_LOGI(TAG, "Starting Timekeeper...");
|
||||
assert(timepulse_init()); // setup timepulse
|
||||
timepulse_start();
|
||||
time_sync(); // sync time
|
||||
#ifdef TIME_SYNC_INTERVAL
|
||||
setSyncInterval(TIME_SYNC_INTERVAL * 60); // controls timeStatus()
|
||||
setSyncInterval(TIME_SYNC_INTERVAL * 60); // controls timeStatus() via Time.h
|
||||
setSyncProvider(syncProvider_CB); // is called by Time.h
|
||||
#endif
|
||||
time_sync(); // sync time
|
||||
|
||||
// start wifi in monitor mode and start channel rotation timer
|
||||
ESP_LOGI(TAG, "Starting Wifi...");
|
||||
|
@ -66,8 +66,8 @@
|
||||
#define RESPONSE_TIMEOUT_MS 60000 // firmware binary server connection timeout [milliseconds]
|
||||
|
||||
// settings for syncing time of node with external time source
|
||||
#define TIME_SYNC_INTERVAL 2 // sync time attempt each .. minutes from time source (GPS/LORA), comment out means [default = 5]
|
||||
#define TIME_SYNC_LORA 1 // use LORA network as time source, comment out means off [default = off]
|
||||
#define TIME_SYNC_INTERVAL 60 // sync time attempt each .. minutes from time source (GPS/LORA) [default = 60], comment out means off
|
||||
//#define TIME_SYNC_LORA 1 // use LORA network as time source, comment out means off [default = off]
|
||||
|
||||
// time zone, see https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino
|
||||
#define DAYLIGHT_TIME {"CEST", Last, Sun, Mar, 2, 120} // Central European Summer Time
|
||||
|
@ -3,6 +3,9 @@
|
||||
// Local logging tag
|
||||
static const char TAG[] = "main";
|
||||
|
||||
// symbol to display current time source
|
||||
const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
|
||||
|
||||
void time_sync() {
|
||||
// synchonization of systime with external time source (GPS/LORA)
|
||||
// frequently called from cyclic.cpp
|
||||
@ -31,20 +34,16 @@ void time_sync() {
|
||||
#endif // TIME_SYNC_INTERVAL
|
||||
} // time_sync()
|
||||
|
||||
// helper function to sync time on start of next second
|
||||
uint8_t syncTime(time_t const t, uint8_t const caller) {
|
||||
|
||||
// symbol to display current time source
|
||||
const char timeSetSymbols[] = {'G', 'R', 'L', '?'};
|
||||
|
||||
// sync time on start of next second
|
||||
uint8_t syncTime(time_t const t, timesource_t const caller) {
|
||||
if (TimeIsValid(t)) {
|
||||
uint8_t const TimeIsPulseSynced =
|
||||
wait_for_pulse(); // wait for next 1pps timepulse
|
||||
setTime(t); // sync time and reset timeStatus() to timeSet
|
||||
adjustTime(1); // forward time to next second
|
||||
timeSource = timeSetSymbols[caller];
|
||||
ESP_LOGD(TAG, "Time source %c set time to %02d:%02d:%02d", timeSource,
|
||||
hour(t), minute(t), second(t));
|
||||
timeSource = caller;
|
||||
ESP_LOGD(TAG, "Time source %c set time to %02d:%02d:%02d",
|
||||
timeSetSymbols[timeSource], hour(t), minute(t), second(t));
|
||||
#ifdef HAS_RTC
|
||||
if ((TimeIsPulseSynced) && (caller != _rtc))
|
||||
set_rtctime(now());
|
||||
@ -53,11 +52,17 @@ uint8_t syncTime(time_t const t, uint8_t const caller) {
|
||||
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Time source %c sync attempt failed", timeSetSymbols[caller]);
|
||||
timeSource = timeSetSymbols[_unsynced];
|
||||
timeSource = _unsynced;
|
||||
return 0; // failure
|
||||
}
|
||||
} // syncTime()
|
||||
|
||||
// callback function called by Time.h in interval set in main.cpp
|
||||
time_t syncProvider_CB(void) {
|
||||
timeSource = _unsynced;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// helper function to sync moment on timepulse
|
||||
uint8_t wait_for_pulse(void) {
|
||||
// sync on top of next second with 1pps timepulse
|
||||
@ -204,7 +209,7 @@ void clock_loop(void *pvParameters) { // ClockTask
|
||||
xTaskNotifyWait(0x00, ULONG_MAX, &wakeTime,
|
||||
portMAX_DELAY); // wait for timepulse
|
||||
|
||||
if (timeStatus() != timeSet) // no confident time -> no output to clock
|
||||
if (timeStatus() == timeNotSet) // no confident time -> no output to clock
|
||||
continue;
|
||||
|
||||
t = now(); // payload to send to clock
|
||||
|
Loading…
Reference in New Issue
Block a user