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

BIN
Application_cbd_apm32f1/.settings/.rtmenus


+ 30 - 12
Application_cbd_apm32f1/applications/beep.c

@@ -12,6 +12,11 @@
 #include <control.h>
 #include "hmi.h"
 
+#define DBG_ENABLE
+#define DBG_COLOR
+#define DBG_TAG "pwm"
+#define DBG_LEVEL         DBG_LOG
+#include <rtdbg.h>
 
 #define HWTIMER_DEV_NAME   "timer2"     /* 定时器名称 */
 
@@ -302,24 +307,37 @@ void Motor_Qingsao_L_PWM(uint8_t on_off)
         rt_pwm_disable(pwm_tim8, PC8_TIM3_CH);
     }
 }
+
 void Motor_shake(uint8_t status_shake,uint16_t shake_sec)
 {
+    rt_uint16_t turn_cnt = 0;
     beep_init();
-    rt_pwm_set(pwm_device, PB1_TIM3_CH, 200000, 150000);//channel,period,pulse
-    if(status_shake==ON)
-    {
-        rt_pwm_enable(pwm_device, PB1_TIM3_CH);
-        if(shake_sec!=0)
-        {
-            rt_thread_delay(shake_sec*1000);
-            rt_pwm_disable(pwm_device, PB1_TIM3_CH);
-            HMI_WRITE("cangWei.switchShake.val=%d",0);
+    rt_pwm_set(pwm_device, PB1_TIM3_CH, 200000, 100000);//channel,period,pulse
+    rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
+    rt_pwm_enable(pwm_device, PB1_TIM3_CH);
+
+    while(rt_pin_read(LIMIT_90)==0){
+        rt_thread_delay(100);
+        turn_cnt++;
+        if(turn_cnt==shake_sec){
+            LOG_E("电机异常,不转?限位异常,持续触发?");
+            HMI_WRITE("sysTest.switchClear.val=%d",0);
+            break;
         }
     }
-    else {
-        rt_pwm_disable(pwm_device, PB1_TIM3_CH);
-        HMI_WRITE("cangWei.switchShake.val=%d",0);
+    if(turn_cnt==shake_sec) return;
+    turn_cnt = 0;
+    while(rt_pin_read(LIMIT_90)==1){
+        turn_cnt++;
+        rt_thread_delay(50);
+        if(turn_cnt==shake_sec){
+            LOG_E("检测不到限位,超时退出?");
+            break;
+        }
     }
+    //停
+    rt_pwm_disable(pwm_device, PB1_TIM3_CH);
+    HMI_WRITE("sysTest.switchClear.val=%d",0);
 }
 
 

+ 114 - 557
Application_cbd_apm32f1/applications/control.c

@@ -602,134 +602,7 @@ uint8_t ctr_led(uint8_t status_led)
     }
     return status_led;
 }
-/*************************************************
-Function:       ctr_turn
-Description:    转盘驱动
-Calls:
-Table Accessed: // 被访问的表(此项仅对于牵扯到数据库操作的程序)
-Table Updated: // 被修改的表(此项仅对于牵扯到数据库操作的程序)
-Input:          v=0(复位) v=90转90度
-Output:         NULL
-Return:         NULL
-Others:         NULL
-*************************************************/
-void ctr_turn(uint8_t v,uint8_t sta)
-{
-    DTU_Write("turn.mp3");
-    LOG_I("================v===============:%d",v);
-    rt_uint16_t turn_cnt = 0;
-    rt_pin_mode(TURN_ZP_R, PIN_MODE_OUTPUT);
-    rt_pin_mode(TURN_ZP_L, PIN_MODE_OUTPUT);
-    rt_pin_mode(LIMIT_0, PIN_MODE_INPUT);
-    rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
-    //if(v==0&&rt_pin_read(LIMIT_0)==0) return;               //如果在初始位置,则不再往下执行
-    while(rt_pin_read(LIMIT_0)==0||rt_pin_read(LIMIT_90)==0)
-    {
-        rt_pin_write(TURN_ZP_R, ON);
-        rt_pin_write(TURN_ZP_L, OFF);
-        //Motor_shake(ON,0);
-        turn_cnt ++;
-        rt_thread_delay(100);
-        if(turn_cnt==1000)
-        {
-            turn_cnt = 0;
-            rt_pin_write(TURN_ZP_R, OFF);
-            rt_pin_write(TURN_ZP_L, OFF);
-            //Motor_shake(OFF,0);
-            char *turn_warn =makeJson_Warn("未检测到限位", "转盘");
-            DTU_Write("%s",turn_warn);
-            rt_free(turn_warn);
-            break;
-        }
-    }
-    turn_cnt = 0;
-    while(v==0&&rt_pin_read(LIMIT_0)==1)
-    {
-        rt_pin_write(TURN_ZP_R, ON);
-        rt_pin_write(TURN_ZP_L, OFF);
-        Motor_shake(ON,0);
-        rt_thread_delay(200);        //10 to 100
-        turn_cnt ++;
-        if(turn_cnt==300)          //6000 to 600
-        {
-            turn_cnt = 0;
-//            rt_pin_write(TURN_ZP_R, OFF);
-//            rt_pin_write(TURN_ZP_L, OFF);
-//            char *turn_warn =makeJson_Warn("超时", "转盘复位");
-//            DTU_Write("%s",turn_warn);
-//            rt_free(turn_warn);
-            break;
-        }
-    }
-    while(v==0&&rt_pin_read(LIMIT_0)==1)
-    {
-        rt_pin_write(TURN_ZP_R, ON);
-        rt_pin_write(TURN_ZP_L, OFF);
-        //Motor_shake(ON,0);
-        rt_thread_delay(50);        //10 to 50
-        turn_cnt ++;
-        if(turn_cnt==10)          //6000 to 1200
-        {
-            turn_cnt = 0;
-            rt_pin_write(TURN_ZP_R, OFF);
-            rt_pin_write(TURN_ZP_L, OFF);
-            //Motor_shake(OFF,0);
-            char *turn_warn =makeJson_Warn("超时", "转盘复位");
-            DTU_Write("%s",turn_warn);
-            rt_free(turn_warn);
-            break;
-        }
-    }
-    turn_cnt = 0;
-    while(v==90&&rt_pin_read(LIMIT_90)==1)
-    {
-        rt_pin_write(TURN_ZP_R, ON);
-        rt_pin_write(TURN_ZP_L, OFF);
-        //Motor_shake(ON,0);
-        rt_thread_delay(200);
-        turn_cnt ++;
-        if(turn_cnt==150)
-        {
-            turn_cnt = 0;
-//            rt_pin_write(TURN_ZP_R, OFF);
-//            rt_pin_write(TURN_ZP_L, OFF);
-//            char *turn_warn =makeJson_Warn("超时", "转盘");
-//            DTU_Write(turn_warn);
-//            rt_free(turn_warn);
-            break;
-        }
-    }
-    while(v==90&&rt_pin_read(LIMIT_90)==1)
-    {
-//        rt_pin_write(TURN_ZP_R, ON);
-//        rt_pin_write(TURN_ZP_L, OFF);
-        Motor_shake(ON,0);
-        rt_thread_delay(50);
-        turn_cnt ++;
-        if(turn_cnt==10)
-        {
-            turn_cnt = 0;
-            rt_pin_write(TURN_ZP_R, OFF);
-            rt_pin_write(TURN_ZP_L, OFF);
-            //Motor_shake(OFF,0);
-            char *turn_warn =makeJson_Warn("超时", "转盘");
-            DTU_Write(turn_warn);
-            rt_free(turn_warn);
-            break;
-        }
-    }
-    if(sta!=0)
-    {
-        //保存位置
-        device_status.run_sta = sta;
-        ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
-    }
-    turn_cnt = 0;
-    rt_pin_write(TURN_ZP_R, OFF);
-    rt_pin_write(TURN_ZP_L, OFF);
-    Motor_shake(OFF,0);
-    HMI_WRITE("cangWei.rotateFlag.val=0");
-}
+
 /*
  *
  * */
@@ -1406,90 +1279,15 @@ void SunTest(void)
 /*上电初始化*/
 void ResetInit(void)
 {
-    if(device_status.dtype==7)
-    {
-        ctr_Motor_Driver(0, 0, 0, 0);
-        //关闭电磁阀
-        ctr_shake(OFF, 0);
-        //关闭加热
-        ctr_Heat(OFF);
-        //关闭制冷
-        ctr_Cold(OFF);
-        //关闭补光灯
-        ctr_led(OFF);
-        //转盘复位
-        if(device_status.run_sta==0)
-            ctr_turn(0, 0);
-    }
-    if(device_status.version_type!=6&&device_status.version_type!=7)
-    {
-        device_status.work_done = 1;
-           //1.打开路由器供电
-           if(device_status.power_status==1)
-           {
-               ctr_router(ON);
-               ctr_RTU_DTU(ON);
-               //2.打开相机供电
-               ctr_photo(ON);
-           }
-           //3.关闭镇流器
-           ctr_lamp(OFF,1);
-           //4.关闭震动电机
-           ctr_shake(OFF, 0);
-           //5.关闭加热
-           ctr_Heat(OFF);
-           //6.关闭补光灯
-           ctr_led(OFF);
-           if(device_status.bat_status==1||atoi(device_status.fuse_voltage)<1)
-           {
-               LOG_W("欠压!");
-               return;
-           }
-           //7.关闭上仓门
-           device_status.ctr_up_motor = 2;
-//           while(device_status.ctr_up_motor!=0)
-//           {
-//               LOG_I("关闭上仓门...");
-//               rt_thread_delay(100);
-//           }
-           //8.关闭下仓门
-           device_status.ctr_down_motor = 2;
-           while(device_status.ctr_down_motor!=0)
-           {
-               LOG_I("关闭下仓门....");
-               rt_thread_delay(100);
-           }
-           //9.清扫
-           if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
-           {
-               LOG_W("异常退出!!!\n");
-               return;
-           }
-            #if 0//LAMP_EN == 0
-            ctr_Fan_PUT(OFF);
-            ctr_Fan_IN(OFF);
-            #endif
-           if(device_status.version_type==4||device_status.version_type==41)
-           {
-               device_status.clear_status=1;
-               while(device_status.clear_status==1){
-                   rt_thread_delay(1000);
-               }
-           }
-    }
-    else {
-        if(device_status.power_status==1)
-        {
-            //1.打开路由器供电
-            ctr_router(ON);
-            ctr_RTU_DTU(ON);
-            //2.打开相机供电
-            ctr_photo(ON);
-        }
-        //5.关闭加热
-        //6.关闭补光灯
-        ctr_led(OFF);
-    }
+    //1.打开路由器供电
+    ctr_router(ON);
+    //2. 打开RTU供电
+    ctr_RTU_DTU(ON);
+    //3.打开光栅供电
+    ctr_photo(ON);
+    //5.关闭加热
+    //6.关闭补光灯
+    ctr_led(OFF);
 }
 /*三色光源*/
 void Led_Check(uint8_t tp)
@@ -1783,243 +1581,6 @@ void WorkCheck(void)
     rt_thread_delay(1000);
 }
 
