|
@@ -36,8 +36,9 @@
|
|
|
Device_Status_typedef device_status;
|
|
Device_Status_typedef device_status;
|
|
|
|
|
|
|
|
rt_thread_t tid_workloop = RT_NULL;
|
|
rt_thread_t tid_workloop = RT_NULL;
|
|
|
-rt_thread_t tid_wkstc = RT_NULL;
|
|
|
|
|
-rt_thread_t tid_ctr = RT_NULL;
|
|
|
|
|
|
|
+
|
|
|
|
|
+rt_timer_t timer_shibie = RT_NULL;
|
|
|
|
|
+
|
|
|
rt_thread_t tid_heat = RT_NULL;
|
|
rt_thread_t tid_heat = RT_NULL;
|
|
|
rt_thread_t tid_485_play = RT_NULL;
|
|
rt_thread_t tid_485_play = RT_NULL;
|
|
|
|
|
|
|
@@ -1080,94 +1081,7 @@ void Hk_Take_io(void)
|
|
|
rt_pin_write(HK_IO, 1);
|
|
rt_pin_write(HK_IO, 1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void calorstat(uint16_t heat_time)
|
|
|
|
|
-{
|
|
|
|
|
- //uint8_t heat_up_cnt = 0;
|
|
|
|
|
- uint16_t n = 0;
|
|
|
|
|
- uint16_t delay_heat = 60;
|
|
|
|
|
- FlagStatus heat_flg = RESET;
|
|
|
|
|
- device_status.heat_time_min = 0;
|
|
|
|
|
- device_status.run_sta = device_status.heattem; //初始化加热实时温度
|
|
|
|
|
- ctr_Heat(ON);
|
|
|
|
|
-// UpLoad_Data(); //开始加热时的第一条数据
|
|
|
|
|
- //恒温模式
|
|
|
|
|
- for(n=0;n < heat_time;n++)
|
|
|
|
|
- {
|
|
|
|
|
- if(device_status.heattem>device_status.heatvalue&&heat_flg==RESET)
|
|
|
|
|
- {
|
|
|
|
|
- heat_flg = SET;
|
|
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
- while(delay_heat!=0)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.C01 &= ~(1<<1); //加热 正常
|
|
|
|
|
- delay_heat --;
|
|
|
|
|
- rt_kprintf("正在恒温加热!!!:%d",delay_heat);
|
|
|
|
|
- HMI_WRITE("workSta.g0.txt=\"正在恒温加热!!!:%d\"",delay_heat);
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- if(device_status.heattem>device_status.run_sta + 1){
|
|
|
|
|
- device_status.run_sta = device_status.heattem;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- delay_heat = 60;
|
|
|
|
|
- //跳出FOR循环
|
|
|
|
|
- n = n + 60;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if(device_status.heattem>device_status.run_sta + 1){
|
|
|
|
|
- device_status.run_sta = device_status.heattem;
|
|
|
|
|
- }
|
|
|
|
|
- if(device_status.heattem < (device_status.heatvalue - 5)&&heat_flg == SET)
|
|
|
|
|
- {
|
|
|
|
|
- //device_status.run_sta = device_status.heattem;
|
|
|
|
|
- ctr_Heat(ON);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
|
|
|
|
|
- {
|
|
|
|
|
-// if(heat_up_cnt==0)
|
|
|
|
|
-// {
|
|
|
|
|
-// UpLoad_Data(); //加热到设定温度的数据
|
|
|
|
|
-// heat_up_cnt = 1;
|
|
|
|
|
-// }
|
|
|
|
|
- //device_status.run_sta = device_status.heattem;
|
|
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
- }
|
|
|
|
|
- if((n % 60)==0)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.heat_time_min = device_status.heat_time_min + 1;
|
|
|
|
|
- if(device_status.heat_time_min % 5 == 0) //加热5分钟温度低于50,判定加热故障
|
|
|
|
|
- {
|
|
|
|
|
- if(device_status.heattem<50) {
|
|
|
|
|
- device_status.C01 |= (1 << 1); // 第1位变为1,加热故障
|
|
|
|
|
- }else {
|
|
|
|
|
- device_status.C01 &= ~(1<<1); //加热 正常
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //如果触发异常退出加热
|
|
|
|
|
- if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
|
|
|
|
|
- {
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- if(device_status.bat_status == 1)
|
|
|
|
|
- {
|
|
|
|
|
- rt_kprintf("============================触发异常退出加热==========================");
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if(device_status.timeSwitch==0&&device_status.sun_status==1)
|
|
|
|
|
- {
|
|
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
- rt_kprintf("异常退出!!!\n");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- rt_kprintf("=======正在加热======:%d-%d\n",n,heat_time);
|
|
|
|
|
- HMI_WRITE("workSta.g0.txt=\"正在加热!!!:%d-%d\"",n,heat_time);
|
|
|
|
|
- }
|
|
|
|
|
- ctr_Heat(OFF);
|
|
|
|
|
- //UpLoad_Data(); //加热结束的数据
|
|
|
|
|
-}
|
|
|
|
|
//初始化所有控制驱动,关闭
|
|
//初始化所有控制驱动,关闭
|
|
|
void HardWare_Init(uint8_t boot)
|
|
void HardWare_Init(uint8_t boot)
|
|
|
{
|
|
{
|
|
@@ -1276,7 +1190,7 @@ void ResetInit(void)
|
|
|
ctr_Heat(OFF); //风机关闭
|
|
ctr_Heat(OFF); //风机关闭
|
|
|
ctr_Motor_Driver_Power(ON); //步进电机驱动电源开启
|
|
ctr_Motor_Driver_Power(ON); //步进电机驱动电源开启
|
|
|
ctr_Motor86_move(0, 500000, 0); //86电机复位
|
|
ctr_Motor86_move(0, 500000, 0); //86电机复位
|
|
|
- device_status.ctr_up_motor = 1; //推杆电机缩进去(落虫)
|
|
|
|
|
|
|
+ device_status.ctr_up_motor = 2; //推杆电机缩进去(落虫)
|
|
|
ctr_Collect_Fan(OFF);
|
|
ctr_Collect_Fan(OFF);
|
|
|
PWM2_CH3_PB10_Fan_LCTD(OFF);
|
|
PWM2_CH3_PB10_Fan_LCTD(OFF);
|
|
|
ctr_Motor_Driver_Power(OFF);
|
|
ctr_Motor_Driver_Power(OFF);
|
|
@@ -1292,106 +1206,6 @@ void ResetInit(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-/*三色光源*/
|
|
|
|
|
-void Led_Check(uint8_t tp)
|
|
|
|
|
-{
|
|
|
|
|
- if(tp==3)
|
|
|
|
|
- {
|
|
|
|
|
- if(device_status.light_over_tim>2*3600)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 1;
|
|
|
|
|
- device_status.lamp1_status = 0;
|
|
|
|
|
- device_status.lamp2_status = 0;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.light_over_tim>3600&&device_status.light_over_tim<7200) {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 0;
|
|
|
|
|
- device_status.lamp1_status = 1;
|
|
|
|
|
- device_status.lamp2_status = 0;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.light_over_tim<1*3600) {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 0;
|
|
|
|
|
- device_status.lamp1_status = 0;
|
|
|
|
|
- device_status.lamp2_status = 1;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (tp==6) {
|
|
|
|
|
- if(device_status.light_over_tim>4*3600)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 1;
|
|
|
|
|
- device_status.lamp1_status = 0;
|
|
|
|
|
- device_status.lamp2_status = 0;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.light_over_tim<14400&&device_status.light_over_tim>7200) {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 0;
|
|
|
|
|
- device_status.lamp1_status = 1;
|
|
|
|
|
- device_status.lamp2_status = 0;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.light_over_tim<7200) {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 0;
|
|
|
|
|
- device_status.lamp1_status = 0;
|
|
|
|
|
- device_status.lamp2_status = 1;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else if (tp==9) {
|
|
|
|
|
- if(device_status.light_over_tim>6*3600)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 1;
|
|
|
|
|
- device_status.lamp1_status = 0;
|
|
|
|
|
- device_status.lamp2_status = 0;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源1计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.light_over_tim<6*3600&&device_status.light_over_tim>3*3600) {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 0;
|
|
|
|
|
- device_status.lamp1_status = 1;
|
|
|
|
|
- device_status.lamp2_status = 0;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源2计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.light_over_tim<3*3600) {
|
|
|
|
|
- device_status.work_status = 1;
|
|
|
|
|
- device_status.lamp_status = 0;
|
|
|
|
|
- device_status.lamp1_status = 0;
|
|
|
|
|
- device_status.lamp2_status = 1;
|
|
|
|
|
- LOG_I("光控定时,计时中:光源3计数:%d",device_status.light_over_tim);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-//出厂前自检 0-开机自检 1-屏幕或指令下发手动自检
|
|
|
|
|
-void HardWare_Check(uint8_t boot)
|
|
|
|
|
-{
|
|
|
|
|
- if(boot==0&&device_status.version_type!=6)
|
|
|
|
|
- {
|
|
|
|
|
- //停止所有动作 -完成
|
|
|
|
|
- HardWare_Init(boot);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- //停止所有动作
|
|
|
|
|
- //读取记录待机功耗(实测大概70mA)
|
|
|
|
|
- //(需减去屏幕的功耗大概120mA)
|
|
|
|
|
- //动作上仓门,读取功率值保存
|
|
|
|
|
- //动作下仓门,读取功率值保存
|
|
|
|
|
- //动作清扫,读取功率值保存
|
|
|
|
|
- //打开镇流器,读取功率值保存
|
|
|
|
|
- //打开海康相机供电,读取功率值保存
|
|
|
|
|
- //打开补光灯,读取功率值保存
|
|
|
|
|
- //打开路由器/RTU供电,读取功率值保存
|
|
|
|
|
- //打开加热,读取功率值保存
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
void WorkCheck(void)
|
|
void WorkCheck(void)
|
|
|
{
|
|
{
|
|
@@ -1487,433 +1301,10 @@ void WorkCheck(void)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-#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)
|
|
|
|
|
- {
|
|
|
|
|
- //工作模式检测(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("当前时间大于开始时间,小于结束时间,工作中!!!");
|
|
|
|
|
- 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点
|
|
|
|
|
- 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("光控定时模式!");
|
|
|
|
|
-
|
|
|
|
|
- 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; //持续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);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- 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
|
|
|
|
|
-//工作任务流程s
|
|
|
|
|
-void WorkTask(void)
|
|
|
|
|
-{
|
|
|
|
|
- static int clt_time = 0; //收集时间差秒数
|
|
|
|
|
- static int heat_time = 0;
|
|
|
|
|
- LOG_I("工作状态:%d",device_status.work_status);
|
|
|
|
|
- LOG_I("开关机状态:%d",device_status.ds);
|
|
|
|
|
- while(device_status.work_status==1&&device_status.temp_status==0&&device_status.bat_status==0&&device_status.rain_status==0&&device_status.ds==1&&device_status.clear_status==0)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.work_done = 0;
|
|
|
|
|
- if(clt_time==0)
|
|
|
|
|
- {
|
|
|
|
|
- #if 0
|
|
|
|
|
- if(device_status.version_type==41&&atoi(device_status.power)<350)
|
|
|
|
|
- {
|
|
|
|
|
- LOG_W("相机电流不足!");
|
|
|
|
|
- char *ctr_hk_p_warn = makeJson_Warn("电流不足", "相机");
|
|
|
|
|
- DTU_Write("%s",ctr_hk_p_warn);
|
|
|
|
|
- rt_free(ctr_hk_p_warn);
|
|
|
|
|
- }
|
|
|
|
|
- #endif
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- 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
|
|
|
|
|
- if(device_status.lamp_status==1&&device_status.sun_status==0) //光控状态不亮灯
|
|
|
|
|
- {
|
|
|
|
|
- ctr_lamp(ON,1);
|
|
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.lamp1_status==1&&device_status.sun_status==0) {
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- ctr_lamp(ON,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
- }
|
|
|
|
|
- else if (device_status.lamp2_status==1&&device_status.sun_status==0) {
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(ON,3);
|
|
|
|
|
- }
|
|
|
|
|
- #else
|
|
|
|
|
- ctr_lamp(ON,1);
|
|
|
|
|
- #endif
|
|
|
|
|
- LOG_I("打开灯管!!!");
|
|
|
|
|
- #if 0
|
|
|
|
|
- rt_thread_delay(2000);
|
|
|
|
|
- if(atoi(device_status.power)<450)
|
|
|
|
|
- {
|
|
|
|
|
- LOG_I("Current is:%d",atoi(device_status.power));
|
|
|
|
|
- if(atoi(device_status.power)>50&&atoi(device_status.power)<5000) //过滤电流检测芯片损坏导致电流异常
|
|
|
|
|
- {
|
|
|
|
|
- char* lamp_err_warn = makeJson_Warn("电流不足", "灯管");
|
|
|
|
|
- DTU_Write("%s",lamp_err_warn);
|
|
|
|
|
- rt_free(lamp_err_warn);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- #endif
|
|
|
|
|
- if(device_status.version_type!=5)
|
|
|
|
|
- {
|
|
|
|
|
- rt_thread_delay(1000); //待灯管启动再往下执行,否则会触发电机过流
|
|
|
|
|
- //2.打开上仓门
|
|
|
|
|
- LOG_I("打开上仓门!!!");
|
|
|
|
|
- device_status.ctr_up_motor = 1;
|
|
|
|
|
- //3.收集
|
|
|
|
|
- clt_time = device_status.clt_time * 60;
|
|
|
|
|
-
|
|
|
|
|
- while(clt_time!=1)
|
|
|
|
|
- {
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- ctr_Fan_IN(ON);
|
|
|
|
|
- #endif
|
|
|
|
|
- clt_time --;
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- if(clt_time%30==0)
|
|
|
|
|
- ctr_Fan_PUT(OFF);
|
|
|
|
|
- #endif
|
|
|
|
|
- rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
|
|
|
|
|
- //如果触发异常
|
|
|
|
|
- if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
|
|
|
|
|
- {
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- #if LAMP_EN == 1
|
|
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
- #endif
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- ctr_Fan_IN(OFF);
|
|
|
|
|
- #endif
|
|
|
|
|
- rt_kprintf("异常退出!!!\n");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- if(device_status.timeSwitch==0&&device_status.sun_status==1)
|
|
|
|
|
- {
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- #if LAMP_EN == 1
|
|
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
- #endif
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- ctr_Fan_IN(OFF);
|
|
|
|
|
- #endif
|
|
|
|
|
- rt_kprintf("异常退出!!!\n");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- clt_time = 1;
|
|
|
|
|
- if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
|
|
|
|
|
- {
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- #if LAMP_EN == 1
|
|
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
- #endif
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- ctr_Fan_IN(OFF);
|
|
|
|
|
- #endif
|
|
|
|
|
- rt_kprintf("异常退出!!!\n");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- if(device_status.timeSwitch==0&&device_status.sun_status==1)
|
|
|
|
|
- {
|
|
|
|
|
- ctr_lamp(OFF,1);
|
|
|
|
|
- #if LAMP_EN == 1
|
|
|
|
|
- ctr_lamp(OFF,2);
|
|
|
|
|
- ctr_lamp(OFF,3);
|
|
|
|
|
- #endif
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- ctr_Fan_IN(OFF);
|
|
|
|
|
- #endif
|
|
|
|
|
- rt_kprintf("异常退出!!!\n");
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- #if 0//LAMP_EN == 0
|
|
|
|
|
- ctr_Fan_IN(OFF);
|
|
|
|
|
- #endif
|
|
|
|
|
- //4.关闭上仓门
|
|
|
|
|
- device_status.ctr_up_motor = 2;
|
|
|
|
|
- rt_kprintf("关闭上仓门!!!\n");
|
|
|
|
|
- while(device_status.ctr_up_motor!=0)
|
|
|
|
|
- {
|
|
|
|
|
- rt_thread_delay(100);
|
|
|
|
|
- LOG_I("等待上仓门关闭!!!");
|
|
|
|
|
- }
|
|
|
|
|
- //5.加热
|
|
|
|
|
- if(device_status.heat_sw==0)
|
|
|
|
|
- {
|
|
|
|
|
- calorstat(device_status.heattime*60);
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- heat_time = device_status.heattime * 60;
|
|
|
|
|
- while(heat_time!=0)
|
|
|
|
|
- {
|
|
|
|
|
- heat_time--;
|
|
|
|
|
- LOG_I("正在加热状态!!!");
|
|
|
|
|
- rt_thread_delay(1000);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //6.打开下仓门
|
|
|
|
|
- if(device_status.rain_status==0)
|
|
|
|
|
- {
|
|
|
|
|
- device_status.ctr_down_motor =1;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- device_status.ctr_down_motor = 2;
|
|
|
|
|
- device_status.ctr_up_motor = 2;
|
|
|
|
|
- }
|
|
|
|
|
- //待下仓门完全打开
|
|
|
|
|
- while(device_status.ctr_down_motor!=0)
|
|
|
|
|
- {
|
|
|
|
|
- rt_thread_delay(100);
|
|
|
|
|
- rt_kprintf("等待下仓门打开!!!\n");
|
|
|
|
|
- }
|
|
|
|
|
- rt_thread_delay(3000);
|
|
|
|
|
- //关闭下仓门
|
|
|
|
|
- device_status.ctr_down_motor = 2;
|
|
|
|
|
- while(device_status.ctr_down_motor!=0)
|
|
|
|
|
- {
|
|
|
|
|
- rt_thread_delay(100);
|
|
|
|
|
- rt_kprintf("等待下仓门关闭!!!\n");
|
|
|
|
|
- }
|
|
|
|
|
- //2022-04-12add:
|
|
|
|
|
- LOG_I("打开上仓门!!!");
|
|
|
|
|
- device_status.ctr_up_motor = 1;
|
|
|
|
|
- if(device_status.version_type==4||device_status.version_type==41)
|
|
|
|
|
- {
|
|
|
|
|
- //震动
|
|
|
|
|
- ctr_shake(ON, device_status.shake_sec);
|
|
|
|
|
- //补光&&拍照
|
|
|
|
|
- LOG_I("拍照!!!");
|
|
|
|
|
- ctr_led(ON);
|
|
|
|
|
- HK_TakePhoto();
|
|
|
|
|
- //清扫
|
|
|
|
|
- device_status.clear_status=1;
|
|
|
|
|
- //清扫失效则使用震动
|
|
|
|
|
- //ctr_shake(ON, 100);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if(device_status.bat_status == 1 || device_status.temp_status == 1 || device_status.rain_status==1 || device_status.ds==0)
|
|
|
|
|
- {
|
|
|
|
|
- LOG_I("-------------------not work--------------------");
|
|
|
|
|
- device_status.work_status = 0;
|
|
|
|
|
- }
|
|
|
|
|
- //工作结束
|
|
|
|
|
- if(device_status.work_done==0&&device_status.work_status==0)
|
|
|
|
|
- {
|
|
|
|
|
- DTU_Write("workdone");
|
|
|
|
|
- if (device_status.version_type==1) {
|
|
|
|
|
- turnzp(); //2024-03-21 :开机不再转仓
|
|
|
|
|
- }
|
|
|
|
|
- ResetInit();
|
|
|
|
|
- clt_time = 0;
|
|
|
|
|
- }
|
|
|
|
|
- rt_kprintf("***not work-device status:%d\n",device_status.ds);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
void guanshan_on(void *args)
|
|
void guanshan_on(void *args)
|
|
|
{
|
|
{
|
|
|
LOG_W("guanshan_on!");
|
|
LOG_W("guanshan_on!");
|
|
|
|
|
+ rt_timer_start(timer_shibie);
|
|
|
rt_event_send(event_485_play, 0x01);
|
|
rt_event_send(event_485_play, 0x01);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -2105,7 +1496,6 @@ void WorkTask_CB5(void)
|
|
|
pin_guangshan_unbind();
|
|
pin_guangshan_unbind();
|
|
|
//pin_motor_86_unbind();
|
|
//pin_motor_86_unbind();
|
|
|
//打开推杆电机,益虫放生
|
|
//打开推杆电机,益虫放生
|
|
|
- device_status.ctr_down_motor = 1;
|
|
|
|
|
DTU_Write("{\"cmd\":\"workdone\"}");
|
|
DTU_Write("{\"cmd\":\"workdone\"}");
|
|
|
ResetInit();
|
|
ResetInit();
|
|
|
}
|
|
}
|
|
@@ -2153,15 +1543,8 @@ static void Work_Loop_thread_entry(void *parameter)
|
|
|
ResetInit();
|
|
ResetInit();
|
|
|
while(1)
|
|
while(1)
|
|
|
{
|
|
{
|
|
|
- if(device_status.version_type!=5&&device_status.dtype==3)
|
|
|
|
|
- {
|
|
|
|
|
- WorkTask();
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- if(device_status.version_type==5)
|
|
|
|
|
- {
|
|
|
|
|
- WorkTask_CB5();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ WorkTask_CB5();
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2199,14 +1582,7 @@ static void Control_Check_thread_entry(void *parameter)
|
|
|
{
|
|
{
|
|
|
if(device_status.update_flag==1) break;
|
|
if(device_status.update_flag==1) break;
|
|
|
if(device_status.version_type==5) break;
|
|
if(device_status.version_type==5) break;
|
|
|
- if(device_status.work_status==1&&device_status.heat_sw==1)
|
|
|
|
|
- {
|
|
|
|
|
- ctr_lamp(ON, 1);
|
|
|
|
|
- rt_thread_delay(10000);
|
|
|
|
|
- calorstat(device_status.heattime*60);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
|
|
+
|
|
|
if(device_status.selfcheck_ws==2)
|
|
if(device_status.selfcheck_ws==2)
|
|
|
{
|
|
{
|
|
|
while(current_second <= total_seconds)
|
|
while(current_second <= total_seconds)
|
|
@@ -2318,7 +1694,7 @@ static void Control_Check_thread_entry(void *parameter)
|
|
|
//延时10S
|
|
//延时10S
|
|
|
rt_thread_delay(10000);
|
|
rt_thread_delay(10000);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
rt_thread_delay(1000);
|
|
rt_thread_delay(1000);
|
|
@@ -2355,7 +1731,7 @@ static void thread_485_play_entry(void *param)
|
|
|
int Control_clear(void)
|
|
int Control_clear(void)
|
|
|
{
|
|
{
|
|
|
/* 创建线程*/
|
|
/* 创建线程*/
|
|
|
- tid_ctr = rt_thread_create("Control_Clear_thread_entry",
|
|
|
|
|
|
|
+ rt_thread_t tid_ctr = rt_thread_create("Control_Clear_thread_entry",
|
|
|
Control_Clear_thread_entry, RT_NULL,
|
|
Control_Clear_thread_entry, RT_NULL,
|
|
|
2048, //2048
|
|
2048, //2048
|
|
|
24, //23
|
|
24, //23
|
|
@@ -2404,7 +1780,7 @@ int Workstatus_check(void)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
/* 创建线程*/
|
|
/* 创建线程*/
|
|
|
- tid_wkstc = rt_thread_create("work_status_check_thread",
|
|
|
|
|
|
|
+ rt_thread_t tid_wkstc = rt_thread_create("work_status_check_thread",
|
|
|
Work_status_thread_entry, RT_NULL,
|
|
Work_status_thread_entry, RT_NULL,
|
|
|
WORK_CHECK_THREAD_STACK_SIZE, //1024
|
|
WORK_CHECK_THREAD_STACK_SIZE, //1024
|
|
|
WORK_CHECK_THREAD_PRIORITY, //23
|
|
WORK_CHECK_THREAD_PRIORITY, //23
|
|
@@ -2433,10 +1809,36 @@ int Work_Loop_Task(void)
|
|
|
return result_loop;
|
|
return result_loop;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void timer_shibie_stop()
|
|
|
|
|
+{
|
|
|
|
|
+ rt_timer_stop(timer_shibie);
|
|
|
|
|
+ LOG_W("timer_shibie_stop!");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static void t_shibie_callback(void *parameter)
|
|
|
|
|
+{
|
|
|
|
|
+ LOG_E("识别超时!");
|
|
|
|
|
+ device_status.autotakepic = 10;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int rt_software_timer_init(void)
|
|
|
|
|
+{
|
|
|
|
|
+ //启动拍照超时定时器
|
|
|
|
|
+ timer_shibie = rt_timer_create("t_shibie",t_shibie_callback,RT_NULL, 50000, RT_TIMER_FLAG_ONE_SHOT|RT_TIMER_FLAG_HARD_TIMER);
|
|
|
|
|
+ if(timer_takephoto==RT_NULL)
|
|
|
|
|
+ {
|
|
|
|
|
+ LOG_E("rt_timer_create t_shibie failed!");
|
|
|
|
|
+ return RT_ERROR;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ return RT_EOK;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
+INIT_APP_EXPORT(rt_software_timer_init);
|
|
|
|
|
|
|
|
|
|
|
|
|
-MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
|
|
|
|
|
MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
|
|
MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
|
|
|
MSH_CMD_EXPORT(ctr_Heat,ctr_Heat<ON|OFF>);
|
|
MSH_CMD_EXPORT(ctr_Heat,ctr_Heat<ON|OFF>);
|
|
|
MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
|
|
MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
|