zhunk 1 anno fa
parent
commit
63509294f7

+ 93 - 0
Application_CBD/applications/control.c

@@ -1842,6 +1842,7 @@ void HardWare_Check(uint8_t boot)
     }
 
 }
+#if 0
 //工作状态检测
 void WorkCheck(void)
 {
@@ -2033,6 +2034,98 @@ void WorkCheck(void)
     device_status.work_status = 0;
     rt_thread_delay(1000);
 }
+#endif
+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)
+    {
+        if(device_status.timeSwitch == 1) // 时控模式
+        {
+            LOG_I("***********时控*****************");
+            if(device_status.startBar == device_status.stopBar)
+            {
+                // 开始结束时间相同则24小时模式
+                device_status.work_status = 1;
+                rt_thread_delay(10000);
+                continue;
+            }
+
+            time_t now;
+            time(&now);
+            struct tm now_tm = *localtime(&now);
+            rt_uint32_t curr_sec = now_tm.tm_hour*3600 + now_tm.tm_min*60 + now_tm.tm_sec;
+            rt_uint32_t start_sec = device_status.startBar * 3600;
+            rt_uint32_t end_sec = device_status.stopBar * 3600;
+
+            // 修复跨天判断逻辑
+            if (start_sec < end_sec)
+            {
+                // 不跨天模式
+                device_status.work_status = (curr_sec >= start_sec && curr_sec < end_sec) ? 1 : 0;
+            }
+            else
+            {
+                // 跨天模式
+                device_status.work_status = (curr_sec >= start_sec || curr_sec < end_sec) ? 1 : 0;
+            }
+
+            LOG_I("时控模式:状态[%s] 当前时间:%02d:%02d:%02d 设置:%02d:00-%02d:00",
+                  device_status.work_status ? "工作" : "待机",
+                  now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec,
+                  device_status.startBar, device_status.stopBar);
+            rt_thread_delay(10000);
+        }
+        else // 光控模式
+        {
+            LOG_I("光控定时模式!");
+            if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
+            {
+                device_status.light_over_tim--;
+                light_timeout = 3600;  // 重置超时计数器
+                device_status.work_status = 1;
+                LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
+            }
+            else
+            {
+                // 仅在白天递减超时计数器
+                if(device_status.sun_status == 1 && light_timeout > 0) {
+                    light_timeout--;
+                }
+
+                device_status.work_status = 0;
+
+                //没有在测试并且没有在自检
+                if(device_status.test_flag==0 && device_status.selfcheck_ws==0)
+                {
+                    ctr_lamp(OFF,1);
+                }
+
+                // 连续1小时白天后重置
+                if(light_timeout == 0) {
+                    device_status.light_over_tim = 0;
+                    light_timeout = 3600;  // 重置防止负数
+                }
+
+                // 白天且倒计时结束:重置夜晚时长
+                if(device_status.light_over_tim == 0 &&
+                   device_status.sun_status == 1)
+                {
+                    device_status.light_over_tim = device_status.sunBar * 3600;
+                }
+            }
+        }
+        rt_thread_delay(1000);
+    }
+
+    // 异常状态处理
+    device_status.work_status = 0;
+    rt_thread_delay(1000);
+}
+
 
 void WorkTask_BZY(void)
 {

+ 1 - 0
Application_CBD/applications/control.h

@@ -122,6 +122,7 @@ typedef struct  _packed
     #if BOOT_ERR == 1
     uint8_t gps_inuse;
     uint8_t gps_view;
+    uint8_t _lamp;
     #endif
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间

+ 4 - 16
Application_CBD/applications/dtu_uart2.c

@@ -709,16 +709,16 @@ char * makeJson()
         LOG_I("Current is:%d",atoi(device_status.power));
         if(atoi(device_status.power)>10)        //过滤电流检测芯片损坏导致电流直为0 的异常
         {
-            device_status.lamp_status = 1;
+            device_status._lamp = 1;
         }
         #endif
         if(device_status.version_type==11||device_status.version_type==12)
         {
-            device_status.lamp_status = 0;
+            device_status._lamp = 0;
         }
     }
     else {
-        device_status.lamp_status = 0;
+        device_status._lamp = 0;
     }
 
 
@@ -853,7 +853,7 @@ char * makeJson()
         rt_sprintf(utos, "%d",device_status.bat_status);
         cJSON_AddStringToObject(pSubJson,"batStatus",utos);
         //灯管状态
-        rt_sprintf(utos, "%d",device_status.lamp_status);
+        rt_sprintf(utos, "%d",device_status._lamp);
         cJSON_AddStringToObject(pSubJson,"lamp",utos);
         //上仓门状态 1-打开,0-关闭-(通道) 打开为落虫,关闭为排水
         rt_sprintf(utos, "%d",device_status.up_status);
@@ -1501,18 +1501,6 @@ int parseDtu(char *json_string)
                         struct timeval tv;
                         gettimeofday(&tv,NULL);
                         LOG_I("系统当前时间戳:%d",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)