From 6e73dccd66ce7d97cc2cb58dece59957d614539b Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 1 Mar 2021 11:16:54 +0100 Subject: [PATCH] changes --- cube/User/Inc/networkAbstractionLayer_impl.h | 3 ++- cube/User/Inc/wizHelper.h | 2 +- cube/User/Src/networkAbstractionLayer.c | 3 ++- cube/User/Src/networkAbstractionLayer_lan.c | 5 +++++ cube/User/Src/wizHelper.c | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cube/User/Inc/networkAbstractionLayer_impl.h b/cube/User/Inc/networkAbstractionLayer_impl.h index 2a4df57..704af5a 100644 --- a/cube/User/Inc/networkAbstractionLayer_impl.h +++ b/cube/User/Inc/networkAbstractionLayer_impl.h @@ -2,10 +2,11 @@ #define _NETWORK_ABSTRACTION_LAYER_IMPL_H_ #include +#include uint64_t networkSntpQuery(); int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufLen); void networkImplInit(); - +bool isNetworkAvailable(); #endif /* _NETWORK_ABSTRACTION_LAYER_IMPL_H_ */ diff --git a/cube/User/Inc/wizHelper.h b/cube/User/Inc/wizHelper.h index bcd7a4b..0441688 100644 --- a/cube/User/Inc/wizHelper.h +++ b/cube/User/Inc/wizHelper.h @@ -7,7 +7,7 @@ int wizInit(); -bool isNetworkAvailable(); +bool wizIsNetworkAvailable(); uint8_t* wizGetIPAddress(); bool wizDnsQuery(char *name, uint8_t *ip); diff --git a/cube/User/Src/networkAbstractionLayer.c b/cube/User/Src/networkAbstractionLayer.c index d9a81d9..0d34d31 100644 --- a/cube/User/Src/networkAbstractionLayer.c +++ b/cube/User/Src/networkAbstractionLayer.c @@ -14,12 +14,13 @@ static t_seconds seconds = { .seconds = 0, .missedUpdates = 0, .valid = false }; static t_configBlock *config; + static void networkSecondsHandler(void *handle) { static bool tryAgain = false; seconds.seconds += 1; - if (! seconds.valid) { + if (! seconds.valid && isNetworkAvailable()) { coloredMsg(LOG_YELLOW, "nsh, initially querying time"); uint64_t tmpSeconds = networkSntpQuery(); if (tmpSeconds != 0) { diff --git a/cube/User/Src/networkAbstractionLayer_lan.c b/cube/User/Src/networkAbstractionLayer_lan.c index 0342a4c..86a2648 100644 --- a/cube/User/Src/networkAbstractionLayer_lan.c +++ b/cube/User/Src/networkAbstractionLayer_lan.c @@ -90,6 +90,7 @@ void networkSntpEngine(void *handle) { if (sockState == SOCK_UDP) { memset(&(localHandle->ntpMsg), 0, sizeof(localHandle->ntpMsg)); localHandle->ntpMsg.li_vn_mode = SEND_LI_VN_MODE; + localHandle->ntpMsg.xmt_l = 1; sendto(SNTP_SOCK, (uint8_t*)(&(localHandle->ntpMsg)), sizeof(localHandle->ntpMsg), localHandle->ntpAddr, NTP_PORT); coloredMsg(LOG_BLUE, "nes, sent"); @@ -209,6 +210,10 @@ int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufL return 1; } +bool isNetworkAvailable() { + return wizIsNetworkAvailable(); +} + void networkImplInit() { config = getConfig(); wizInit(); diff --git a/cube/User/Src/wizHelper.c b/cube/User/Src/wizHelper.c index 1b9292a..281ed96 100644 --- a/cube/User/Src/wizHelper.c +++ b/cube/User/Src/wizHelper.c @@ -33,7 +33,7 @@ extern const uint8_t DNS_SOCK; static bool networkAvailable = false; -bool isNetworkAvailable() { +bool wizIsNetworkAvailable() { return networkAvailable; }