-//工作任务流程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");
-        }
-        //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);
-            }
-        }
-        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)
-    {
-        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)
 {
@@ -2043,75 +1604,51 @@ static void pin_guangshan_unbind(void)
 }
 
 
-/*
- * 灯管
- *
- * */
-void WorkTask_CB5(void)
+
+//拍照性诱工作任务流程
+void WorkTask_XYV3(void)
 {
-    static int work_loop = 0;
-    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)
-    {
-        work_loop++;
-        device_status.work_done = 0;
-        //发送串口消息,通知yolo是被及相机采集模块启动,定期将模块的运行状态展示到屏幕上
-        if(work_loop%60==0||work_loop==1)
-        {
-            DTU_Write("{\"cmd\":\"workstart\"}");
-            //推杆电机1打开,导流板到落虫通道
-            device_status.ctr_up_motor = 1;
-            while(device_status.ctr_up_motor!=0)
-            {
-                rt_thread_delay(2000);
-                LOG_I("等待上仓门打开....");
+    int cal_n = device_status.cul_time * 60;
+    LOG_I("工作状态:%d",device_status.work_status);
+    LOG_I("开关机状态:%d",device_status.ds);
+    while(device_status.work_status==1&&device_status.bat_status==0&&device_status.ds==1&&device_status.temp_status==0)
+    {
+        //高压板通电
+        ctr_lamp(ON, 1);     //清扫-DC12v电机正反转
+        //光栅传感器通电
+        ctr_photo(ON);
+        //拍照(?触发条件)计数?没有虫呢?定时
+        while(1){
+            cal_n--;
+            LOG_I("诱虫检测计数剩余时间:%d S",cal_n);
+            if(cal_n==0){
+                //自动进入省电模式
+                device_status.sleep_mode = 1;
+                //发送拍照计数指令
+                device_status.photo_ws = 2;
+                cal_n = device_status.cul_time * 60;
+            }
+            if(device_status.sleep_mode>0){
+                if(cal_n==120){
+                    ctr_router(ON);
+                    ctr_RTU_DTU(ON);
+                }
             }
-            //推杆电机2关闭,益虫仓门关闭
-            device_status.ctr_down_motor = 2;
-            while(device_status.ctr_down_motor!=0)
+
+            if(device_status.sleep_mode==10)
             {
-                rt_thread_delay(2000);
-                LOG_I("等待益虫仓门打开....");
+                rt_thread_delay(5000);
+                ctr_router(OFF);
+                ctr_RTU_DTU(OFF);
+                device_status.sleep_mode = 1;
             }
-            //打开86步进电机驱动器供电
-            ctr_Motor_Driver_Power(ON);
-            //风机启动
-            //打开灯管
-            ctr_lamp(ON,1);
-            //打开补光灯
-            ctr_led(ON);
-            //光栅启动
-            ctr_photo(ON);
-            //
-            pin_guangshan_bind();
-            pin_motor_86_bind();
-        }
 
-        rt_thread_delay(1000);
-    }
-    device_status.work_status = 0;
-    //工作结束
-    if(device_status.work_done==0&&device_status.work_status==0)
-    {
-        pin_guangshan_unbind();
-        pin_motor_86_unbind();
-        //打开推杆电机,益虫放生
-        device_status.ctr_down_motor = 1;
-        DTU_Write("{\"cmd\":\"workdone\"}");
-        ResetInit();
-    }
-    work_loop = 0;
-    while(device_status.work_status==0)
-    {
-        work_loop++;
-        LOG_I("WorkTask_CB5 sleeping......%d",work_loop);
-        if(work_loop>120)
-        {
-            work_loop = 0;
-            DTU_Write("{\"cmd\":\"workdone\"}");
+            if(device_status.temp_status==1 || device_status.bat_status==1 ||device_status.work_status==0) break;
+            rt_thread_delay(1000);
         }
-        rt_thread_delay(5000);
     }
-
+    ctr_lamp(OFF, 1);
+    ctr_photo(OFF);
 }
 
 /* 入口函数-工作状态检测 */
@@ -2143,78 +1680,98 @@ static void Work_Loop_thread_entry(void *parameter)
     ResetInit();
     while(1)
     {
-        if(device_status.version_type!=5&&device_status.dtype==3)
-        {
-            WorkTask();
-        }
-
-        if(device_status.version_type==5)
-        {
-            WorkTask_CB5();
-        }
+        WorkTask_XYV3();
         rt_thread_delay(1000);
     }
 }
 /*入口函数清扫*/
 static void Control_Clear_thread_entry(void *parameter)
 {
+
+    static int selfcheck_cnt = 0;
     while(1)
     {
-        if(device_status.update_flag==1) break;
-        if(device_status.clear_status==1)
+        if(device_status.selfcheck_ws==1){
+            selfcheck_cnt++;
+        }else{
+            selfcheck_cnt = 0;
+        }
+        if(selfcheck_cnt>1200)   //超过3分钟
         {
-            if(device_status.version_type==41){
-                ctr_TG_Clear(300);
-            }else {
-                ctr_TG_Clear(200);
-            }
-
+            device_status.selfcheck_ws = 0;
+            device_status.camera_sta = 1;   //相机异常
+           //上报自检结果
+           //上报自检结果
+           char *json_temp = makeJson_selfCheck_(1);
+           DTU_Write("%s",json_temp);
+           free(json_temp);
+        }
+        if(device_status.clear_status==10){
+            //ctr_turn(90,0);
+            Motor_shake(1,800);
+            device_status.clear_status = 0;
         }
         rt_thread_delay(100);
     }
 }
+
 /*入口函数加热*/
 static void Control_Heat_thread_entry(void *parameter)
 {
-    static int total_seconds = 200;
-    static int current_second = 0;
-    static int process = 0;
+    rt_pin_mode(SIGNAL_GaoYa, PIN_MODE_INPUT);
+    rt_pin_mode(SIGNAL_GuangShan, PIN_MODE_INPUT);
+    static int GaoyYa_cnt,GuangShan_cnt = 500; //10s
+    bool GaoYa = false;
+    bool GuangShan = false;
     while(1)
     {
-        if(device_status.update_flag==1) break;
-        if(device_status.work_status==1&&device_status.heat_sw==1)
+
+        if(rt_pin_read(SIGNAL_GaoYa)==0)
+        {
+            LOG_I("检测到高压计数!");
+            GaoYa = true;
+        }
+
+        if(rt_pin_read(SIGNAL_GuangShan)==0)
         {
-            ctr_lamp(ON, 1);
-            rt_thread_delay(10000);
-            calorstat(device_status.heattime*60);
+            LOG_I("检测到光栅计数!");
+            GuangShan = true;
         }
-        else
+
+        if(GaoYa)
         {
-            if(device_status.selfcheck_ws==2)
+            GaoyYa_cnt --;
+            if(GaoyYa_cnt==0)
             {
-                while(current_second <= total_seconds)
-                {
-                    process = (current_second * 100) / total_seconds;
-                    device_status.process = process / 100.0;
-                    LOG_I("process:%d",process);
-                    HMI_WRITE("selfcheck.s106.val=%d",process);
-                    rt_thread_delay(1000);
-                    current_second++;
-                    if(device_status.selfcheck_ws==0)
-                    {
-                        HMI_WRITE("selfcheck.s106.val=100");
-                        break;
-                    }
-                }
-                HMI_WRITE("selfcheck.s106.val=100");
-            }else {
-                process = 0;
-                current_second = 0;
+                GaoyYa_cnt = 500;
+                GaoYa = false;
             }
+        }
 
+        if(GuangShan)
+        {
+            GuangShan_cnt--;
+            if(GuangShan_cnt==0)
+            {
+                GuangShan_cnt = 500;
+                GuangShan = false;
+            }
         }
-        rt_thread_delay(1000);
 
+        if(GaoYa&&GuangShan)
+        {
+            device_status.all_ycct += 1;   //计数值增加
+            //拍照
+            if(device_status.all_ycct>=1){
+                //device_status.photo_ws = 1;
+            }
+            GaoYa = false;
+            GuangShan = false;
+            GaoyYa_cnt = 500;
+            GuangShan_cnt = 500;
+            rt_thread_delay(1000);
+        }
+        rt_thread_delay(20);
     }
 }
 

+ 15 - 16
Application_cbd_apm32f1/applications/control.h

@@ -18,7 +18,7 @@
 
 
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
-#define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
+#define PCB_V1           1             //1-旧PCB,0-新PCB(模块化)
 #define MATCH_DEVICE     0             //比赛设备
 #define SENSOR_EN        1             //温湿度:0关闭,1打开
 
@@ -28,20 +28,11 @@
 #define LAMP_CURRENT    400
 #endif
 ////////////////////////////////////////////////////////////////
-#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.5.41(HK)"            //4.0海康-1200W
-    #define VERSION_HK_2000W    "2.15.4(2000W)"         //4.0水稻
-#endif
 
-#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
+#define VERSION  "2.0.0"
 
-extern rt_event_t event_485_play;
 
+extern rt_event_t event_485_play;
 
 /*********************************************************************/
 typedef struct  _packed
@@ -115,15 +106,19 @@ typedef struct  _packed
     uint8_t account_status;         //卡状态
     uint8_t test_flag;              //测试标志
     uint8_t sensor_485_sta;         //485传感器
-    uint8_t Power_Type;      //供电类型
-    uint8_t handle_bugger;   //排虫模式,0推杆收回来是排虫,1推出去是收虫
+    uint8_t yc_ct;                //诱虫次数
+    uint8_t all_ycct;             //诱虫计数
+    uint8_t InsectSpecies;        //昆虫种类
+    uint8_t Power_Type;           //供电类型
+    uint8_t camera_sta;           //拍照报警
+    uint8_t led_sta;              //补光灯报警
+    uint8_t selfcheck_ws;          //自检
     uint8_t collt_box_sta;   //收虫仓状态
     uint8_t camsta;          //拍照报警,0正常,1异常
     uint8_t heat_sta;        //加热报警0-正常,1-异常
-    uint8_t led_sta;         //补光灯报警0-正常,1-异常
-    uint8_t selfcheck_ws;    //自检开关1-北大荒,2-标配
     uint8_t gps_inuse;
     uint8_t gps_view;
+    uint8_t sleep_mode;      //省电模式:0-关 1-开,> 1 超时时间
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间
     uint16_t thsp;           //息屏时间
@@ -166,6 +161,7 @@ typedef struct  _packed
     char voltage[6];           //电池电压
     char deviceId[32];         //bdh-设备编码
     char voltage_sun[8];       //太阳能板电压
+    char cpu_temp[8];
     char qianming[128];
     char photolink[128];        //图片地址
 }Device_Status_typedef;
