nal
This commit is contained in:
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();
|
||||
}
|
Reference in New Issue
Block a user