浏览代码

fix sntp set

balbekova 7 年之前
父节点
当前提交
0cf6097fd8
共有 6 个文件被更改,包括 47 次插入20 次删除
  1. 6 0
      modules/Ethernet/sntp.c
  2. 17 12
      modules/HTTP_Server/http_server.c
  3. 4 2
      modules/parameters.c
  4. 15 6
      modules/settings_api.c
  5. 2 0
      modules/settings_api.h
  6. 3 0
      user/main.c

+ 6 - 0
modules/Ethernet/sntp.c

@@ -5,6 +5,8 @@
 #include <string.h>
 #include <time.h>
 
+#include "semphr.h"
+
 #ifdef PRINTF_STDLIB
 #include <stdio.h>
 #endif
@@ -46,6 +48,8 @@ static int port = 123;
   */
 extern SETTINGS_t sSettings;
 
+extern SemaphoreHandle_t flash_mutex;
+
 /**
   * @brief  Разовая синхронизация времени при старте контроллера
   */
@@ -166,11 +170,13 @@ static void recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
 	/* Сохраним время последней синхронизации */
 	TM_RTC_GetDateTime(&data, TM_RTC_Format_BIN);
 		
+	xSemaphoreTake(flash_mutex, portMAX_DELAY);
 	memset(sSettings.sSNTP.data, 0, sizeof(sSettings.sSNTP.data));
 	
 	sprintf(sSettings.sSNTP.data, "%02d.%02d.%02d %02d:%02d:%02d", 
 			data.date, data.month, data.year,
 			data.hours, data.minutes, data.seconds);
+	xSemaphoreGive(flash_mutex);
 	
     timeout = VALID_TIMEOUT;
     

+ 17 - 12
modules/HTTP_Server/http_server.c

@@ -795,24 +795,28 @@ void HTTP_SetSettings(char *buf, uint16_t lenBuf)
 
   // Параметры даты и времени
   GetParamValue(buf, "ntp=", value, &valueLen);
-  SetSntpStateStr(value);
 
   if (strncmp(value, "1", 1) == 0)  // Если ntp on устанавливаем параметры
   {
+    memset(str, 0, len);
+    GetParamValue(buf, "ntpservip=", str, &valueLen);
+    SetSntpServerIpStr(str);
+    SetSntpStateStr(value);
     memset(value, 0, len);
-
-    GetParamValue(buf, "ntpservip=", value, &valueLen);
-    SetSntpServerIpStr(value);
-    memset(value, 0, len);
+    memset(str, 0, len);
   }
   else if (strncmp(value, "0", 1) == 0){
+	  SetSntpStateStr(value);
+	  memset(value, 0, len);
       GetParamValue(buf, "date=", value, &valueLen);
       SetDateStr(value);
       memset(value, 0, len);
       GetParamValue(buf, "time=", value, &valueLen);
+      memset(str, 0, len);
       url_decode(str, sizeof(str), value);
       SetTimeStr(str);
       memset(value, 0, len);
+      memset(str, 0, len);
   }
 
   GetParamValue(buf, "utc=", value, &valueLen);
@@ -1150,13 +1154,13 @@ int HTTP_ConfirmWebPwd(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *l
 			  if(cnt_err_psw < 4)
 				  strcat(bufOut,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"3; url=/rslogin.html\" /></head><center><h2>Не правильный логин или пароль</h2></center></html>");
 			  else
-				  strcat(bufOut,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"3; url=/rslogin.html\" /></head><center><h2>Вход заблокирован!</h2></center></head><center><h2>Повторите попытку через 15 минут</h2></center></html>");
+				  strcat(bufOut,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"3; url=/rslogin.html\" /></head><center><h2>Вход заблокирован!</h2></center></head><center><h2>Повторите попытку через 1 минуту</h2></center></html>");
 		  }
 		  else{
 			  if(cnt_err_psw < 4)
 				  strcat(bufOut,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"3; url=/login.html\" /></head><center><h2>Не правильный логин или пароль</h2></center></html>");
 			  else
-				  strcat(bufOut,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"3; url=/login.html\" /></head><center><h2>Вход заблокирован!</h2></center></head><center><h2>Повторите попытку через 15 минут</h2></center></html>");
+				  strcat(bufOut,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"3; url=/login.html\" /></head><center><h2>Вход заблокирован!</h2></center></head><center><h2>Повторите попытку через 1 минуту</h2></center></html>");
 		  }
 		  *lenBufOut = strlen(bufOut);
 		  return SEND_REQUIRED_NO;
