From b3b19084806472a5aea9a26453bf0d8373ecb416 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 16 Feb 2021 11:04:45 +0100 Subject: [PATCH] missedUpdates --- cube/User/Inc/networkAbstractionLayer.h | 1 + cube/User/Src/networkAbstractionLayer.c | 6 +++++- cube/User/Src/wizHelper.c | 4 ---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cube/User/Inc/networkAbstractionLayer.h b/cube/User/Inc/networkAbstractionLayer.h index fc5611b..762dc2b 100644 --- a/cube/User/Inc/networkAbstractionLayer.h +++ b/cube/User/Inc/networkAbstractionLayer.h @@ -6,6 +6,7 @@ typedef struct { uint64_t seconds; + uint32_t missedUpdates; bool valid; } t_seconds; diff --git a/cube/User/Src/networkAbstractionLayer.c b/cube/User/Src/networkAbstractionLayer.c index 0be10f4..79d3162 100644 --- a/cube/User/Src/networkAbstractionLayer.c +++ b/cube/User/Src/networkAbstractionLayer.c @@ -6,7 +6,7 @@ #include -static t_seconds seconds = { .seconds = 0, .valid = false }; +static t_seconds seconds = { .seconds = 0, .missedUpdates = 0, .valid = false }; static void networkSecondsHandler(void *handle) { @@ -20,15 +20,18 @@ static void networkSecondsHandler(void *handle) { if (tmpSeconds != 0) { coloredMsg(LOG_YELLOW, "nsh, success, time is %lu", tmpSeconds); seconds.seconds = tmpSeconds; + seconds.missedUpdates = 0; seconds.valid = true; } else { coloredMsg(LOG_YELLOW, "nsh, failed"); + seconds.missedUpdates += 1; } } else if (tryAgain || ((seconds.seconds % 3600) == 0)) { coloredMsg(LOG_YELLOW, "nsh, periodically querying time"); uint64_t tmpSeconds = wizSntpQuery(); if (tmpSeconds != 0) { coloredMsg(LOG_YELLOW, "nsh, success, network time is %lu", tmpSeconds); + seconds.missedUpdates = 0; tryAgain = false; if (seconds.seconds != tmpSeconds) { coloredMsg(LOG_YELLOW, "nsh, local time updated"); @@ -38,6 +41,7 @@ static void networkSecondsHandler(void *handle) { } } else { coloredMsg(LOG_YELLOW, "nsh, failed, trying again ..."); + seconds.missedUpdates += 1; tryAgain = true; } } diff --git a/cube/User/Src/wizHelper.c b/cube/User/Src/wizHelper.c index 2face62..bb2e0ca 100644 --- a/cube/User/Src/wizHelper.c +++ b/cube/User/Src/wizHelper.c @@ -136,7 +136,6 @@ bool wizDnsQuery(char *name, uint8_t *ip) { uint64_t wizSntpQuery() { bool success = false; uint64_t seconds = 0; - static uint32_t missedUpdates = 0; if (networkAvailable) { coloredMsg(LOG_BLUE, "wizsq, about to call SNTP"); @@ -150,7 +149,6 @@ uint64_t wizSntpQuery() { int8_t res = SNTP_run(&curTime); if (res == 1) { seconds = curTime.seconds - UNIX_NTP_EPOCH_DIFF; - missedUpdates = 0; updated = true; success = true; coloredMsg(LOG_BLUE, "wizsq, curTime: %lu", seconds); @@ -160,11 +158,9 @@ uint64_t wizSntpQuery() { if (! updated) { coloredMsg(LOG_BLUE, "wizsq, time update failed"); - missedUpdates += 1; } } else { coloredMsg(LOG_BLUE, "wizsq, error when querying ntp server name"); - missedUpdates += 1; } }