@@ -256,6 +252,9 @@ uint8_t ctr_Camera_Power(uint8_t status_ws);
 #define GUANG_SHAN GET_PIN(C,13)       //光栅
 #define MOTOR_86   GET_PIN(B,9)        //85电机限位
 void ctr_Motor_Driver_Power(uint8_t status_ws);
+/****************************性诱3.0********************************/
+#define SIGNAL_GaoYa GET_PIN(B,5)
+#define SIGNAL_GuangShan GET_PIN(B,8)
 /*****************************孢子仪**********************************/
 //制冷
 #define Cold_Pin GET_PIN(B,11)

+ 115 - 348
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -447,11 +447,10 @@ static void dtu_thread_entry_send(void *parameter)
     device_status.num_updata = 0;
     static uint16_t current_arry[10];
     static uint8_t record_current = 0;
-    static uint8_t lamp_sta_cnt = 0;
     rt_thread_delay(10000);
     static rt_uint16_t wait_i = 0;
     static rt_uint8_t check_i = 0;
-    static rt_uint8_t power_i = 0;
+
     while(1)
     {
         time_t now_t;
@@ -480,52 +479,14 @@ static void dtu_thread_entry_send(void *parameter)
                 {
                     HMI_WRITE("sleep=%d",1);
                 }
-                LOG_I("掉电检测:%d-%d",atoi(device_status.voltage),device_status.power_status);
-                //检测到电源掉电
-                if(atoi(device_status.voltage)<5&&device_status.power_status==1)
-                {
-                    power_i++;
-                    //确定网络状态
-                    if(power_i==10)
+                if(device_status.sleep_mode == 1) {
+                    if(device_status.num_updata==120)
                     {
-                        device_status.bat_status = 1;
-                        rt_sprintf(device_status.net, "1");
-                        HMI_WRITE("sleep=%d",1);    //屏幕休眠
-                        DTU_Write("%s",makeJson_Warn("power down","power"));
-                        device_status.power_status = 0;
-                        rt_thread_delay(5000);
-                        ctr_router(OFF);
-                        ctr_RTU_DTU(OFF);
-                        power_i = 0;
-                    }
-                }
-                if(atoi(device_status.voltage)>12&&device_status.power_status==0)      //电压正常
-                {
-                    device_status.power_status = 1;
-                    ctr_router(ON);
-                    ctr_RTU_DTU(ON);
-                    power_i = 0;
-                }
-                if(device_status.work_status==1&&device_status.num_updata%10==0&&atoi(device_status.power)>20)    //每过10S把电流值存入数组,连续10条数据的电流值大于400mA判断为正常
-                {
-                    current_arry[record_current] = atoi(device_status.power);
-                    record_current++;
-                    if(record_current==10)
-                    {
-                        record_current = 0;
-                        if(hasElementGreaterThan400(current_arry, 10)==0)   //连续10条电流值大于400,灯管状态正常
-                        {
-                            device_status.lamp = 0;
-                            lamp_sta_cnt = 0;
-                        }
-                        if(hasElementGreater_lessThan400(current_arry,10)==0)   //连续10条电流值小于400,灯管状态异常
-                        {
-                            lamp_sta_cnt++;
-                        }
-                        if(lamp_sta_cnt>=3) device_status.lamp = 1;
-                        memset(current_arry,0,sizeof(current_arry));
+                        ctr_router(ON);
+                        ctr_RTU_DTU(ON);
                     }
                 }
+
             }
             else {
                 char *readinfo =  makeJson_ReadInfo();
@@ -544,39 +505,26 @@ static void dtu_thread_entry_send(void *parameter)
                     rt_free(res_fuse_warn);
                 }
                 device_status.num_updata = device_status.dattim * 60;
-                if(device_status.dattim==0) device_status.dattim=20;   //数据上传时间间隔设置为0?
-                if(device_status.bat_status==0) device_status.power_status = 1;     //解除欠压,清除标志位
-            }
-        }
-    else {
-            wait_i ++;
-            LOG_I("wait connect internet......%d",wait_i);
-            //检测到电源掉电
-            if(Read_Real_Voltage()/100<5&&device_status.power_status==1&&wait_i>200)
-            {
-                check_i++;
-                LOG_W("断网状态下检测到设备断电!%d",atoi(device_status.voltage));
-                if(check_i==10)
-                {
-                    device_status.bat_status = 1;
-                    device_status.power_status = 0;
+                if(device_status.dattim==0) device_status.dattim=30;   //数据上传时间间隔设置为0?
+
+                if(device_status.sleep_mode == 1) {
                     rt_thread_delay(5000);
                     ctr_router(OFF);
                     ctr_RTU_DTU(OFF);
-                    check_i = 0;
                 }
             }
-            if(Read_Real_Voltage()/100>10&&device_status.power_status==0)
-            {
-                check_i = 0;
-                LOG_I("电源恢复正常,打开路由器和RTU供电!");
-                device_status.power_status = 1;
-                //打开路由器和RTU供电
-                ctr_router(ON);
-                ctr_RTU_DTU(ON);
+        }
+    else {
+            wait_i ++;
+            if(device_status.sleep_mode == 1){
+                if(wait_i==3500){
+                    ctr_router(ON);
+                    ctr_RTU_DTU(ON);
+                }
             }
+            LOG_I("wait connect internet......%d",wait_i);
         }
-    rt_thread_mdelay(1000);
+        rt_thread_mdelay(1000);
     }
 }
 
