network abstraction

This commit is contained in:
Wolfgang Hottgenroth 2021-02-16 11:26:49 +01:00
parent af21143561
commit 37767dc81d
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -5,15 +5,32 @@
#include <sinkStruct.h>
#include <config.h>
#define NETWORK_LAN 1
#define NETWORK_WiFi 2
#define NETWORK_GSM 3
#if NETWORK == NETWORK_LAN
#include <wizHelper.h>
#include <wizchip_conf.h>
#include <socket.h>
#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) {