|
|
@@ -1591,10 +1591,160 @@ 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)
|
|
|
+ {
|
|
|
+ if(device_status.timeSwitch == 1) // 时控模式
|
|
|
+ {
|
|
|
+ LOG_I("***********时控*****************");
|
|
|
+ if(device_status.startBar == device_status.stopBar &&
|
|
|
+ device_status.startBar == 0)
|
|
|
+ {
|
|
|
+ // 24小时模式处理
|
|
|
+ #if LAMP_EN == 1
|
|
|
+ device_status.lamp_status = (device_status.sun_status == 0) ? 1 : 0;
|
|
|
+ device_status.lamp1_status = 0;
|
|
|
+ device_status.lamp2_status = 0;
|
|
|
+ #endif
|
|
|
+ device_status.work_status = 1;
|
|
|
+ rt_thread_delay(1000);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ time_t now;
|
|
|
+ time(&now);
|
|
|
+ struct tm now_tm = *localtime(&now);
|
|
|
+ struct tm start_tm = *localtime(&now);
|
|
|
+ struct tm end_tm = *localtime(&now);
|
|
|
+
|
|
|
+ // 设置开始时间
|
|
|
+ now_tm.tm_hour = now_tm.tm_hour-8;
|
|
|
+ time_t now_time = mktime(&now_tm);
|
|
|
+
|
|
|
+ // 设置开始时间
|
|
|
+ start_tm.tm_hour = device_status.startBar-8;
|
|
|
+ start_tm.tm_min = 0;
|
|
|
+ start_tm.tm_sec = 0;
|
|
|
+ time_t start_time = mktime(&start_tm);
|
|
|
+
|
|
|
+ // 设置结束时间(自动处理跨天)
|
|
|
+ end_tm.tm_hour = device_status.stopBar-8;
|
|
|
+ end_tm.tm_min = 0;
|
|
|
+ end_tm.tm_sec = 0;
|
|
|
+ if(device_status.startBar >= device_status.stopBar) {
|
|
|
+ end_tm.tm_mday += 1; // 结束时间+1天
|
|
|
+ }
|
|
|
+ time_t end_time = mktime(&end_tm);
|
|
|
+
|
|
|
+ // 工作时间判断
|
|
|
+ if(now_time >= start_time && now_time < end_time)
|
|
|
+ {
|
|
|
+ device_status.work_status = 1;
|
|
|
+ LOG_I("时控工作模式:现在:%d- 开始:%d-结束:%d",now_time,start_time,end_time);
|
|
|
+ rt_thread_delay(10000);
|
|
|
+ #if LAMP_EN == 1
|
|
|
+ // 统一灯控制逻辑
|
|
|
+ int hours = now_tm.tm_hour;
|
|
|
+ if (hours >= 20 && hours < 21) {
|
|
|
+ device_status.lamp_status = 1;
|
|
|
+ device_status.lamp1_status = 0;
|
|
|
+ device_status.lamp2_status = 0;
|
|
|
+ } else if (hours >= 21 && hours < 22) {
|
|
|
+ device_status.lamp_status = 0;
|
|
|
+ device_status.lamp1_status = 1;
|
|
|
+ device_status.lamp2_status = 0;
|
|
|
+ } else if (hours >= 22 && hours < 23) {
|
|
|
+ device_status.lamp_status = 0;
|
|
|
+ device_status.lamp1_status = 0;
|
|
|
+ device_status.lamp2_status = 1;
|
|
|
+ } else {
|
|
|
+ // 非20-23点默认状态
|
|
|
+ device_status.lamp_status = 1;
|
|
|
+ device_status.lamp1_status = 0;
|
|
|
+ device_status.lamp2_status = 0;
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ device_status.work_status = 0;
|
|
|
+ LOG_I("时控待机模式:现在:%d- 开始:%d-结束:%d",now_time,start_time,end_time);
|
|
|
+ rt_thread_delay(10000);
|
|
|
+ #if LAMP_EN == 1
|
|
|
+ // 非工作时间关灯
|
|
|
+ device_status.lamp_status = 0;
|
|
|
+ device_status.lamp1_status = 0;
|
|
|
+ device_status.lamp2_status = 0;
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else // 光控模式
|
|
|
+ {
|
|
|
+ LOG_I("光控定时模式!");
|
|
|
+ if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
|
|
|
+ {
|
|
|
+ device_status.light_over_tim--;
|
|
|
+ light_timeout = 3600; // 重置超时计数器
|
|
|
+ #if LAMP_EN == 1
|
|
|
+ Led_Check(device_status.sunBar);
|
|
|
+ #else
|
|
|
+ device_status.work_status = 1;
|
|
|
+ LOG_I("光控定时,计时中>>>>>>>>>:%d",device_status.light_over_tim);
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ #if LAMP_EN == 1
|
|
|
+ ctr_lamp(OFF,2);
|
|
|
+ ctr_lamp(OFF,3);
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+
|
|
|
+ // 连续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);
|
|
|
+}
|
|
|
+#if 0
|
|
|
//工作状态检测
|
|
|
void WorkCheck(void)
|
|
|
{
|
|
|
static rt_uint32_t light_timeout = 3600;
|
|
|
+ static int check_stamp_cnt = 0;
|
|
|
//雨控检测,温控检测,电池电压检测
|
|
|
while(device_status.ds==1&&device_status.rain_status==0&&device_status.temp_status==0&&device_status.bat_status==0)
|
|
|
{
|
|
|
@@ -1644,18 +1794,25 @@ void WorkCheck(void)
|
|
|
if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
|
|
|
{
|
|
|
LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
|
|
|
- device_status.work_status = 1;
|
|
|
+ check_stamp_cnt++;
|
|
|
+ if(check_stamp_cnt>20)
|
|
|
+ {
|
|
|
+ device_status.work_status = 1;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
//如果当前时间小于开始时间
|
|
|
else if(difftime(mktime(&nowtime),mktime(&starttime))<0)
|
|
|
{
|
|
|
LOG_I("当前时间小于开始时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
|
|
|
device_status.work_status = 0;
|
|
|
+ check_stamp_cnt = 0;
|
|
|
}
|
|
|
//当前时间大于结束时间
|
|
|
else {
|
|
|
LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
|
|
|
device_status.work_status = 0;
|
|
|
+ check_stamp_cnt = 0;
|
|
|
}
|
|
|
#if LAMP_EN == 1
|
|
|
//如果当前时间超过20点,未到21点
|
|
|
@@ -1736,16 +1893,7 @@ void WorkCheck(void)
|
|
|
}
|
|
|
else {
|
|
|
LOG_I("光控定时模式!");
|
|
|
- /*
|
|
|
- time_t now;
|
|
|
- time(&now);
|
|
|
- static struct tm nowstamp;
|
|
|
- nowstamp =*localtime(&now);
|
|
|
- nowstamp.tm_hour = nowstamp.tm_hour - 8;
|
|
|
- static rt_uint32_t nowstamp_num = 0;
|
|
|
- nowstamp_num = mktime(&nowstamp);
|
|
|
- rt_kprintf("now stamp:%d\n",nowstamp_num);
|
|
|
- */
|
|
|
+
|
|
|
if(device_status.sun_status==0&&device_status.light_over_tim!=0)
|
|
|
{
|
|
|
|
|
|
@@ -1782,7 +1930,7 @@ void WorkCheck(void)
|
|
|
device_status.work_status = 0;
|
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
|
-
|
|
|
+#endif
|
|
|
//工作任务流程s
|
|
|
void WorkTask(void)
|
|
|
{
|
|
|
@@ -1808,6 +1956,16 @@ void WorkTask(void)
|
|
|
ctr_Fan_PUT(ON);
|
|
|
#endif
|
|
|
DTU_Write("workstart.mp3");
|
|
|
+ if(device_status.debug_ws==1)
|
|
|
+ {
|
|
|
+ time_t stamp=time(RT_NULL);
|
|
|
+ static struct tm tm;
|
|
|
+ gmtime_r(&stamp, &tm);
|
|
|
+ rt_sprintf(device_status.stamp,"%04d%02d%02d%02d%02d%02d",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
|
|
+ char* debug_str = makeJson_Warn("Work start!", device_status.stamp);
|
|
|
+ DTU_Write(debug_str);
|
|
|
+ rt_free(debug_str);
|
|
|
+ }
|
|
|
}
|
|
|
//1.打开灯管
|
|
|
#if LAMP_EN == 1
|
|
|
@@ -1985,22 +2143,6 @@ void WorkTask(void)
|
|
|
//ctr_shake(ON, 100);
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- //打开高压
|
|
|
- ctr_Heat(ON);
|
|
|
- //打开补光
|
|
|
- ctr_led(ON);
|
|
|
- LOG_I("打开补光!!");
|
|
|
- rt_pin_mode(CLEAR_L_LIMIT,PIN_MODE_INPUT);
|
|
|
- //2.翻转清虫
|
|
|
- while(rt_pin_read(CLEAR_L_LIMIT)==1) rt_thread_delay(20);
|
|
|
- rt_thread_delay(500);
|
|
|
- Hk_Take_io(); //触发海康相机拍照
|
|
|
- rt_thread_delay(500);
|
|
|
- ctr_turnv5(); //摆动清虫
|
|
|
- LOG_I("摆动清虫!");
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
|
|
|
{
|