zhunk 1 год назад
Родитель
Сommit
c0b85097f7

+ 4 - 1
Application_cbd_apm32f1/applications/control.c

@@ -1594,6 +1594,7 @@ void HardWare_Check(uint8_t boot)
 //工作状态检测
 void WorkCheck(void)
 {
+    static rt_uint32_t light_timeout = 3600;
     //雨控检测,温控检测,电池电压检测
     while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
     {
@@ -1749,7 +1750,7 @@ void WorkCheck(void)
                 {
 
                     device_status.light_over_tim--;
-
+                    light_timeout = 3600;
                     #if LAMP_EN == 1
                     Led_Check(device_status.sunBar);
                     #else
@@ -1759,6 +1760,7 @@ void WorkCheck(void)
                 }
                 else
                 {
+                    light_timeout --;
                     //没有在测试并且没有在自检
                     if(device_status.test_flag==0&&device_status.selfcheck_ws==0)
                     {
@@ -1769,6 +1771,7 @@ void WorkCheck(void)
                         #endif
                     }
                     device_status.work_status = 0;
+                    if(light_timeout==0) device_status.light_over_tim = 0;  //持续1小时白天,清除光控计时,20250519
                     if(device_status.light_over_tim==0&&device_status.sun_status==1) device_status.light_over_tim = device_status.sunBar * 3600;
                     LOG_I("光控中,白天:%d!!!",device_status.sun_status);
                 }

+ 3 - 3
Application_cbd_apm32f1/applications/control.h

@@ -15,15 +15,15 @@
 #include <rtdevice.h>
 //定制相关//////////////////////////////////////////////////////
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
-#define PCB_V1           1
+#define PCB_V1           0
 #define SENSOR_EN        1              //温湿度:0关闭,1打开
 ////////////////////////////////////////////////////////////////
 #if LAMP_EN == 1
     #define VERSION_HK          "1.(3ledV9).41(HK)"      //4.0海康-三色光源
     #define VERSION_HK_2000W    "1.3led.40(2000W)"       //水稻
 #else
-    #define VERSION_HK          "2.4.41(HK)"            //4.0海康-1200W
-    #define VERSION_HK_2000W    "2.11.4(2000W)"         //4.0水稻
+    #define VERSION_HK          "2.5.41(HK)"            //4.0海康-1200W
+    #define VERSION_HK_2000W    "2.12.4(2000W)"         //4.0水稻
 #endif
 
 #define VERSION_ZP          "1.45.1(ZP)"            //1.0转盘

+ 71 - 0
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -382,6 +382,52 @@ static void dtu_thread_entry_recv(void *parameter)
 //    }
 }
 
+// 解析时间戳并返回一个tm结构体
+struct tm* parseTimestamp(const char *timestamp) {
+    if (strlen(timestamp) != 14) {
+        LOG_E("Invalid timestamp length: %s", timestamp);
+        return NULL;
+    }
+    LOG_I("parseTimestamp:%s",timestamp);
+    int year, month, day, hour, minute, second;
+    sscanf(timestamp, "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
+    //校验时间日期
+    if(year<2024||month>12||day>31||hour>23||minute>59||second>59) return NULL;
+
+    struct tm* tm_time = (struct tm*)malloc(sizeof(struct tm));
+    tm_time->tm_year = year - 1900; // tm_year is years since 1900
+    tm_time->tm_mon = month - 1;   // tm_mon is 0-11
+    tm_time->tm_mday = day;
+    tm_time->tm_hour = hour;
+    tm_time->tm_min = minute;
+    tm_time->tm_sec = second;
+
+    // Check if the time is valid
+    if (mktime(tm_time) == -1) {
+        free(tm_time);
+        LOG_E("Failed to parse time: %s", timestamp);
+        return NULL;
+    }
+
+    return tm_time;
+}
+
+void setSystemTime(struct tm *timeinfo) {
+    time_t t = mktime(timeinfo);
+    if (t == -1) {
+        LOG_E("Failed to convert time to time_t");
+        return;
+    }
+    // Convert the time_t value to a timeval structure
+    struct timeval tv;
+    tv.tv_sec = t;
+    tv.tv_usec = 0; // Assuming no microseconds in the timestamp
+    if (settimeofday(&tv, NULL) == -1) {
+        LOG_E("Failed to set system time!");
+        return;
+    }
+    LOG_I("System time set successfully!");
+}
 
 // 函数定义:判断数组中是否有大于 100 的元素
 int hasElementGreaterThan400(uint16_t arr[], int size) {
@@ -1724,6 +1770,31 @@ int parseDtu(char *json_string)
                   //if(device_status.sensor_485_sta!=0) return 0;
                   hum = cJSON_GetObjectItem(item_ext,"new_hum");
                   tmp = cJSON_GetObjectItem(item_ext,"new_tem");
+                  cJSON* stamp_server = cJSON_GetObjectItem(item_ext,"stamp");
+                  if(stamp_server!=NULL)
+                  {
+                      LOG_I("解析到温湿度stamp:%s",stamp_server->valuestring);
+                      struct tm *tm_time = parseTimestamp(stamp_server->valuestring);
+                      time_t timestamp;
+                      timestamp = mktime(tm_time);
+                      LOG_I("服务器时间戳:{}",timestamp);
+                      //获取当前系统时间戳
+                      struct timeval tv;
+                      gettimeofday(&tv,NULL);
+                      LOG_I("系统当前时间戳:{}",tv.tv_sec);
+                      time_t timestamp_diff;
+                      if(timestamp>tv.tv_sec)
+                      {
+                         timestamp_diff = timestamp - tv.tv_sec;
+                      }else
+                      {
+                         timestamp_diff = tv.tv_sec - timestamp;
+                      }
+                      if (tm_time != NULL&&timestamp_diff>60) {
+                         setSystemTime(tm_time);
+                         free(tm_time); // Free the allocated memory
+                      }
+                  }
                   if(hum!=NULL&&tmp!=NULL)
                   {
                       //先判断是否是空字符再判断数值是否合理

+ 9 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,12 @@
+# 2025-05-19 更新说明
+#define VERSION_HK          "2.5.41(HK)"            //4.0海康-1200W
+#define VERSION_HK_2000W    "2.12.4(2000W)"         //4.0水稻
+#define VERSION_ZP          "1.45.1(ZP)"            //1.0转盘
+#define VERSION_GK          "1.41.1(GK)"            //1.0高空
+#define VERSION_V5          "2.0.5(HK)"             //5.0
+1. 修复光控运行逻辑错误:在光控时间未结束提前天亮会导致第二天工作时间异常;
+	解决措施:持续超过1小时触发光控,清除光控计时
+2. 解析服务器下发的温湿度中的时间
 # 2025-05-16 更新说明
 1. 修复欠压状态并且RTU程序未运行时 会关断RTU电源问题