@@ -681,6 +629,26 @@ char * makeJson_ReadInfo()
     cJSON_Delete(rJsonRoot);
     return r;
 }
+
+char *makeJson_ParsePhoto()
+{
+    cJSON * rJsonRoot = NULL;
+    rJsonRoot = cJSON_CreateObject();
+    if(NULL==rJsonRoot)
+    {
+        return NULL;
+    }
+    cJSON_AddStringToObject(rJsonRoot, "cmd", "ParsePhoto");
+    char * r = cJSON_PrintUnformatted(rJsonRoot);
+    if(NULL == r)
+    {
+        cJSON_Delete(rJsonRoot);
+        return NULL;
+    }
+    cJSON_Delete(rJsonRoot);
+    return r;
+}
+
 //{"cmd": "platform", "ext": {"type": "120.27.222.26"}}
 char * makeJson_platform(char *plt)
 {
@@ -969,12 +937,6 @@ char * makeJson()
     if(device_status.gps==NULL)
     rt_sprintf(device_status.gps, "0");
 
-    if(device_status.work_status==0) {
-        device_status.lamp = 0;
-    }
-    if(atoi(device_status.power)>5000)
-        rt_sprintf(device_status.power,"0.01");
-
     makejson_sta = 1;
     time_t stamp=time(RT_NULL);
     static struct tm tm;
@@ -989,56 +951,6 @@ char * makeJson()
         return NULL;
     }
     memset(device_status.driver,0,sizeof(device_status.driver));
