|
|
@@ -1495,18 +1495,44 @@ void ctr_TG_Clear(uint16_t clear_timeout)
|
|
|
HMI_WRITE("cangWei.rotateFlag.val=%d",0);
|
|
|
HMI_WRITE("sysTest.switchClear.val=%d",0);
|
|
|
}
|
|
|
-//DTU,RTU供电
|
|
|
+
|
|
|
+// 全局静态变量,保存上次关闭的 tick
|
|
|
+static rt_uint32_t s_last_off_tick = 0;
|
|
|
+
|
|
|
void ctr_RTU_DTU(uint8_t status_rtu)
|
|
|
{
|
|
|
+ // 1. 先设置引脚模式(只需要设置一次即可,放这里也兼容多次调用)
|
|
|
rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
|
|
|
- if(status_rtu==ON)
|
|
|
+
|
|
|
+ if (status_rtu == ON)
|
|
|
{
|
|
|
- rt_pin_write(RTU_DTU,ON);
|
|
|
+ // 开机逻辑:必须满足冷却时间才能开机
|
|
|
+ rt_uint32_t current_tick = rt_tick_get();
|
|
|
+ rt_uint32_t cool_ticks = 30 * RT_TICK_PER_SECOND; // 30秒
|
|
|
+ if (s_last_off_tick != 0)
|
|
|
+ {
|
|
|
+ rt_uint32_t diff_tick = current_tick - s_last_off_tick;
|
|
|
+ if (diff_tick < cool_ticks)
|
|
|
+ {
|
|
|
+ // 未冷却完成,计算剩余时间
|
|
|
+ rt_uint32_t wait_ticks = cool_ticks - diff_tick;
|
|
|
+ rt_uint32_t wait_ms = wait_ticks * (1000 / RT_TICK_PER_SECOND);
|
|
|
+ LOG_W("RTU电源关闭后需等待 %d ms 冷却, 禁止开机", wait_ms);
|
|
|
+ // 阻塞等待冷却(如果不允许阻塞,就直接return,不要delay)
|
|
|
+ rt_thread_delay(wait_ticks);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 冷却完成,执行开机
|
|
|
+ rt_pin_write(RTU_DTU, ON);
|
|
|
+ s_last_off_tick = 0; // 清除关机时间
|
|
|
+ LOG_W("RTU电源启动!!!");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- LOG_W("RTU电源复位!!!");
|
|
|
- rt_pin_write(RTU_DTU,OFF);
|
|
|
+ // 关机逻辑:记录关机时刻tick
|
|
|
+ rt_pin_write(RTU_DTU, OFF);
|
|
|
+ s_last_off_tick = rt_tick_get();
|
|
|
+ LOG_W("RTU电源关闭:%d",s_last_off_tick);
|
|
|
}
|
|
|
}
|
|
|
//海康拍照
|
|
|
@@ -1727,7 +1753,6 @@ void ResetInit(void)
|
|
|
if(device_status.power_status==1)
|
|
|
{
|
|
|
ctr_router(ON);
|
|
|
- ctr_RTU_DTU(ON);
|
|
|
//2.打开相机供电
|
|
|
ctr_photo(ON);
|
|
|
}
|
|
|
@@ -1909,199 +1934,7 @@ void HardWare_Check(uint8_t boot)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-#if 0
|
|
|
-//工作状态检测
|
|
|
-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)
|
|
|
- {
|
|
|
- //工作模式检测(RTC时间正常,1-时控/0-光控)(RTC时间异常强行使用光控)
|
|
|
- if(device_status.timeSwitch==1)
|
|
|
- {
|
|
|
- LOG_I("***********时控*****************");
|
|
|
- if(device_status.startBar==device_status.stopBar&&device_status.startBar==0){
|
|
|
- device_status.work_status = 1;
|
|
|
- LOG_I("24 hours work...");
|
|
|
- #if LAMP_EN == 1
|
|
|
- device_status.lamp_status = 1;
|
|
|
- device_status.lamp1_status = 0;
|
|
|
- device_status.lamp2_status = 0;
|
|
|
- if(device_status.sun_status==1){
|
|
|
- ctr_lamp(OFF, 1);
|
|
|
- ctr_lamp(OFF, 2);
|
|
|
- ctr_lamp(OFF, 3);
|
|
|
- }
|
|
|
- #endif
|
|
|
- }
|
|
|
|
|
|
- //如果开始和结束是同一天
|
|
|
- if(device_status.startBar<device_status.stopBar)
|
|
|
- {
|
|
|
- LOG_I("开始和结束是同一天");
|
|
|
- time_t now;
|
|
|
- time(&now);
|
|
|
- static struct tm nowtime; //现在
|
|
|
- static struct tm starttime; //开始
|
|
|
- static struct tm endtime; //结束
|
|
|
- //获取当前时间戳
|
|
|
- nowtime =*localtime(&now);
|
|
|
- nowtime.tm_hour = nowtime.tm_hour-8;
|
|
|
- //获取定时开始的时间戳
|
|
|
- starttime = *localtime(&now);
|
|
|
- starttime.tm_hour = device_status.startBar-8;
|
|
|
- starttime.tm_min = 0;
|
|
|
- starttime.tm_sec = 0;
|
|
|
- //获取定时结束的时间戳
|
|
|
- endtime = *localtime(&now);
|
|
|
- endtime.tm_hour = device_status.stopBar-8;
|
|
|
- endtime.tm_min = 0;
|
|
|
- endtime.tm_sec = 0;
|
|
|
- LOG_I("***工作结束在当天:现在时间:%d-开始时间:%d-结束时间:%d***",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
|
|
|
- //如果当前时间大于开始时间且小于结束时间,且没有开始工作
|
|
|
- if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&endtime))<0))
|
|
|
- {
|
|
|
- LOG_I("当前时间大于开始时间,小于结束时间,工作中!!!");
|
|
|
- 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;
|
|
|
- }
|
|
|
- //当前时间大于结束时间
|
|
|
- else {
|
|
|
- LOG_I("当前时间大于结束时间,不工作!!!-%d-%d",mktime(&nowtime),mktime(&starttime));
|
|
|
- device_status.work_status = 0;
|
|
|
- }
|
|
|
- #if LAMP_EN == 1
|
|
|
- //如果当前时间超过20点,未到21点
|
|
|
- if((difftime(mktime(&nowtime), mktime(&starttime)) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+3600)<0))
|
|
|
- {
|
|
|
- LOG_I("3led:20~21");
|
|
|
- device_status.lamp_status = 1;
|
|
|
- device_status.lamp1_status = 0;
|
|
|
- device_status.lamp2_status = 0;
|
|
|
- }
|
|
|
- else if ((difftime(mktime(&nowtime), mktime(&starttime)+3600) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+7200)<0)) {
|
|
|
- LOG_I("3led:21~22");
|
|
|
- device_status.lamp1_status = 1;
|
|
|
- device_status.lamp_status = 0;
|
|
|
- device_status.lamp2_status = 0;
|
|
|
- }
|
|
|
- else if ((difftime(mktime(&nowtime), mktime(&starttime)+7200) >=0) && (difftime(mktime(&nowtime),mktime(&starttime)+10800)<0)) {
|
|
|
- LOG_I("3led:22~23");
|
|
|
- device_status.lamp2_status = 1;
|
|
|
- device_status.lamp_status = 0;
|
|
|
- device_status.lamp1_status =0;
|
|
|
- }
|
|
|
- #endif
|
|
|
- }
|
|
|
- //如果结束时间是第二天
|
|
|
- else if (device_status.startBar>device_status.stopBar) {
|
|
|
- time_t now;
|
|
|
- time(&now);
|
|
|
- static struct tm nowtime; //现在
|
|
|
- static struct tm starttime; //开始
|
|
|
- static struct tm endtime; //结束
|
|
|
- //获取当前时间戳
|
|
|
- nowtime =*localtime(&now);
|
|
|
- nowtime.tm_hour = nowtime.tm_hour-8;
|
|
|
- //获取定时开始的时间戳
|
|
|
- starttime = *localtime(&now);
|
|
|
- starttime.tm_hour = device_status.startBar-8;
|
|
|
- starttime.tm_min = 0;
|
|
|
- starttime.tm_sec = 0;
|
|
|
- //获取定时结束的时间戳
|
|
|
- endtime = *localtime(&now);
|
|
|
- endtime.tm_hour = device_status.stopBar-8;
|
|
|
- endtime.tm_min = 0;
|
|
|
- endtime.tm_sec = 0;
|
|
|
- LOG_I("工作结束在第二天:现在时间:%d-开始时间:%d-结束时间:%d!!!",mktime(&nowtime),mktime(&starttime),mktime(&endtime));
|
|
|
- //如果当前时间大于开始时间,且没有开始工作 ,注意时间戳日期加1
|
|
|
- if((difftime(mktime(&nowtime), mktime(&starttime)) > 0 ))
|
|
|
- {
|
|
|
- //获取定时结束的时间戳
|
|
|
- endtime = *localtime(&now); //将获取到的时间转换为时间戳
|
|
|
- endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
|
|
|
- endtime.tm_min = 0;
|
|
|
- endtime.tm_sec = 0;
|
|
|
- device_status.work_status = 1;
|
|
|
- LOG_I("当前前时间大于开始时间,且没有开始工作");
|
|
|
- }
|
|
|
- //当前时间小于开始时间
|
|
|
- else if ((difftime(mktime(&nowtime), mktime(&starttime)) < 0))
|
|
|
- {
|
|
|
- //获取定时结束的时间戳
|
|
|
- endtime = *localtime(&now); //将获取到的时间转换为时间戳
|
|
|
- endtime.tm_hour = device_status.stopBar-8; //这里需减8用于时区转换
|
|
|
- endtime.tm_min = 0;
|
|
|
- endtime.tm_sec = 0;
|
|
|
- //如果当前时间戳小于结束时间戳
|
|
|
- if(difftime(mktime(&nowtime),mktime(&endtime)) < 0)
|
|
|
- {
|
|
|
- LOG_I("当前时间大于开始时间,且没有开始工作,当前时间小于结束时间的情况:计算工作时间:从当前时间工作第二天的结束时间");
|
|
|
- device_status.work_status = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LOG_I("当前时间小于开始时间,且没有开始工作,不是重启引起的,即还没到开始时间");
|
|
|
- device_status.work_status = 0; //不在工作时间,待机
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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)
|
|
|
- {
|
|
|
-
|
|
|
- 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
|
|
|
- {
|
|
|
- light_timeout --;
|
|
|
- //没有在测试并且没有在自检
|
|
|
- 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
|
|
|
- }
|
|
|
- device_status.work_status = 0;
|
|
|
- if(light_timeout==0) device_status.light_over_tim=0;
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- rt_thread_delay(1000);
|
|
|
- }
|
|
|
- LOG_I("雨控状态,温控状态,电压状态:%d-%d-%d",device_status.rain_status,device_status.temp_status,device_status.bat_status);
|
|
|
- device_status.work_status = 0;
|
|
|
- rt_thread_delay(1000);
|
|
|
-}
|
|
|
-#endif
|
|
|
void WorkCheck(void)
|
|
|
{
|
|
|
static rt_uint32_t light_timeout = 3600;
|
|
|
@@ -2149,9 +1982,12 @@ void WorkCheck(void)
|
|
|
else // 光控模式
|
|
|
{
|
|
|
LOG_I("光控定时模式!");
|
|
|
- if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
|
|
|
+ if(device_status.sun_status == 0 && device_status.light_over_tim > 0)
|
|
|
{
|
|
|
- device_status.light_over_tim--;
|
|
|
+ // 夜晚且有剩余时间:工作
|
|
|
+ if(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);
|
|
|
@@ -2173,22 +2009,14 @@ void WorkCheck(void)
|
|
|
|
|
|
// 连续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;
|
|
|
+ light_timeout = 3600; // 重置防止负数
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
|
-
|
|
|
- // 异常状态处理
|
|
|
+ // 异常状态处理while之外
|
|
|
device_status.work_status = 0;
|
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
|
@@ -2897,4 +2725,31 @@ int Work_Loop_Task(void)
|
|
|
MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
|
|
|
MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
|
|
|
MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
|
|
|
+
|
|
|
+// RTU/DTU 电源控制 shell 命令
|
|
|
+static void ctr_rtu_dtu(int argc, char** argv)
|
|
|
+{
|
|
|
+ if(argc != 2)
|
|
|
+ {
|
|
|
+ rt_kprintf("Usage: ctr_rtu_dtu <ON|OFF>\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(strcmp(argv[1], "ON") == 0 || strcmp(argv[1], "on") == 0)
|
|
|
+ {
|
|
|
+ ctr_RTU_DTU(ON);
|
|
|
+ rt_kprintf("RTU/DTU Power ON\n");
|
|
|
+ }
|
|
|
+ else if(strcmp(argv[1], "OFF") == 0 || strcmp(argv[1], "off") == 0)
|
|
|
+ {
|
|
|
+ ctr_RTU_DTU(OFF);
|
|
|
+ rt_kprintf("RTU/DTU Power OFF\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rt_kprintf("Invalid parameter: %s\n", argv[1]);
|
|
|
+ rt_kprintf("Usage: ctr_rtu_dtu <ON|OFF>\n");
|
|
|
+ }
|
|
|
+}
|
|
|
+MSH_CMD_EXPORT(ctr_rtu_dtu,ctr_rtu_dtu<ON|OFF>);
|
|
|
MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);
|