From 37767dc81d95741a2b8ff507d00d0bcbe6a49335 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 16 Feb 2021 11:26:49 +0100 Subject: [PATCH] network abstraction --- cube/User/Src/networkAbstractionLayer.c | 29 ++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cube/User/Src/networkAbstractionLayer.c b/cube/User/Src/networkAbstractionLayer.c index 7eb350c..94289ab 100644 --- a/cube/User/Src/networkAbstractionLayer.c +++ b/cube/User/Src/networkAbstractionLayer.c @@ -5,15 +5,32 @@ #include #include + + +#define NETWORK_LAN 1 +#define NETWORK_WiFi 2 +#define NETWORK_GSM 3 + +#if NETWORK == NETWORK_LAN #include #include #include +#endif + +const uint16_t SINK_PORT = 20169; + static t_seconds seconds = { .seconds = 0, .missedUpdates = 0, .valid = false }; static t_configBlock *config; +#if NETWORK == NETWORK_LAN +static uint64_t networkSntpQuery() { + return wizSntpQuery(); +} +#endif + static void networkSecondsHandler(void *handle) { static bool tryAgain = false; @@ -21,7 +38,7 @@ static void networkSecondsHandler(void *handle) { if (! seconds.valid) { coloredMsg(LOG_YELLOW, "nsh, initially querying time"); - uint64_t tmpSeconds = wizSntpQuery(); + uint64_t tmpSeconds = networkSntpQuery(); if (tmpSeconds != 0) { coloredMsg(LOG_YELLOW, "nsh, success, time is %lu", tmpSeconds); seconds.seconds = tmpSeconds; @@ -33,7 +50,7 @@ static void networkSecondsHandler(void *handle) { } } else if (tryAgain || ((seconds.seconds % 3600) == 0)) { coloredMsg(LOG_YELLOW, "nsh, periodically querying time"); - uint64_t tmpSeconds = wizSntpQuery(); + uint64_t tmpSeconds = networkSntpQuery(); if (tmpSeconds != 0) { coloredMsg(LOG_YELLOW, "nsh, success, network time is %lu", tmpSeconds); seconds.missedUpdates = 0; @@ -59,10 +76,11 @@ t_seconds* networkGetSeconds() { } -extern uint8_t SINK_SOCK; -const uint16_t SINK_PORT = 20169; -int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufLen) { +#if NETWORK == NETWORK_LAN +extern uint8_t SINK_SOCK; + +static int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufLen) { uint8_t sinkAddr[4]; if (! wizDnsQuery(hostname, sinkAddr)) { coloredMsg(LOG_BLUE, "nus, failed to resolve sink server name"); @@ -85,6 +103,7 @@ int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufL return 1; } +#endif int8_t networkSendMinuteBuffer(t_minuteBuffer *minuteBuffer) {