-    if(device_status.version_type==1)
-    {
-        rt_sprintf(device_status.driver,"%s-%s",VERSION_ZP,device_status.driver_4g);
-    }
-    else if (device_status.version_type==4) {
-        rt_sprintf(device_status.driver,"%s-%s",VERSION_HK_2000W,device_status.driver_4g);
-    }
-    else if (device_status.version_type==41) {
-        rt_sprintf(device_status.driver,"%s-%s",VERSION_HK,device_status.driver_4g);
-    }
-    else if (device_status.version_type==11) {
-        rt_sprintf(device_status.driver,"%s-%s",VERSION_GK,device_status.driver_4g);
-    }
-    else if (device_status.version_type==5) {
-        rt_sprintf(device_status.driver,"%s-%s",VERSION_V5,device_status.driver_4g);
-        cJSON_AddStringToObject(pJsonRoot, "DEVICE_SERIAL_NUMBER", device_status.imei);
-        cJSON_AddStringToObject(pJsonRoot, "VERSION", device_status.driver);
-        cJSON_AddStringToObject(pJsonRoot, "SIGNAL", device_status.csq);
-        cJSON_AddStringToObject(pJsonRoot, "SIM", device_status.iccid);
-        static char iso8601_time[32];  // 确保缓冲区足够大以容纳时间字符串
-        get_iso8601_utc_time(iso8601_time, sizeof(iso8601_time),24);
-        cJSON_AddStringToObject(pJsonRoot, "UPDATE_DATE", iso8601_time);
-        cJSON_AddStringToObject(pJsonRoot, "STATUS", "STATUS_ONLINE");
-        cJSON_AddStringToObject(pJsonRoot, "STATUS_DESCRIPTION","设备运行正常");
-        cJSON_AddStringToObject(pJsonRoot, "LOCATION","113.0,34.0");
-        static char iso8601_time_s[32];  // 确保缓冲区足够大以容纳时间字符串
-        get_iso8601_utc_time(iso8601_time_s, sizeof(iso8601_time_s),device_status.startBar);
-        cJSON_AddStringToObject(pJsonRoot, "START_TIME",iso8601_time_s);
-        get_iso8601_utc_time(iso8601_time_s, sizeof(iso8601_time_s),device_status.stopBar);
-        cJSON_AddStringToObject(pJsonRoot, "END_TIME",iso8601_time_s);
-
-        cJSON_AddNumberToObject(pJsonRoot, "CONTRIL", !device_status.timeSwitch);
-        cJSON_AddNumberToObject(pJsonRoot, "TT", device_status.sunBar);
-        cJSON_AddNumberToObject(pJsonRoot, "WS", device_status.work_status);
-        cJSON_AddNumberToObject(pJsonRoot, "TPS", device_status.tpl);
-        cJSON_AddNumberToObject(pJsonRoot, "RPS", device_status.rain_status);
-        cJSON_AddNumberToObject(pJsonRoot, "LPS", device_status.sun_status);
-        cJSON_AddNumberToObject(pJsonRoot, "TEMPERATURE", 20.2);
-        cJSON_AddNumberToObject(pJsonRoot, "HUMIDITY", 60.2);
-        char *p = cJSON_PrintUnformatted(pJsonRoot);
-        if(NULL == p)
-        {
-            cJSON_Delete(pJsonRoot);
-            rt_kprintf("cJSON_Delete NULL!!!\n");
-            return NULL;
-        }
-        cJSON_Delete(pJsonRoot);
-        return p;
-    }
-
 
     cJSON * pSubJson = NULL;
     pSubJson = cJSON_CreateObject();
@@ -1057,6 +969,7 @@ char * makeJson()
         cJSON_AddStringToObject(pJsonRoot, "cmd", "data");
     }
 
