nal
This commit is contained in:
parent
5b7248a8a5
commit
d29529bf8a
@ -87,7 +87,8 @@ Core/Src/system_stm32f1xx.c
|
|||||||
ifeq ($(NETWORK), 1)
|
ifeq ($(NETWORK), 1)
|
||||||
C_SOURCES += \
|
C_SOURCES += \
|
||||||
User/Src/ports.c \
|
User/Src/ports.c \
|
||||||
User/Src/wizHelper.c
|
User/Src/wizHelper.c \
|
||||||
|
User/Src/networkAbstractionLayer_lan.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
10
cube/User/Inc/networkAbstractionLayer_impl.h
Normal file
10
cube/User/Inc/networkAbstractionLayer_impl.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _NETWORK_ABSTRACTION_LAYER_IMPL_H_
|
||||||
|
#define _NETWORK_ABSTRACTION_LAYER_IMPL_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint64_t networkSntpQuery();
|
||||||
|
int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufLen);
|
||||||
|
void networkImplInit();
|
||||||
|
|
||||||
|
#endif /* _NETWORK_ABSTRACTION_LAYER_IMPL_H_ */
|
@ -5,18 +5,7 @@
|
|||||||
#include <sinkStruct.h>
|
#include <sinkStruct.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <networkAbstractionLayer_impl.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;
|
const uint16_t SINK_PORT = 20169;
|
||||||
@ -25,12 +14,6 @@ static t_seconds seconds = { .seconds = 0, .missedUpdates = 0, .valid = false };
|
|||||||
static t_configBlock *config;
|
static t_configBlock *config;
|
||||||
|
|
||||||
|
|
||||||
#if NETWORK == NETWORK_LAN
|
|
||||||
static uint64_t networkSntpQuery() {
|
|
||||||
return wizSntpQuery();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void networkSecondsHandler(void *handle) {
|
static void networkSecondsHandler(void *handle) {
|
||||||
static bool tryAgain = false;
|
static bool tryAgain = false;
|
||||||
|
|
||||||
@ -75,45 +58,12 @@ t_seconds* networkGetSeconds() {
|
|||||||
return &seconds;
|
return &seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#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");
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
coloredMsg(LOG_BLUE, "nus, sink server at %d.%d.%d.%d", sinkAddr[0], sinkAddr[1], sinkAddr[2], sinkAddr[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket(SINK_SOCK, Sn_MR_UDP, SINK_PORT, 0);
|
|
||||||
uint8_t sockState = getSn_SR(SINK_SOCK);
|
|
||||||
if (sockState == SOCK_UDP) {
|
|
||||||
sendto(SINK_SOCK, buf, bufLen, sinkAddr, SINK_PORT);
|
|
||||||
coloredMsg(LOG_BLUE, "nus, sent");
|
|
||||||
} else {
|
|
||||||
coloredMsg(LOG_BLUE, "nus, socket in unexpected state: %d", sockState);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(SINK_SOCK);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
int8_t networkSendMinuteBuffer(t_minuteBuffer *minuteBuffer) {
|
int8_t networkSendMinuteBuffer(t_minuteBuffer *minuteBuffer) {
|
||||||
return networkUdpSend(config->sinkServer, SINK_PORT, minuteBuffer->b, sizeof(minuteBuffer->b));
|
return networkUdpSend(config->sinkServer, SINK_PORT, minuteBuffer->b, sizeof(minuteBuffer->b));
|
||||||
}
|
}
|
||||||
|
|
||||||
void networkInit() {
|
void networkInit() {
|
||||||
#if NETWORK == NETWORK_LAN
|
networkImplInit();
|
||||||
wizInit();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
config = getConfig();
|
config = getConfig();
|
||||||
schAdd(networkSecondsHandler, NULL, 0, 1000);
|
schAdd(networkSecondsHandler, NULL, 0, 1000);
|
||||||
|
43
cube/User/Src/networkAbstractionLayer_lan.c
Normal file
43
cube/User/Src/networkAbstractionLayer_lan.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <networkAbstractionLayer_impl.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
|
#include <wizHelper.h>
|
||||||
|
#include <wizchip_conf.h>
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t networkSntpQuery() {
|
||||||
|
return wizSntpQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern uint8_t SINK_SOCK;
|
||||||
|
|
||||||
|
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");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
coloredMsg(LOG_BLUE, "nus, sink server at %d.%d.%d.%d", sinkAddr[0], sinkAddr[1], sinkAddr[2], sinkAddr[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket(SINK_SOCK, Sn_MR_UDP, port, 0);
|
||||||
|
uint8_t sockState = getSn_SR(SINK_SOCK);
|
||||||
|
if (sockState == SOCK_UDP) {
|
||||||
|
sendto(SINK_SOCK, buf, bufLen, sinkAddr, port);
|
||||||
|
coloredMsg(LOG_BLUE, "nus, sent");
|
||||||
|
} else {
|
||||||
|
coloredMsg(LOG_BLUE, "nus, socket in unexpected state: %d", sockState);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(SINK_SOCK);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void networkImplInit() {
|
||||||
|
wizInit();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user