瀏覽代碼

Правка netcong sntp udp_netsettings

TelenkovDmitry 7 年之前
父節點
當前提交
2bc148825a
共有 6 個文件被更改,包括 31 次插入32 次删除
  1. 1 1
      config/common_config.h
  2. 1 0
      modules/Ethernet/lwipopts.h
  3. 1 1
      modules/Ethernet/netconf.c
  4. 23 26
      modules/Ethernet/sntp.c
  5. 2 1
      modules/Ethernet/udp_netsetting.c
  6. 3 3
      user/init_task.c

+ 1 - 1
config/common_config.h

@@ -115,7 +115,7 @@
   * @brief  SNMP протокол
   */
 #if defined HARDWARE_BT6702
-#define SNMP_ENABLE
+//#define SNMP_ENABLE
 #endif
 
 /**

+ 1 - 0
modules/Ethernet/lwipopts.h

@@ -141,6 +141,7 @@ a lot of data that needs to be copied, this should be set high. */
 #define LWIP_UDP                1
 #define UDP_TTL                 255
 
+#define LWIP_SO_RCVTIMEO        1 // Эта опция необходима для netconn_set_recvtimeout в модуле udp_netsetting.c
 
 /* ---------- Statistics options ---------- */
 #define LWIP_STATS 0

+ 1 - 1
modules/Ethernet/netconf.c

@@ -271,7 +271,7 @@ void LwIP_DHCP_task(void * pvParameters)
       default: break;
     }
 
-    vTaskDelay(2500);
+    vTaskDelay(1500);
   }   
 }
 

+ 23 - 26
modules/Ethernet/sntp.c

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

+ 2 - 1
modules/Ethernet/udp_netsetting.c

@@ -9,6 +9,7 @@
 #include "task.h"
 
 #include "lwip/api.h"
+
 #include "udp_netsetting.h"
 #include "stm32_uid.h"
 #include "parameters.h"
@@ -215,7 +216,7 @@ bool http_server_serve(struct netconn *conn)
     u16_t buflen;
     bool flag = false;
 
-    //netconn_set_recvtimeout(conn, RCV_TIMEOUT);
+    netconn_set_recvtimeout(conn, RCV_TIMEOUT);
     res = netconn_recv(conn, &inbuf);
 
   //  DBG printf("recv failed %d\n", res);

+ 3 - 3
user/init_task.c

@@ -141,7 +141,7 @@ void InitTask(void *params)
 #define SSL_TASK_PRIO   ( configMAX_PRIORITIES - 3 )
   xTaskCreate(ssl_server, "SSL", 10*configMINIMAL_STACK_SIZE, NULL, SSL_TASK_PRIO, NULL); 
 #endif
-#if 0  
+
 #ifdef SNMP_ENABLE
 
   SNMP_Init();
@@ -164,9 +164,9 @@ void InitTask(void *params)
 				 NULL, tskIDLE_PRIORITY, NULL);
 #endif      
 // -----------------------------------------------------------------------------  
-#endif
+
 	 /* UDP for net settings */
-	  //UDP_netsetting_init();
+	  UDP_netsetting_init();
 // Тестирование
     
   // Тест таблицы трапов