+    rt_sprintf(device_status.driver,"%s-%s",VERSION,device_status.driver_4g);
 
     if(device_status.sensor_485_sta!=0)
     {
@@ -1070,158 +983,66 @@ char * makeJson()
     rt_sprintf(utos, "%d",device_status.dtype);
     cJSON_AddStringToObject(pSubJson,"dtype",utos);
     //类型细分
-    if(device_status.version_type==4)          //水稻
-    {
-        rt_sprintf(utos,"4");
-        cJSON_AddStringToObject(pSubJson,"vtype",utos);
-    }
-    else if (device_status.version_type==1) {   //1.0
-        rt_sprintf(utos,"1");
-        cJSON_AddStringToObject(pSubJson,"vtype",utos);
-    }
-    else if (device_status.version_type==11) {  //高空
-        rt_sprintf(utos,"11");
-        cJSON_AddStringToObject(pSubJson,"vtype",utos);
-    }
-    else if (device_status.version_type==5) {   //5.0
-        rt_sprintf(utos,"5");
-        cJSON_AddStringToObject(pSubJson,"vtype",utos);
-    }
-    else if (device_status.version_type==6) {   //吸虫塔
-        rt_sprintf(utos,"6");
-        cJSON_AddStringToObject(pSubJson,"vtype",utos);
-    }
-    if(device_status.version_type!=6&&device_status.dtype!=7)
-    {
-        //光控定时
-        rt_sprintf(utos, "%d",device_status.sunBar);
-        cJSON_AddStringToObject(pSubJson,"tt",utos);
-        //定时模式
-        rt_sprintf(utos, "%d",device_status.timeSwitch);
-        cJSON_AddStringToObject(pSubJson,"ts",utos);
-        //温控
-        rt_sprintf(utos, "%d",device_status.temp_status);
-        cJSON_AddStringToObject(pSubJson,"tps",utos);
-        //光控状态
-        rt_sprintf(utos, "%d",device_status.sun_status);
-        cJSON_AddStringToObject(pSubJson,"lps",utos);
-        //雨控状态
-        rt_sprintf(utos, "%d",device_status.rain_status);
-        cJSON_AddStringToObject(pSubJson,"rps",utos);
-        //电池状态
-        rt_sprintf(utos, "%d",device_status.bat_status);
-        cJSON_AddStringToObject(pSubJson,"batStatus",utos);
-        //灯管状态
-        rt_sprintf(utos, "%d",device_status.lamp);
-        cJSON_AddStringToObject(pSubJson,"lamp",utos);
-        //上仓门状态 1-打开,0-关闭-(通道) 打开为落虫,关闭为排水
-        rt_sprintf(utos, "%d",device_status.up_status);
-        cJSON_AddStringToObject(pSubJson,"upds",utos);
-        //下仓门状态 1-打开,0-关闭
-        rt_sprintf(utos, "%d",device_status.down_status);
-        cJSON_AddStringToObject(pSubJson,"dnds",utos);
-        //加热仓温度
-        if(device_status.run_sta>device_status.heattem)
-        {
-            rt_sprintf(utos, "%d",device_status.run_sta);
-            device_status.run_sta = 0;
-        }
-        else {
-            rt_sprintf(utos, "%d",device_status.heattem);
-        }
-        cJSON_AddStringToObject(pSubJson,"hrt",utos);
-        //加热状态
-        rt_sprintf(utos, "%d",device_status.heat_status);
-        cJSON_AddStringToObject(pSubJson,"hs",utos);
-        //收集时间(参数)
-        rt_sprintf(utos, "%d",device_status.clt_time);
-        cJSON_AddStringToObject(pSubJson,"collt",utos);
-        //加热时间(参数)
-        rt_sprintf(utos, "%d",device_status.heattime);
-        cJSON_AddStringToObject(pSubJson,"htim",utos);
-        //加热温度(参数)
-        rt_sprintf(utos, "%d",device_status.heatvalue);
-        cJSON_AddStringToObject(pSubJson,"hst",utos);
-        //高温保护
-        rt_sprintf(utos, "%d",device_status.tph);
-        cJSON_AddStringToObject(pSubJson,"tph",utos);
-        //低温保护
-        rt_sprintf(utos, "%d",device_status.tpl);
-        cJSON_AddStringToObject(pSubJson,"tpl",utos);
-    }
-    if(device_status.dtype==3)
-    {
-        //工作状态
-        rt_sprintf(utos, "%d",device_status.work_status);
-        cJSON_AddStringToObject(pSubJson,"ws",utos);
-        //保险丝电压
-        cJSON_AddStringToObject(pSubJson,"fuse_voltage",device_status.fuse_voltage);
-        //开始时间
-        rt_sprintf(utos, "%d",device_status.startBar);
-        cJSON_AddStringToObject(pSubJson,"st",utos);
-        //结束时间
-        rt_sprintf(utos, "%d",device_status.stopBar);
-        cJSON_AddStringToObject(pSubJson,"et",utos);
-    }
-    else if(device_status.dtype==7)
-    {
-        char ct1[10],ct2[10];
-        rt_sprintf(ct1,"%d-%d",device_status.collecting_sh1,device_status.collecting_eh1);
-        rt_sprintf(ct2,"%d-%d",device_status.collecting_sh2,device_status.collecting_eh2);
-        rt_kprintf("ct1-ct2:%s\n",ct1);
-        device_status.coll_time[0] = ct1;
-        device_status.coll_time[1] = ct2;
-        cJSON *data_clt = NULL;
-        data_clt = cJSON_CreateStringArray(device_status.coll_time,2);
-        //工作状态
-        rt_sprintf(utos, "%d",device_status.work_status);
-        cJSON_AddStringToObject(pSubJson,"work_sta",utos);
-        //运行状态
-        rt_sprintf(utos, "%d",device_status.run_sta);
-        cJSON_AddStringToObject(pSubJson,"run_sta",utos);
-        //箱体温度-box_tem
-        rt_sprintf(utos, "%d",device_status.box_temp);
-        cJSON_AddStringToObject(pSubJson,"box_tem",utos);
-        //培养时间-cul_time
-        rt_sprintf(utos, "%d",device_status.cul_time);
-        cJSON_AddStringToObject(pSubJson,"cul_time",utos);
-        //制冷状态
-        rt_sprintf(utos, "%d",device_status.cold_sw);
-        cJSON_AddStringToObject(pSubJson,"cold_sw",utos);
-        //电压状态-batStatus
-        rt_sprintf(utos, "%d",device_status.bat_status);
-        cJSON_AddStringToObject(pSubJson,"batStatus",utos);
-        //已培养时间-staytime
-        rt_sprintf(utos, "%d",device_status.stay_time);
-        cJSON_AddStringToObject(pSubJson,"stay_time",utos);
-        //风机开关
-        rt_sprintf(utos, "%d",device_status.wind_sw);
-        cJSON_AddStringToObject(pSubJson,"wind_sw",utos);
-        //培养仓温度
-        rt_sprintf(utos, "%d",device_status.pre_temp);
-        cJSON_AddStringToObject(pSubJson,"pre_temp",utos);
-        //分辨率
-        cJSON_AddStringToObject(pSubJson,"imgres","0");
-        //usb
-        cJSON_AddStringToObject(pSubJson,"usb_sta","0");
-        //雨控状态-rps
-        rt_sprintf(utos, "%d",device_status.rain_status);
-        cJSON_AddStringToObject(pSubJson,"rps",utos);
-        //收集时间
-        cJSON_AddItemToObject(pSubJson,"coll_time",data_clt);
-        //设定温度
-        rt_sprintf(utos, "%d",device_status.heatvalue);
-        cJSON_AddStringToObject(pSubJson,"set_temp",utos);
-    }
-    if(device_status.dtype!=7)
-    {
-        //震动开关
-        rt_sprintf(utos, "%d",device_status.shake_ws);
-        cJSON_AddStringToObject(pSubJson,"shake",utos);
-    }
-    //震动时间
-    rt_sprintf(utos, "%d",device_status.shake_sec);
-    cJSON_AddStringToObject(pSubJson,"shake_sec",utos);
+
+
+    //电流(当前)
+    cJSON_AddStringToObject(pSubJson,"cc",device_status.power);
+    //电压
+    cJSON_AddStringToObject(pSubJson,"bv",device_status.voltage);
+    //电压状态-batStatus
+    rt_sprintf(utos, "%d",device_status.bat_status);
+    cJSON_AddStringToObject(pSubJson,"bs",utos);
+    //工作状态
+    rt_sprintf(utos, "%d",device_status.work_status);
+    cJSON_AddStringToObject(pSubJson,"ws",utos);
+    //开始时间
+    rt_sprintf(utos, "%d",device_status.startBar);
+    cJSON_AddStringToObject(pSubJson,"st",utos);
+    //结束时间
+    rt_sprintf(utos, "%d",device_status.stopBar);
+    cJSON_AddStringToObject(pSubJson,"et",utos);
+    //cs:充电标志位 0:非充电 1:充电
+    cJSON_AddStringToObject(pSubJson,"cs","0");
+    //rps雨控状态 0:正常 1:保护
+    rt_sprintf(utos, "%d",device_status.rain_status);
+    cJSON_AddStringToObject(pSubJson,"rps",utos);
+    //定时模式
+    rt_sprintf(utos, "%d",device_status.timeSwitch);
+    cJSON_AddStringToObject(pSubJson,"ts",utos);
+    //温控
+    rt_sprintf(utos, "%d",device_status.temp_status);
+    cJSON_AddStringToObject(pSubJson,"tps",utos);
+    //倾倒状态
+    cJSON_AddStringToObject(pSubJson,"dps","0");
+    //cv 充电电压 单位:V 字符串类型
+    cJSON_AddStringToObject(pSubJson,"cv",device_status.voltage_sun);
+    //volt_ct电击计数值
+    rt_sprintf(utos, "%d",device_status.all_ycct);
+    cJSON_AddStringToObject(pSubJson,"volt_ct",utos);
+
+    //清虫间隔
+    rt_sprintf(utos, "%d",device_status.cul_time);
+    cJSON_AddStringToObject(pSubJson,"clt_t",utos);
+    //主板温度
+    rt_sprintf(utos, "%d.%d",Get_Temprate()/100,Get_Temprate()%100);
+    cJSON_AddStringToObject(pSubJson,"bt",utos);
+    //volt_freq
+    cJSON_AddStringToObject(pSubJson,"volt_freq","3");
+    //barometric
+//        cJSON_AddStringToObject(pSubJson,"barometric","0");
+    //wind_drec
+    cJSON_AddStringToObject(pSubJson,"wind_drec","0");
+    //wind_sped
+    cJSON_AddStringToObject(pSubJson,"wind_sped","0");
+    //cpu_temp
+    cJSON_AddStringToObject(pSubJson,"cpu_tmp",device_status.cpu_temp);
+    //camera_sta
+    cJSON_AddStringToObject(pSubJson,"cam_sta",device_status.camera_sta);
+    //InsectSpecies,昆虫种类
+    cJSON_AddNumberToObject(pSubJson,"InsectSpecies",device_status.InsectSpecies);
+    cJSON_AddNumberToObject(pSubJson,"Power_Type",device_status.Power_Type);
+    cJSON_AddStringToObject(pSubJson,"deviceId",device_status.deviceId);
+
     cJSON_AddStringToObject(pSubJson,"gps",device_status.gps);              //定位状态
     //开关状态
     rt_sprintf(utos, "%d",device_status.ds);
@@ -1239,23 +1060,13 @@ char * makeJson()
     cJSON_AddStringToObject(pSubJson,"lat",device_status.lat);
     //是否为上电开机
     cJSON_AddNumberToObject(pSubJson,"rcnt",device_status.rebootcnt);
-    //电流(当前)
-    cJSON_AddStringToObject(pSubJson,"current",device_status.power);
-    #if PCB_V1 == 0
-    //加热电流(当前)
-    cJSON_AddStringToObject(pSubJson,"current_heat",device_status.heat_power);
-    #endif
-    //电压
-    cJSON_AddStringToObject(pSubJson,"vbat",device_status.voltage);
+
     //数据上传间隔
     rt_sprintf(utos, "%d",device_status.dattim);
     cJSON_AddStringToObject(pSubJson,"dat_f",utos);
     //信号强度
     cJSON_AddStringToObject(pSubJson,"csq",device_status.csq);
-    #if 0
-    //太阳能板电压
-    cJSON_AddStringToObject(pSubJson,"cv",device_status.voltage_sun);
-    #endif
+
     char *p = cJSON_PrintUnformatted(pJsonRoot);
     if(NULL == p)
     {
@@ -1481,27 +1292,12 @@ int parseDtu(char *json_string)
 
           if(ledsta!=NULL)
           {
-              rt_timer_stop(timer_takephoto);
-              HMI_WRITE("selfcheck.t3.bco=2024");
-              device_status.C01 &= ~(1<<2);
-              if(ledsta->valueint==0)
-              {
-                  HMI_WRITE("selfcheck.t4.bco=2024");
-                  device_status.C01 &= ~(1<<3);
-              }
-              else
-              {
-                  HMI_WRITE("selfcheck.t4.bco=63488");
-                  device_status.C01 |= (1<<3);
-              }
-
               device_status.led_sta = ledsta->valueint;
               LOG_I("补光灯报警状态:%d",device_status.led_sta);
           }
           if(photolink!=NULL){
-              device_status.camsta = 0; //拍照正常
-              device_status.ctr_up_motor = 0;   //关闭
-              device_status.ctr_down_motor = 0; //关闭
+              device_status.selfcheck_ws = 0;
+              device_status.camera_sta = 0; //拍照正常
               rt_sprintf(device_status.photolink,"%s",photolink->valuestring);
               LOG_I("接收到图片地址:%s",device_status.photolink);
               //上报自检结果
@@ -1510,7 +1306,7 @@ int parseDtu(char *json_string)
                   DTU_Write("%s",json_temp);
                   free(json_temp);
               }
-
+              if(device_status.work_status==0) ctr_lamp(OFF, 1);  //关闭高压
           }
           if(item_checkself!=NULL){//自检签名
               memset(device_status.qianming,0,sizeof(device_status.qianming));
@@ -1521,9 +1317,9 @@ int parseDtu(char *json_string)
               char *json_temp = makeJson_selfCheck_(0);
               DTU_Write("%s",json_temp);
               free(json_temp);
-              ctr_lamp(ON, 1);
-              ctr_Heat(OFF);
-              //执行自检
+              ctr_lamp(OFF,1);
+              rt_thread_delay(1000);
+              ctr_lamp(ON, 1);  //开启高压
               device_status.selfcheck_ws = 1;
           }
           //item_data = cJSON_GetObjectItem(root,"data");
@@ -1603,18 +1399,7 @@ int parseDtu(char *json_string)
                       rt_free(photo);
                       rt_thread_delay(2000);
                   }