@@ -1662,6 +1666,7 @@ void ssl_server_read(void)
 
         // Read decrypted application data
         ret = ssl_read(&ssl, (unsigned char*)receiveBuf, receivedBufLen);
+        printf("receive %s \r\n", receiveBuf);
 
         if(ret == POLARSSL_ERR_NET_WANT_READ || ret == POLARSSL_ERR_NET_WANT_WRITE)
             continue;
@@ -1679,14 +1684,14 @@ void ssl_server_read(void)
             break;
 
             default:
-                //printf("\n\r ssl_read returned %d\n", ret);
+                printf("\n\r ssl_read returned %d\n", ret);
             break;
             }
             break;
         }
         receivedBufLen = ret;
         // Display the length of read data
-        //printf("\n\r Successfully read %d bytes from client \n\r",len);
+        printf("\n\r Successfully read %d bytes from client \n\r",receivedBufLen);
     }while(0);
 }
 
@@ -1826,7 +1831,7 @@ void ssl_server(void *pvParameters)
         //memcpy(receiveBuf, p->payload , receivedBufLen);
 
         receiveBuf[receivedBufLen] = '\0';
-        // printf("receive %s \r\n", receiveBuf);
+       //  printf("receive %s \r\n", receiveBuf);
         // Get cookie "uname" value 
         CookiePtr = strstr(receiveBuf, "uname=");
         strncpy(CookieBuf, CookiePtr, 50);
@@ -2111,7 +2116,7 @@ void ssl_server(void *pvParameters)
 					for(i  = TotalData; i < size; i ++)
 					{
 						ssl_server_read();
-						strncat(sendBuf,  DataOffset, receivedBufLen);
+						strncat(sendBuf,  receiveBuf, receivedBufLen);
 						TotalData += receivedBufLen;
 					}
 
@@ -2120,7 +2125,7 @@ void ssl_server(void *pvParameters)
                     {
                        DBG printf("State: Received %d bytes\r\n", (int)TotalData);
 
-                       DBG printf("receive %s /r/n", sendBuf);
+                      //  printf("receive %s \r\n", sendBuf);
                         strncat(sendBuf,  " ", 1);
                         HTTP_SetSettings(sendBuf, strlen(sendBuf));
 

+ 4 - 2
modules/parameters.c

@@ -980,7 +980,7 @@ void SetTimeStr(char *str)
 
 // ************************************************************************** //
 //                             Параметры SNTP
-
+#ifndef BT6702_SERVICE
 /**
   * @brief  Состояние SNTP
   */
@@ -990,7 +990,8 @@ void SetSntpStateStr(char *str)
   if (strncmp(str, "1", 1) == 0){
 	sSettings.sSNTP.sntpEnable = true;
 	if(old_sntpEnable != sSettings.sSNTP.sntpEnable){
-		SNTP_Enable(sSettings.sSNTP.sntpEnable);
+		SNTP_Init();
+		//vTaskDelay(7000);
 		SNTP_Poll();
 	}
   }
@@ -999,6 +1000,7 @@ void SetSntpStateStr(char *str)
 	SNTP_Enable(sSettings.sSNTP.sntpEnable);
   }
 }
+#endif
 
 /**
   * @brief  IP адрес SNTP сервера

+ 15 - 6
modules/settings_api.c

@@ -22,6 +22,7 @@
 
 #include "FreeRTOS.h"
 #include "task.h"
+#include "semphr.h"
 #include "main.h"
 
 #include <string.h>
@@ -39,6 +40,9 @@
 #define DEVICE_MAC "00-00-00-00-00-03"
 #endif
 
+
+SemaphoreHandle_t flash_mutex;
+
 /**
   * @brief  Флаг подтверждения новых сетевых параметров пользователем
   */  
