start
This commit is contained in:
@ -10,7 +10,6 @@ int wizInit();
|
|||||||
bool isNetworkAvailable();
|
bool isNetworkAvailable();
|
||||||
uint8_t* wizGetIPAddress();
|
uint8_t* wizGetIPAddress();
|
||||||
bool wizDnsQuery(char *name, uint8_t *ip);
|
bool wizDnsQuery(char *name, uint8_t *ip);
|
||||||
uint64_t wizSntpQuery();
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _WIZHELPER_H_
|
#endif // _WIZHELPER_H_
|
||||||
|
@ -1,14 +1,54 @@
|
|||||||
#include <networkAbstractionLayer_impl.h>
|
#include <networkAbstractionLayer_impl.h>
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
|
#include <PontCoopScheduler.h>
|
||||||
|
|
||||||
#include <wizHelper.h>
|
#include <wizHelper.h>
|
||||||
#include <wizchip_conf.h>
|
#include <wizchip_conf.h>
|
||||||
#include <socket.h>
|
#include <socket.h>
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
|
||||||
|
static t_configBlock *config;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t sntpBuffer[MAX_SNTP_BUF_SIZE];
|
||||||
|
const uint64_t UNIX_NTP_EPOCH_DIFF = 2208988800;
|
||||||
|
extern const uint8_t SNTP_SOCK;
|
||||||
|
|
||||||
|
|
||||||
uint64_t networkSntpQuery() {
|
uint64_t networkSntpQuery() {
|
||||||
return wizSntpQuery();
|
uint64_t seconds = 0;
|
||||||
|
|
||||||
|
if (isNetworkAvailable()) {
|
||||||
|
coloredMsg(LOG_BLUE, "wizsq, about to call SNTP");
|
||||||
|
|
||||||
|
uint8_t ntpServer[4];
|
||||||
|
if (wizDnsQuery(config->ntpServer, ntpServer)) {
|
||||||
|
SNTP_init(SNTP_SOCK, ntpServer, 0, sntpBuffer);
|
||||||
|
uint16_t cycles = 0;
|
||||||
|
uint32_t startTime = HAL_GetTick();
|
||||||
|
while (1) {
|
||||||
|
cycles += 1;
|
||||||
|
datetime curTime;
|
||||||
|
if (1 == SNTP_run(&curTime)) {
|
||||||
|
seconds = curTime.seconds - UNIX_NTP_EPOCH_DIFF;
|
||||||
|
coloredMsg(LOG_BLUE, "wizsq, cycles: %u, curTime: %lu", cycles, seconds);
|
||||||
|
uint32_t stopTime = HAL_GetTick();
|
||||||
|
coloredMsg(LOG_BLUE, "wizsq, duration: %u ms", stopTime - startTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (seconds == 0) {
|
||||||
|
coloredMsg(LOG_BLUE, "wizsq, time update failed");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
coloredMsg(LOG_BLUE, "wizsq, error when querying ntp server name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,5 +79,6 @@ int8_t networkUdpSend(char *hostname, uint16_t port, uint8_t *buf, uint16_t bufL
|
|||||||
}
|
}
|
||||||
|
|
||||||
void networkImplInit() {
|
void networkImplInit() {
|
||||||
|
config = getConfig();
|
||||||
wizInit();
|
wizInit();
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,9 @@ static uint8_t dhcpBuffer[DHCP_BUFFER_SIZE];
|
|||||||
static uint8_t dnsBuffer[DNS_BUFFER_SIZE];
|
static uint8_t dnsBuffer[DNS_BUFFER_SIZE];
|
||||||
|
|
||||||
|
|
||||||
static uint8_t sntpBuffer[MAX_SNTP_BUF_SIZE];
|
|
||||||
const uint64_t UNIX_NTP_EPOCH_DIFF = 2208988800;
|
|
||||||
|
|
||||||
|
|
||||||
extern const uint8_t DHCP_SOCK;
|
extern const uint8_t DHCP_SOCK;
|
||||||
extern const uint8_t DNS_SOCK;
|
extern const uint8_t DNS_SOCK;
|
||||||
extern const uint8_t SNTP_SOCK;
|
|
||||||
|
|
||||||
|
|
||||||
static bool networkAvailable = false;
|
static bool networkAvailable = false;
|
||||||
@ -133,40 +129,6 @@ bool wizDnsQuery(char *name, uint8_t *ip) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t wizSntpQuery() {
|
|
||||||
uint64_t seconds = 0;
|
|
||||||
|
|
||||||
if (networkAvailable) {
|
|
||||||
coloredMsg(LOG_BLUE, "wizsq, about to call SNTP");
|
|
||||||
|
|
||||||
uint8_t ntpServer[4];
|
|
||||||
if (wizDnsQuery(config->ntpServer, ntpServer)) {
|
|
||||||
SNTP_init(SNTP_SOCK, ntpServer, 0, sntpBuffer);
|
|
||||||
uint16_t cycles = 0;
|
|
||||||
uint32_t startTime = HAL_GetTick();
|
|
||||||
while (1) {
|
|
||||||
cycles += 1;
|
|
||||||
datetime curTime;
|
|
||||||
if (1 == SNTP_run(&curTime)) {
|
|
||||||
seconds = curTime.seconds - UNIX_NTP_EPOCH_DIFF;
|
|
||||||
coloredMsg(LOG_BLUE, "wizsq, cycles: %u, curTime: %lu", cycles, seconds);
|
|
||||||
uint32_t stopTime = HAL_GetTick();
|
|
||||||
coloredMsg(LOG_BLUE, "wizsq, duration: %u ms", stopTime - startTime);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seconds == 0) {
|
|
||||||
coloredMsg(LOG_BLUE, "wizsq, time update failed");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
coloredMsg(LOG_BLUE, "wizsq, error when querying ntp server name");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wizPhyLinkHandler(void *handle) {
|
static void wizPhyLinkHandler(void *handle) {
|
||||||
// this handler is anyhow called with a 1s period, so we reuse it for the DNS timer
|
// this handler is anyhow called with a 1s period, so we reuse it for the DNS timer
|
||||||
DNS_time_handler();
|
DNS_time_handler();
|
||||||
|
Reference in New Issue
Block a user