-                  //{"ext": {"type": "turn"}, "cmd": "ctrl"}   转仓
-                  else if(strstr(type->valuestring,"turn")!=RT_NULL)
-                  {
-                      #if Color_EN == 0
-                      char *turn_zp = makeJson_Warn("send cmd success:turn_zp","control");
-                      DTU_Write("%s",turn_zp);
-                      rt_free(turn_zp);
-                      ctr_turn(90, 0);
-                      #else
-                      DTU_Write("黄板复位:%d",ctr_Color_board(RESET, 800));
-                      #endif
-                  }
+
                   //{"ext": {"type": "paichong"}, "cmd": "ctrl"}   排虫
                   else if (strstr(type->valuestring,"paichong")!=RT_NULL) {
                       char *turn_zp = makeJson_Warn("send cmd success:paichong","control");
@@ -1632,29 +1417,11 @@ int parseDtu(char *json_string)
                   {
                       ctr_led(OFF);
                   }
-                  else if(strstr(type->valuestring,"selfcheck")!=RT_NULL)
-                  {
-                      if(device_status.selfcheck_ws == 2)
-                      {
-                          char *js = makeJson_C01_Warn(device_status.C01,device_status.process);
-                          DTU_Write("%s",js);
-                          free(js);
-                      }
-                      else
-                      {
-                          device_status.selfcheck_ws = 2;
-                      }
-                      LOG_I("收到自检指令:%d",device_status.selfcheck_ws);
-                  }
-                  else if(strstr(type->valuestring,"insect_kill")!=RT_NULL)
+                  else if(strstr(type->valuestring,"sleep_mode")!=RT_NULL)
                   {
-                      device_status.autotakepic = 10;
-                      LOG_W("收到害虫信号!");
-                  }
-                  else if(strstr(type->valuestring,"insect_save")!=RT_NULL)
-                  {
-                      device_status.autotakepic = 11;
-                      LOG_W("收到益虫信号!");
+                      device_status.sleep_mode = 1;
+                      ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));           //设备编码
+                      LOG_I("收到设置休眠指令:%d",device_status.sleep_mode);
                   }
               }
               //切换平台
@@ -1878,10 +1645,10 @@ int parseDtu(char *json_string)
                       HMI_WRITE("menu.eth1_sta.val=%d",atoi(value_commn->valuestring));
                   }
                   value_commn = cJSON_GetObjectItem(item_ext,"cpu_tmp");