@@ -118,7 +122,7 @@ void SETTINGS_SetInfoDef(void)
 	  strcpy(sSettings.sInfo.productionData, "09.07.2017");
 	  strcpy(sSettings.sInfo.mac, DEVICE_MAC);
 	  strcpy(sSettings.sInfo.serialNumber, DEVICE_SERIAL);
-	  strcpy(sSettings.sFlags.testState, "T2READY");
+	  strcpy(sSettings.sFlags.testState, "T2OK");
 
   }
   strcpy(sSettings.sInfo.comments, "");
@@ -146,13 +150,13 @@ void SETTINGS_SetServiceDef(void)
         case 0:
             sSettings.sAuth[user_id].level = ADMIN;
             strcpy(sSettings.sAuth[user_id].login, "admin");
-            strcpy(sSettings.sAuth[user_id].password, "12345");
+            strcpy(sSettings.sAuth[user_id].password, "R04ekR4MP2");
             break;
         case 1:
         default:
         	sSettings.sAuth[user_id].level = USER;
             strcpy(sSettings.sAuth[user_id].login, "user");
-            strcpy(sSettings.sAuth[user_id].password, "1234");
+            strcpy(sSettings.sAuth[user_id].password, "R03ekR4MP2");
             break;
         }
     }
@@ -186,11 +190,11 @@ void SETTINGS_SetINOUTSDef(void)
 void SETTINGS_SetRADIUSDef(void)
 {
   sSettings.sRADIUS.Auth_enable = true;
-  sSettings.sRADIUS.RDSEnable = true;
+  sSettings.sRADIUS.RDSEnable = false;
   strcpy(sSettings.sRADIUS.ServerIP, "0.0.0.0");
   sSettings.sRADIUS.port = 1812;
   sSettings.sRADIUS.key_access = 123;
-  strcpy(sSettings.sRADIUS.rds_password, "R04ekR4MP2");
+  strcpy(sSettings.sRADIUS.rds_password, "R02ekR4MP2");
 }
   
 /**
@@ -274,10 +278,12 @@ void SETTINGS_SetDefaultDebug(void)
   */
 void SETTINGS_Save(void)
 {
+	xSemaphoreTake(flash_mutex, portMAX_DELAY);
   /* Calc critical section CRC and store to the settings structure */
   sSettings.CritSecCRC = SETTINGS_GetCritSecCRC();
 
   SETTINGS_WriteToFlash((uint8_t*)&sSettings, sizeof(sSettings));
+  xSemaphoreGive(flash_mutex);
 }
 
 /**
@@ -496,5 +502,8 @@ void SETTINGS_SetDHCPOn(void)
   sSettings.sWebParams.dhcpEnable = 1;
 }
 
-
+void init_settings(void)
+{
+	  flash_mutex = xSemaphoreCreateMutex();
+}
 /********************************* (C) ROTEK **********************************/

+ 2 - 0
modules/settings_api.h

@@ -328,6 +328,8 @@ void SETTINGS_SetT2OK(void);
   */
 void SETTINGS_SetDHCPOn(void);
 
+void init_settings(void);
+
 #endif /* #ifndef SETTINGS_API_H */
 
 /********************************* (C) РОТЕК **********************************/

+ 3 - 0
user/main.c

@@ -3,6 +3,7 @@
 #include "FreeRTOS.h"
 #include "task.h"
 #include "common_config.h"
+#include "settings_api.h"
 
 #include "gpio.h"
 
@@ -54,6 +55,8 @@ int main()
 	//log_test();
 	//spi_flash_test();
 //  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
+
+	init_settings();
   
   xTaskCreate( InitTask, "InitTask", 1000, NULL, tskIDLE_PRIORITY, NULL);