|
@@ -2,6 +2,9 @@
|
|
#include "rtc.h"
|
|
#include "rtc.h"
|
|
#include "settings_api.h"
|
|
#include "settings_api.h"
|
|
|
|
|
|
|
|
+#include "tcpip.h"
|
|
|
|
+#include "udp.h"
|
|
|
|
+
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <time.h>
|
|
|
|
|
|
@@ -38,12 +41,12 @@ struct sntp_packet
|
|
uint64_t rec;
|
|
uint64_t rec;
|
|
uint64_t xmt;
|
|
uint64_t xmt;
|
|
};
|
|
};
|
|
-/*
|
|
|
|
|
|
+
|
|
static unsigned int timeout;
|
|
static unsigned int timeout;
|
|
-static struct udp_pcb* upcb;
|
|
|
|
-static struct ip_addr server;
|
|
|
|
|
|
+static struct udp_pcb* upcb;
|
|
|
|
+static struct ip4_addr server;
|
|
static int port = 123;
|
|
static int port = 123;
|
|
-*/
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @brief Общая структура настроек
|
|
* @brief Общая структура настроек
|
|
*/
|
|
*/
|
|
@@ -52,7 +55,7 @@ extern SETTINGS_t sSettings;
|
|
/**
|
|
/**
|
|
* @brief Разовая синхронизация времени при старте контроллера
|
|
* @brief Разовая синхронизация времени при старте контроллера
|
|
*/
|
|
*/
|
|
-//extern TaskHandle_t xHandleSntpOnceSinhro;
|
|
|
|
|
|
+extern TaskHandle_t xHandleSntpOnceSinhro;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @brief Синхронизация времени единоразово при включении контроллера
|
|
* @brief Синхронизация времени единоразово при включении контроллера
|
|
@@ -65,15 +68,15 @@ void vTaskOnceSynchro(void *arg)
|
|
if (sSettings.sSNTP.sntpEnable)
|
|
if (sSettings.sSNTP.sntpEnable)
|
|
{
|
|
{
|
|
vTaskDelay(7000);
|
|
vTaskDelay(7000);
|
|
- //SNTP_Poll();
|
|
|
|
|
|
+ SNTP_Poll();
|
|
//printf("Once time sinhro\n\r");
|
|
//printf("Once time sinhro\n\r");
|
|
- //vTaskDelete(xHandleSntpOnceSinhro);
|
|
|
|
|
|
+ vTaskDelete(xHandleSntpOnceSinhro);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
vTaskDelay(7000);
|
|
vTaskDelay(7000);
|
|
}
|
|
}
|
|
- //vTaskDelete(xHandleSntpOnceSinhro);
|
|
|
|
|
|
+ vTaskDelete(xHandleSntpOnceSinhro);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -91,7 +94,7 @@ void vTaskPeriodicSynchro(void *arg)
|
|
for (;;)
|
|
for (;;)
|
|
{
|
|
{
|
|
vTaskDelay(10000);
|
|
vTaskDelay(10000);
|
|
-#if 0
|
|
|
|
|
|
+
|
|
if (sSettings.sSNTP.sntpEnable)
|
|
if (sSettings.sSNTP.sntpEnable)
|
|
{
|
|
{
|
|
TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
|
|
TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
|
|
@@ -107,7 +110,6 @@ void vTaskPeriodicSynchro(void *arg)
|
|
if (data.hours > 1)
|
|
if (data.hours > 1)
|
|
fSinhro = 0;
|
|
fSinhro = 0;
|
|
}
|
|
}
|
|
-#endif
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -133,14 +135,12 @@ void vTaskSntp(void *arg)
|
|
*/
|
|
*/
|
|
void SNTP_Init(void)
|
|
void SNTP_Init(void)
|
|
{
|
|
{
|
|
-
|
|
|
|
-
|
|
|
|
- //SNTP_SetServerAddr(sSettings.sSNTP.ip);
|
|
|
|
- //SNTP_Enable(sSettings.sSNTP.sntpEnable);
|
|
|
|
|
|
+ SNTP_SetServerAddr(sSettings.sSNTP.ip);
|
|
|
|
+ SNTP_Enable(sSettings.sSNTP.sntpEnable);
|
|
}
|
|
}
|
|
-#if 0
|
|
|
|
|
|
+
|
|
static void recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
|
static void recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
|
- struct ip_addr *addr, u16_t port)
|
|
|
|
|
|
+ const ip_addr_t *addr, u16_t port)
|
|
{
|
|
{
|
|
time_t t;
|
|
time_t t;
|
|
int utcSec = 0;
|
|
int utcSec = 0;
|
|
@@ -185,9 +185,9 @@ static void recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
|
out:
|
|
out:
|
|
pbuf_free(p);
|
|
pbuf_free(p);
|
|
}
|
|
}
|
|
-#endif
|
|
|
|
|
|
+
|
|
void SNTP_Enable(bool enable)
|
|
void SNTP_Enable(bool enable)
|
|
-{ /*
|
|
|
|
|
|
+{
|
|
if (enable)
|
|
if (enable)
|
|
{
|
|
{
|
|
if (upcb == 0)
|
|
if (upcb == 0)
|
|
@@ -216,27 +216,25 @@ void SNTP_Enable(bool enable)
|
|
udp_remove(upcb);
|
|
udp_remove(upcb);
|
|
upcb = 0;
|
|
upcb = 0;
|
|
}
|
|
}
|
|
-*/
|
|
|
|
}
|
|
}
|
|
|
|
|
|
bool SNTP_IsEnabled(void)
|
|
bool SNTP_IsEnabled(void)
|
|
{
|
|
{
|
|
- //return upcb != 0;
|
|
|
|
|
|
+ return upcb != 0;
|
|
}
|
|
}
|
|
|
|
|
|
void SNTP_SetServerAddr(char *addr)
|
|
void SNTP_SetServerAddr(char *addr)
|
|
{
|
|
{
|
|
- //server.addr = ipaddr_addr(addr);
|
|
|
|
|
|
+ server.addr = ipaddr_addr(addr);
|
|
}
|
|
}
|
|
|
|
|
|
int sntp_getserverport(void)
|
|
int sntp_getserverport(void)
|
|
{
|
|
{
|
|
- //return port;
|
|
|
|
|
|
+ return port;
|
|
}
|
|
}
|
|
|
|
|
|
static void send_request(void)
|
|
static void send_request(void)
|
|
{
|
|
{
|
|
-#if 0
|
|
|
|
struct sntp_packet packet;
|
|
struct sntp_packet packet;
|
|
struct pbuf* psend;
|
|
struct pbuf* psend;
|
|
memset(&packet, 0, sizeof(packet));
|
|
memset(&packet, 0, sizeof(packet));
|
|
@@ -249,11 +247,10 @@ static void send_request(void)
|
|
timeout = (udp_sendto(upcb, psend, &server, port) == ERR_OK) ? SENT_TIMEOUT : SENDFAIL_TIMEOUT;
|
|
timeout = (udp_sendto(upcb, psend, &server, port) == ERR_OK) ? SENT_TIMEOUT : SENDFAIL_TIMEOUT;
|
|
pbuf_free(psend);
|
|
pbuf_free(psend);
|
|
}
|
|
}
|
|
-#endif
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void SNTP_Poll(void)
|
|
void SNTP_Poll(void)
|
|
-{ /*
|
|
|
|
|
|
+{
|
|
if (upcb)
|
|
if (upcb)
|
|
- send_request();*/
|
|
|
|
|
|
+ send_request();
|
|
}
|
|
}
|