+                  sprintf(device_status.cpu_temp,"%s",value_commn->valuestring);
                   if(value_commn!=RT_NULL)
                   {
-                      HMI_WRITE("menu.cpu_temp.txt=\"%d.%d℃\"",atoi(value_commn->valuestring)/1000,atoi(value_commn->valuestring)%1000);
-
+                      HMI_WRITE("menu.cpu.txt=\"%d.%d\"",atoi(value_commn->valuestring)/1000,atoi(value_commn->valuestring)%1000);
                   }
                   if(link_ip!=NULL)
                   {

+ 0 - 23
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -24,30 +24,7 @@ typedef struct{
 //    |STATUS_ONLINE""
 //};
 
-//5.0测报灯数据上报结构体
-typedef struct {
-    char DEVICE_SERIAL_NUMBER[32];
-    char SIM[32];
-    char SIGNAL[16];
-    char LOCATION[32];
-    double VOLTAGE;
-    double CURRENT;
-    double TEMPERATURE;
-    double HUMIDITY;
-    char UPDATE_DATE[64];
-    char STATUS[32];
-    char STATUS_DESCRIPTION[64];
-    char START_TIME[64];
-    char END_TIME[64];
-    char VERSION[16];
-    uint8_t DATT;
-    uint8_t TPS;
-    uint8_t LPS;
-    uint8_t RPS;
-    uint8_t WS;
-    uint8_t TT;
 
-}WS_CBDV5;
 
 
 

Разница между файлами не показана из-за своего большого размера
+ 232 - 1035
Application_cbd_apm32f1/applications/hmi.c


+ 6 - 68
Application_cbd_apm32f1/applications/sht30_collect.c

@@ -190,7 +190,6 @@ static void sht30_collect_thread_entry(void *parameter)
 static void Power_ReadCheck(void *parameter)
 {
     int rain_cnt = 0;
-    int bat_cnt = 0;
     int RV;
     MovingAverageFilter* filter = moving_average_filter_init(10);
     //MovingAverageFilter* filter_hi = moving_average_filter_init(10);
@@ -218,77 +217,21 @@ static void Power_ReadCheck(void *parameter)
             sprintf(device_status.heat_power,"%.2f",(float)(Read_Heat_Current()-2450)/0.1);     //2481-2465
         }
         #else
-//        rt_uint16_t _24v_current_int = moving_average_filter_update(filter,Read_Real_Current());
-//        sprintf(device_status.power,"%.2f",(float)_24v_current_int/10);
+
         sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current()/100*2.5))+20.0);
         #endif
         //LOG_I("负载电流:%s,加热电流:%s",device_status.power,device_status.heat_power);
-        if (Read_Real_Voltage()/100<12)
+        if (Read_Real_Voltage()/100<11)
         {
-            //关闭外设
-            ctr_photo(OFF); //关闭相机供电
-            ctr_led(OFF);   //关闭补光灯
-            ctr_Heat(OFF);  //关闭加热
-            ctr_Cold(OFF);  //关闭制冷
-            #if Color_EN == 0
-            ctr_cangmen_down(OFF);  //关闭下仓门输出(转盘)
-            ctr_cangmen_up(OFF);    //关闭上仓门输出(散热)
-            #endif
+            device_status.bat_status = 1; //欠压
         }
-        if(atof(device_status.voltage)<22.0)    //小于22.0V,并且持续10S,欠压
+        else if(atof(device_status.voltage)>=12)    //大于24.0V,解除欠压
         {
-            #if ROBOT_EN == 1
-            ctr_led(OFF);
-            HMI_WRITE("sleep=%d",1);
-            #endif
-            bat_cnt++;
-        }else if(atof(device_status.voltage)>=24.0)    //大于24.0V,解除欠压
-        {
-            bat_cnt = 0;
-            device_status.C01 &= ~(1<<4);
+
             device_status.bat_status = 0; //解除欠压
-            ctr_router(ON);               //打开路由器供电
-            ctr_photo(ON);                //打开相机供电
-        #if ROBOT_EN == 1
-            ctr_led(ON);        //打开补光灯
-            ctr_lamp(ON, 1);    //打开镇流器输出,用于24V转12V给相机供电
-            ctr_router(ON);
-            HMI_WRITE("sleep=%d",0);
-        #endif
         }
         //
-        if(device_status.dtype==7)
-        {
-            //箱体温度
-            RV = 10000 * (4096 - Read_Rain_Voltage()) / Read_Rain_Voltage();
-            if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
-            {
-                LOG_E("temp value err!!!!");
-            }
-            else
-            {
-                device_status.box_temp = TempCalculate(RV, 3950, 10000);
-                if(device_status.box_temp>160)
-                {
-                    device_status.box_temp = 25;
-                }
-            }
-            //培养仓温度
-            RV = 10000 * (4096 - Read_Light_Voltage()) / Read_Light_Voltage();
-            if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
-            {
-                LOG_E("temp value err!!!!");
-            }
-            else
-            {
-                device_status.pre_temp = TempCalculate(RV, 3950, 10000);
-                if(device_status.pre_temp>160)
-                {
-                    device_status.pre_temp = 25;
-                }
-            }
-        }
-        else {
+        if(1){
             RV = 10000 * (4096 - Read_Ntc_Voltage()) / Read_Ntc_Voltage();
             if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
             {
@@ -324,11 +267,6 @@ static void Power_ReadCheck(void *parameter)
                 }
             }
         }
-        if(bat_cnt>=15){  //持续10s
-            bat_cnt = 0;
-            device_status.C01 |= (1<<4);
-            device_status.bat_status = 1; //欠压
-        }
 
         //rt_sprintf(device_status.voltage,"%d.%02d",filter_voltage()/100,filter_voltage()%100);
         rt_uint16_t in_voltage_int = moving_average_filter_update(filter_v,Read_Real_Voltage());

+ 1 - 1
Application_cbd_apm32f1/drivers/board.c

@@ -96,7 +96,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
     //吸虫塔屏蔽下面这行,孢子仪打开
-    __HAL_AFIO_REMAP_TIM3_ENABLE();
+    //__HAL_AFIO_REMAP_TIM3_ENABLE();
 
   /* USER CODE BEGIN TIM3_MspPostInit 1 */
 

+ 7 - 0
Application_cbd_apm32f1/drivers/drv_clk.c

@@ -57,6 +57,13 @@ static void system_clock_config(void)
     }
     //Enables the Clock Security System
 
+    // 使能电源接口时钟和备份区域时钟
+    __HAL_RCC_PWR_CLK_ENABLE();
+    __HAL_RCC_BKP_CLK_ENABLE();
+
+    // 取消备份区域写保护
+    HAL_PWR_EnableBkUpAccess();
+
     HAL_RCC_EnableCSS();
 
     #define NVIC_VTOR_MASK   0x3FFFFF80

+ 2 - 1
Application_cbd_apm32f1/packages/EasyFlash-v4.1.0/src/ef_fal_port.c

@@ -87,7 +87,8 @@ static const ef_env default_env_set[] = {
         {"collecting_eh2","0"},    //
         {"Power_Type","0"},        //供电类型
         {"deviceId","0"},          //BDH设备编码
-        {"handle_bugger","0"}      //虫子处理,收虫,排虫
+        {"InsectSpecies","0"},     //虫子处理,收虫,排虫
+        {"sleep_mode","0"}         //省电模式,0-关,1-开,>1 超时时间
 };
 static char log_buf[RT_CONSOLEBUF_SIZE];
 static struct rt_semaphore env_cache_lock;