zhunk hai 1 ano
pai
achega
67f65f0f0f

BIN=BIN
Application_cbd_apm32f1/.settings/.rtmenus


+ 1 - 1
Application_cbd_apm32f1/.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-472937748808239374" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-434655907455513827" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

+ 2 - 1
Application_cbd_apm32f1/.settings/projcfg.ini

@@ -1,9 +1,10 @@
 #RT-Thread Studio Project Configuration
-#Thu Jan 23 17:40:17 CST 2025
+#Wed Apr 16 08:41:26 CST 2025
 project_type=rtt
 chip_name=STM32F103RE
 cpu_name=None
 target_freq=72
+full_chip_name=STM32F103RETx
 clock_source=hsi
 dvendor_name=STMicroelectronics
 rx_pin_name=PA10

+ 178 - 10
Application_cbd_apm32f1/applications/beep.c

@@ -12,10 +12,80 @@
 #include <control.h>
 #include "hmi.h"
 
+
+#define HWTIMER_DEV_NAME   "timer2"     /* 定时器名称 */
+
+
 Device_Status_typedef device_status;
 
 struct rt_device_pwm    *pwm_device = RT_NULL; //定义 pwm 设备指针
 struct rt_device_pwm    *pwm_tim8 = RT_NULL; //定义 pwm 设备指针
+
+/* 定时器超时回调函数 */
+static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
+{
+    rt_kprintf("this is hwtimer timeout callback fucntion!\n");
+    rt_kprintf("tick is :%d !\n", rt_tick_get());
+    rt_pwm_disable(pwm_device, BEEP_PWM_CH);
+    rt_device_close(dev);
+    return 0;
+}
+
+
+rt_device_t hw_dev = RT_NULL;   /* 定时器设备句柄 */
+
+static int hwtimer_sample(int argc, char *argv[])
+{
+    rt_err_t ret = RT_EOK;
+    rt_hwtimerval_t timeout_s;      /* 定时器超时值 */
+    rt_device_t hw_dev = RT_NULL;   /* 定时器设备句柄 */
+    rt_hwtimer_mode_t mode;         /* 定时器模式 */
+    rt_uint32_t freq = 10000;               /* 计数频率 */
+
+    /* 查找定时器设备 */
+    hw_dev = rt_device_find(HWTIMER_DEV_NAME);
+    if (hw_dev == RT_NULL)
+    {
+        rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
+        return RT_ERROR;
+    }
+
+    /* 以读写方式打开设备 */
+    ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
+        return ret;
+    }
+
+    /* 设置超时回调函数 */
+    rt_device_set_rx_indicate(hw_dev, timeout_cb);
+
+    /* 设置计数频率(若未设置该项,默认为1Mhz 或 支持的最小计数频率) */
+    rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
+    /* 设置模式为周期性定时器(若未设置,默认是HWTIMER_MODE_ONESHOT)*/
+    mode = HWTIMER_MODE_PERIOD; //HWTIMER_MODE_ONESHOT;
+    ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("set mode failed! ret is :%d\n", ret);
+        return ret;
+    }
+
+    /* 设置定时器超时值为5s并启动定时器 */
+    timeout_s.sec = 10;      /* 秒 */
+    timeout_s.usec = 0;     /* 微秒 */
+    if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
+    {
+        rt_kprintf("set timeout value failed\n");
+        return RT_ERROR;
+    }
+    //beep_init();
+    hwtimer2_pwm3_output(0,20000,1,1);
+    return ret;
+}
+
+
 /*初始化蜂鸣器*/
 int beep_init(void)
 {
@@ -28,6 +98,102 @@ int beep_init(void)
     }
     return 0;
 }
+
+static int init_pwm3(void)
+{
+    /*查找PWM设备*/
+    pwm_device = (struct rt_device_pwm *)rt_device_find(BEEP_PWM_DEVICE);
+    if(pwm_device==RT_NULL)
+    {
+        rt_kprintf("pwm device %s not found!\n", BEEP_PWM_DEVICE);
+        return -RT_ERROR;
+    }
+    return 0;
+}
+
+static int init_tim2(void)
+{
+    rt_err_t ret = RT_EOK;
+    rt_hwtimerval_t timeout_s;      /* 定时器超时值 */
+    rt_device_t hw_dev = RT_NULL;   /* 定时器设备句柄 */
+    rt_hwtimer_mode_t mode;         /* 定时器模式 */
+    rt_uint32_t freq = 10000;               /* 计数频率 */
+
+    /* 查找定时器设备 */
+    hw_dev = rt_device_find(HWTIMER_DEV_NAME);
+    if (hw_dev == RT_NULL)
+    {
+        rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
+        return RT_ERROR;
+    }
+
+    /* 以读写方式打开设备 */
+    ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
+        return ret;
+    }
+
+    /* 设置超时回调函数 */
+    rt_device_set_rx_indicate(hw_dev, timeout_cb);
+
+    /* 设置计数频率(若未设置该项,默认为1Mhz 或 支持的最小计数频率) */
+    rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
+    /* 设置模式为周期性定时器(若未设置,默认是HWTIMER_MODE_ONESHOT)*/
+    mode = HWTIMER_MODE_ONESHOT; //HWTIMER_MODE_ONESHOT;
+    ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("set mode failed! ret is :%d\n", ret);
+        return ret;
+    }
+
+    /* 设置定时器超时值为5s并启动定时器 */
+    timeout_s.sec = 1;      /* 秒 */
+    timeout_s.usec = 100000;     /* 微秒 */ //100ms
+    if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
+    {
+        rt_kprintf("set timeout value failed\n");
+        return RT_ERROR;
+    }
+    return 0;
+}
+
+int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DIR)
+{
+    init_pwm3();
+    rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
+    rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
+    rt_pin_write(Motor_EN, EN);
+    rt_pin_write(Motor_DIR, DIR);
+    rt_pwm_set(pwm_device, BEEP_PWM_CH, freq, freq/2);//channel,period,pulse
+    if(init_tim2()==0)
+        rt_pwm_enable(pwm_device, BEEP_PWM_CH); //使能蜂鸣器对应的 PWM 通道
+    return 0;
+}
+
+static void stop_motor_86(void)
+{
+    rt_kprintf("stop_motor_86!\n");
+    rt_pwm_disable(pwm_device, BEEP_PWM_CH);
+}
+
+void pin_motor_86_bind(void)
+{
+    rt_pin_mode(MOTOR_86, PIN_MODE_INPUT);
+    /* 绑定中断,下降沿模式,回调函数名为 */
+    rt_pin_attach_irq(MOTOR_86, PIN_IRQ_MODE_FALLING, stop_motor_86, RT_NULL);
+    /* 使能中断 */
+    rt_pin_irq_enable(MOTOR_86, PIN_IRQ_ENABLE);
+}
+
+void pin_motor_86_unbind(void)
+{
+    rt_pin_detach_irq(MOTOR_86);
+}
+
+
 /*打开蜂鸣器*/
 int pwm_on(uint8_t pwn_ch,rt_uint32_t pwm_freq)
 {
@@ -80,11 +246,18 @@ void beep_set(uint32_t freq, uint32_t volume)
     period = freq;    /* 周期为0.5ms,单位为纳秒500000ns-200k */
     /* 根据声音大小计算占空比 蜂鸣器低电平触发 */
     pulse = volume;     //5000
+    if(freq==0)
+    {
+        rt_pwm_disable(pwm_device, BEEP_PWM_CH);
+    }else {
+        /* 利用 PWM API 设定 周期和占空比 */
+        rt_pwm_set(pwm_device, BEEP_PWM_CH, period, pulse);//channel,period,pulse
+        rt_pwm_enable(pwm_device, BEEP_PWM_CH);
+    }
 
-    /* 利用 PWM API 设定 周期和占空比 */
-    rt_pwm_set(pwm_device, BEEP_PWM_CH, period, pulse);//channel,period,pulse
-    rt_pwm_enable(pwm_device, BEEP_PWM_CH);
 }
+
+
 void Beep_Tip(uint16_t volnum)
 {
     rt_pin_mode(Beep, PIN_MODE_OUTPUT);
@@ -150,13 +323,8 @@ void Motor_shake(uint8_t status_shake,uint16_t shake_sec)
 }
 
 
-
-
-
-
-
-
-
+/* 导出到 msh 命令列表中 */
+MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);
 
 
 

+ 5 - 0
Application_cbd_apm32f1/applications/beep.h

@@ -28,4 +28,9 @@ void Motor_Qingsao_R_PWM(uint8_t on_off);
 void Motor_Juandai(uint8_t on_off);
 void Motor_shake(uint8_t status_shake,uint16_t shake_sec);
 /***********************************************************/
+void pin_motor_86_bind(void);
+void pin_motor_86_unbind(void);
+int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DIR);
+
+
 #endif                                          /* APPLICATIONS_INC_BEEP_H_ */

+ 169 - 305
Application_cbd_apm32f1/applications/control.c

@@ -15,6 +15,7 @@
 #include "sound.h"
 #include "dtu_uart2.h"
 #include "sht30_collect.h"
+#include <user_mb_app.h>
 #define DBG_ENABLE
 #define DBG_COLOR
 #define DBG_TAG "control"
@@ -37,6 +38,11 @@ rt_thread_t tid_workloop = RT_NULL;
 rt_thread_t tid_wkstc = RT_NULL;
 rt_thread_t tid_ctr = RT_NULL;
 rt_thread_t tid_heat = RT_NULL;
+rt_thread_t tid_485_play = RT_NULL;
+
+rt_event_t event_485_play;
+
+extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
 
 /***************************************************************************/
 int thread_delete_workloop(void)
@@ -81,208 +87,6 @@ uint8_t ctr_Fan_IN(uint8_t status_ws)
     return 0;
 }
 
-
-/****************************定制色诱*************************************/
-/**/
-#if Color_EN == 1
-uint8_t Read_Color_Key(rt_base_t key_pin)
-{
-    rt_uint32_t sta_s = 0;
-    rt_pin_mode(key_pin, PIN_MODE_INPUT);
-    while(rt_pin_read(key_pin)==1)
-    {
-        sta_s++;
-        /*持续的*/
-        rt_thread_delay(50);
-    }
-    while(rt_pin_read(key_pin)==0)
-    {
-        rt_thread_delay(50);
-        if(sta_s>0) break;
-    }
-    LOG_W("检测到IO0翻转!!!");
-    return 1;
-
-}
-/*读限位开关状态*/
-uint8_t Read_Color_Limit(rt_base_t pin_limit)
-{
-    uint8_t l_sta = 0;
-    rt_pin_mode(pin_limit, PIN_MODE_INPUT);
-    l_sta = rt_pin_read(pin_limit);
-    rt_thread_delay(20);
-    l_sta = rt_pin_read(pin_limit);
-    return l_sta;
-}
-/*色诱板*/
-int ctr_Color_board(uint8_t forward,uint16_t time_board)
-{
-    if(forward==CLOSE)  //归位
-    {
-        if(device_status.cul_time>0)
-            device_status.cul_time--;
-        ctr_cangmen_down(OFF);
-        ctr_cangmen_up(OFF);
-        rt_thread_delay(1000);
-//        if(device_status.cul_time>7) device_status.cul_time=7;
-//        if(device_status.cul_time!=7)
-//        {
-//            uint8_t ct = device_status.cul_time;
-//            while(1)
-//            {
-//                Beep_Tip(100);
-//                rt_thread_delay(100);
-//                ct--;
-//                if(ct==0) break;
-//            }
-//            //return device_status.cul_time;
-//        }
-        if(Read_Color_Limit(LIMIT_RESET)==0)
-        {
-            device_status.cul_time = 0;
-            LOG_W("已在初始位置!");
-            Beep_Tip(1000);
-            return 0;
-            //黄板已经在复位状态,直接返回0;
-        }
-        ctr_cangmen_up(CLOSE);
-        rt_thread_delay(20000);
-        ctr_cangmen_up(OFF);
-
-//        if(device_status.cul_time==7&&Read_Color_Limit(LIMIT_BOARD)==0)
-//        {
-//            LOG_W("第七天!!!");
-//            ctr_cangmen_down(CLOSE);
-//            rt_thread_delay(500);
-//        }
-        LOG_W("先打开运行到限位的右侧!");
-        while(Read_Color_Limit(LIMIT_BOARD)==0)
-        {
-            LOG_W("归位:到达限位中间");
-            ctr_cangmen_down(CLOSE);
-            if(Read_Color_Limit(LIMIT_RESET)==0)
-            {
-                ctr_cangmen_down(OFF);
-                break;
-            }
-        }
-        //先打开运行到限位的右侧
-        while(Read_Color_Limit(LIMIT_BOARD)==1)
-        {
-            LOG_W("归位:运行!");
-            ctr_cangmen_down(CLOSE);
-            if(Read_Color_Limit(LIMIT_RESET)==0)
-            {
-                ctr_cangmen_down(OFF);
-                break;
-            }
-
-        }
-        while(Read_Color_Limit(LIMIT_BOARD)==0)    //到达限位中间 继续运行
-        {
-            LOG_W("归位:到达限位中间");
-            ctr_cangmen_down(CLOSE);
-            if(Read_Color_Limit(LIMIT_RESET)==0)
-            {
-                ctr_cangmen_down(OFF);
-                break;
-            }
-        }
-        if(Read_Color_Limit(LIMIT_RESET)==0) return 0;
-            LOG_W("到达限位左侧!");
-            //停止电机
-            ctr_cangmen_down(OFF);
-            rt_thread_delay(2000);
-            //将推杆电机归位
-            LOG_D("*推杆电机归位*");
-            /*推杆电机伸出*/
-            ctr_cangmen_up(OPEN);
-            rt_thread_delay(20000);
-            ctr_cangmen_up(OFF);
-        return 2;
-    }
-    else if(forward==OPEN)
-    {
-        ctr_cangmen_down(OFF);
-        ctr_cangmen_up(OFF);
-        rt_thread_delay(1000);
-        if(device_status.cul_time==7)
-        {
-            Beep_Tip(5000);
-            return 7;
-        }
-        LOG_W("打开推杆电机!");
-        //2023-04-18:add
-        //if(Read_Color_Limit(LIMIT_BOARD)==0)
-        {
-            LOG_D("*推杆电机归位*");
-            /*推杆电机归位*/
-            ctr_cangmen_up(CLOSE);
-            rt_thread_delay(20000);
-            ctr_cangmen_up(OFF);
-        }
-        if(device_status.cul_time<7)
-        device_status.cul_time++;
-        while(Read_Color_Limit(LIMIT_BOARD)==0)
-        {
-            ctr_cangmen_down(forward);
-            rt_thread_delay(50);
-        }
-        while(Read_Color_Limit(LIMIT_BOARD)==1)
-        {
-            time_board--;
-            if(time_board==0) break;
-            ctr_cangmen_down(forward);
-            rt_thread_delay(50);
-        }
-        ctr_cangmen_down(OFF);
-        rt_thread_delay(1000);
-
-        ctr_cangmen_up(OPEN);
-        rt_thread_delay(20000);
-        ctr_cangmen_up(OFF);
-//        ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time));     //采集时间
-        return OPEN;
-    }
-    else if (forward==RESET) {
-        ctr_cangmen_up(OFF);
-        ctr_cangmen_down(OFF);
-        if(Read_Color_Limit(LIMIT_RESET)==0)
-        {
-            device_status.cul_time = 0;
-            //ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time));     //采集时间
-            LOG_W("已在初始位置!");
-            Beep_Tip(1000);
-            ctr_cangmen_up(CLOSE);
-            rt_thread_delay(20000);
-            ctr_cangmen_up(OFF);
-            device_status.cul_time = 0;
-            return 0;
-            //黄板已经在复位状态,直接返回0;
-        }
-        //if(Read_Color_Limit(LIMIT_BOARD)==0)
-        {
-            LOG_D("*推杆电机归位*");
-            /*推杆电机归位*/
-            ctr_cangmen_up(CLOSE);
-            rt_thread_delay(20000);
-            ctr_cangmen_up(OFF);
-        }
-        while(Read_Color_Limit(LIMIT_RESET)==1)
-        {
-            time_board--;
-            if(time_board==0) break;
-            ctr_cangmen_down(CLOSE);
-            rt_thread_delay(20);
-        }
-        device_status.cul_time = 0;
-        ctr_cangmen_down(OFF);
-    }
-//    device_status.cul_time = 0;
-    //ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time));     //采集时间
-    return RESET;   //复位返回0
-}
-#endif
 /****************************5.0***********************************/
 void ctr_turnv5(void)
 {
@@ -926,6 +730,15 @@ void ctr_turn(uint8_t v,uint8_t sta)
     Motor_shake(OFF,0);
     HMI_WRITE("cangWei.rotateFlag.val=0");
 }
+/*
+ *
+ * */
+void ctr_Motor_Driver_Power(uint8_t status_ws)
+{
+    rt_pin_mode(SHAKE_SW, PIN_MODE_OUTPUT);
+    rt_pin_write(SHAKE_SW, status_ws);
+}
+
 /*************************************************
 Function:       ctr_Motor_Driver
 Description:    步进电机驱动
@@ -971,10 +784,11 @@ void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_ou
         rt_thread_delay(50);
         time_out --;
     }
-    rt_pin_write(Motor_EN, OFF);
-    if(device_status.autotakepic==0)
-    ctr_lamp(OFF, 1);
+    //rt_pin_write(Motor_EN, OFF);
+    //if(device_status.autotakepic==0)
+    //ctr_lamp(OFF, 1);
     beep_set(0, 0);      //200kzh - 50%
+    rt_thread_delay(50);
 }
 /*************************************************
 Function:       ctr_Petroleum_jelly
@@ -1441,9 +1255,13 @@ void calorstat(uint16_t heat_time)
             //跳出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;
+            //device_status.run_sta = device_status.heattem;
             ctr_Heat(ON);
         }
         else if (device_status.heattem>=device_status.heatvalue&&heat_flg==SET)
@@ -1453,7 +1271,7 @@ void calorstat(uint16_t heat_time)
 //                UpLoad_Data();      //加热到设定温度的数据
 //                heat_up_cnt = 1;
 //            }
-            device_status.run_sta = device_status.heattem;
+            //device_status.run_sta = device_status.heattem;
             ctr_Heat(OFF);
         }
         if((n % 60)==0)
@@ -1616,10 +1434,6 @@ void ResetInit(void)
            }
            //3.关闭镇流器
            ctr_lamp(OFF,1);
-           #if LAMP_EN == 1
-           ctr_lamp(OFF,2);
-           ctr_lamp(OFF,3);
-           #endif
            //4.关闭震动电机
            ctr_shake(OFF, 0);
            //5.关闭加热
@@ -1662,15 +1476,6 @@ void ResetInit(void)
                    rt_thread_delay(1000);
                }
            }
-
-
-           //排虫
-           if(device_status.handle_bugger==0){
-               device_status.run_sta = 111;     //排虫
-           }else{
-               device_status.run_sta = 112;     //收虫
-           }
-
     }
     else {
         if(device_status.power_status==1)
@@ -2212,25 +2017,98 @@ void WorkTask(void)
     rt_kprintf("***not work-device status:%d\n",device_status.ds);
 }
 
+
+void guanshan_on(void *args)
+{
+    LOG_W("guanshan_on!");
+    rt_event_send(event_485_play, 0x01);
+}
+
+static void pin_guangshan_bind(void)
+{
+    /* PC14引脚为输入模式 */
+    rt_pin_mode(GUANG_SHAN, PIN_MODE_INPUT);
+    /* 绑定中断,下降沿模式,回调函数名为guanshan_on */
+    rt_pin_attach_irq(GUANG_SHAN, PIN_IRQ_MODE_RISING, guanshan_on, RT_NULL);
+    /* 使能中断 */
+    rt_pin_irq_enable(GUANG_SHAN, PIN_IRQ_ENABLE);
+}
+
+static void pin_guangshan_unbind(void)
+{
+    rt_pin_detach_irq(GUANG_SHAN);
+}
+
+
+/*
+ * 灯管
+ *
+ * */
 void WorkTask_CB5(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)
     {
-        //打开灯管
-        ctr_lamp(ON,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("等待上仓门打开....");
+            }
+            //推杆电机2关闭,益虫仓门关闭
+            device_status.ctr_down_motor = 2;
+            while(device_status.ctr_down_motor!=0)
+            {
+                rt_thread_delay(2000);
+                LOG_I("等待益虫仓门打开....");
+            }
+            //打开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)
     {
-        DTU_Write("workdone");
+        pin_guangshan_unbind();
+        pin_motor_86_unbind();
+        //打开推杆电机,益虫放生
+        device_status.ctr_down_motor = 1;
+        DTU_Write("{\"cmd\":\"workdone\"}");
         ResetInit();
     }
-    LOG_I("WorkTask_CB5 sleeping......");
+    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\"}");
+        }
+        rt_thread_delay(5000);
+    }
+
 }
 
 /* 入口函数-工作状态检测 */
@@ -2262,17 +2140,14 @@ static void Work_Loop_thread_entry(void *parameter)
     ResetInit();
     while(1)
     {
-        if(device_status.version_type!=6&&device_status.dtype==3)
+        if(device_status.version_type!=5&&device_status.dtype==3)
         {
             WorkTask();
         }
-        if(device_status.version_type==6)
-        {
-            WorkTask_XCT();
-        }
+
         if(device_status.version_type==5)
         {
-
+            WorkTask_CB5();
         }
         rt_thread_delay(1000);
     }
@@ -2280,87 +2155,26 @@ static void Work_Loop_thread_entry(void *parameter)
 /*入口函数清扫*/
 static void Control_Clear_thread_entry(void *parameter)
 {
-    static int selfcheck_cnt = 0;
-    float voltage_f = 0.0;
     while(1)
     {
-        #if ROBOT_EN ==1
-        ctr_Motor_Robot(ON);
-        rt_thread_delay(100);
-        #else
-        #if Color_EN ==1
-        /*复位*/
-        if(Read_Color_Key(KEY_RESET)==1)
+        if(device_status.clear_status==1)
         {
-            ctr_Color_board(RESET, 1200);
-            rt_thread_delay(5000);
-        }
-        #else
-        if(device_status.selfcheck_ws==1){
-            selfcheck_cnt ++;
-            if(selfcheck_cnt==1){
-                ctr_lamp(ON,1);
-                rt_thread_delay(1000);
-                device_status.ctr_up_motor = 1;
-                device_status.ctr_down_motor = 1;
-                //记录当前电压
-                voltage_f = atof(device_status.voltage);
-                rt_thread_delay(1500);
-                //开启加热
-                ctr_Heat(ON);
-            }
-            if(selfcheck_cnt==50){
-                double voltage_n = atof(device_status.voltage);
-                //判断当前电压和加热前的电压差
-                if(voltage_f-voltage_n<0.5){
-                    device_status.heat_sta = 1; //加热异常
-                    //上报预警,加热故障
-                    char *heat_warn = makeJson_Warn("加热报警", "heat-error");
-                    DTU_Write("%s", heat_warn);
-                    rt_free(heat_warn);
-                }else{
-                   device_status.heat_sta = 0;
-                }
-                rt_thread_delay(1000);
-                //关闭加热
-                ctr_Heat(OFF);
-                //振动
-                ctr_shake(ON, 1);
-                //device_status.clear_status = 1;
-                ctr_lamp(OFF, 1);
-            }
-            if(selfcheck_cnt>1800){  //超过3分钟
-                device_status.selfcheck_ws = 0;
-                device_status.ctr_up_motor = 0;
-                device_status.ctr_down_motor = 0;
-                //
-                device_status.camsta = 1;   //相机异常
-                device_status.led_sta = 1;
-                //上报自检结果
-                //上报自检结果
-                char *json_temp = makeJson_selfCheck_(1);
-                DTU_Write("%s",json_temp);
-                free(json_temp);
+            if(device_status.version_type==41){
+                ctr_TG_Clear(300);
+            }else {
+                ctr_TG_Clear(150);
             }
 
         }
-        if(device_status.selfcheck_ws==0)
-        {
-            selfcheck_cnt = 0;
-        }
-        if(device_status.clear_status==1)
-        {
-            if(ctr_clear(1200)==0)
-            ctr_TG_Clear(400);
-        }
         rt_thread_delay(100);
-        #endif
-        #endif
     }
 }
 /*入口函数加热*/
 static void Control_Heat_thread_entry(void *parameter)
 {
+    static int total_seconds = 200;
+    static int current_second = 0;
+    static int process = 0;
     while(1)
     {
         if(device_status.work_status==1&&device_status.heat_sw==1)
@@ -2373,11 +2187,9 @@ static void Control_Heat_thread_entry(void *parameter)
         {
             if(device_status.selfcheck_ws==2)
             {
-                static int total_seconds = 200;
-                static int current_second = 0;
                 while(current_second <= total_seconds)
                 {
-                    int process = (current_second * 100) / 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);
@@ -2390,12 +2202,41 @@ static void Control_Heat_thread_entry(void *parameter)
                     }
                 }
                 HMI_WRITE("selfcheck.s106.val=100");
+            }else {
+                process = 0;
+                current_second = 0;
             }
+
         }
         rt_thread_delay(1000);
 
     }
 }
+
+static void thread_485_play_entry(void *param)
+{
+    static USHORT sound105[] = {0x736F,0x756E,0x6431,0x3037};
+    rt_uint32_t e;
+    // 创建事件控制块
+    event_485_play = rt_event_create("event", RT_IPC_FLAG_FIFO);
+    if (event_485_play == RT_NULL)
+    {
+        LOG_E("Event create failed!");
+        return;
+    }
+    while(1)
+    {
+        //等待事件
+        if(rt_event_recv(event_485_play, 0x01, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &e)==RT_EOK)
+        {
+            LOG_I("Interrupt occurred and processed.");
+            _485_play(sound105, 4);
+            //发送串口消息,通知JETSON计算卡进行拍照
+            DTU_Write("{\"guangshan\":\"on\"}");
+        }
+    }
+}
+
 /*清扫线程*/
 int Control_clear(void)
 {
@@ -2426,6 +2267,24 @@ int Control_heat(void)
     }
     return 0;
 }
+
+int thread_485_play(void)
+{
+    tid_485_play = rt_thread_create("thread_485play",
+                                    thread_485_play_entry, RT_NULL,
+                                    1024,       //1024
+                                    26,         //23
+                                    5);       //5
+    if(tid_485_play!=RT_NULL)
+    {
+        rt_thread_startup(tid_485_play);
+    }
+    else {
+        LOG_E("thread_485_play start failed!");
+    }
+    return 0;
+}
+
 /* 创建线程 -工作状态检测*/
 int Workstatus_check(void)
 {
@@ -2459,8 +2318,13 @@ int Work_Loop_Task(void)
     }
     return result_loop;
 }
+
+
+
+
 MSH_CMD_EXPORT(HardWare_Check,HardWare_Check<ON|OFF>);
 MSH_CMD_EXPORT(ctr_lamp,ctr_lamp<ON|OFF>);
+MSH_CMD_EXPORT(ctr_Heat,ctr_Heat<ON|OFF>);
 MSH_CMD_EXPORT(ctr_clear,ctr_clear<ON|OFF>);
 MSH_CMD_EXPORT(ctr_led,sample:ctr_led <ON|OFF>);
 //INIT_APP_EXPORT(Control_heat);

+ 16 - 18
Application_cbd_apm32f1/applications/control.h

@@ -15,20 +15,22 @@
 #include <rtdevice.h>
 //定制相关//////////////////////////////////////////////////////
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
+#define PCB_V1           0
 #define SENSOR_EN        1              //温湿度:0关闭,1打开
 ////////////////////////////////////////////////////////////////
 #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.2.41(HK)"            //4.0海康-1200W
-    #define VERSION_HK_2000W    "2.3.4(2000W)"         //4.0水稻
+    #define VERSION_HK          "2.4.41(HK)"            //4.0海康-1200W
+    #define VERSION_HK_2000W    "2.10.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
 
+extern rt_event_t event_485_play;
 
 
 /*********************************************************************/
@@ -79,7 +81,7 @@ typedef struct  _packed
     uint8_t ds;              //设备状态   0-关机 1-开机
     uint8_t work_status;     //工作状态   0-待机 1-工作
     uint8_t work_done;       //工作结束   1-正常 0-工作已结束
-    uint8_t bat_status;      //电压状态   1-正常 0-欠压
+    uint8_t bat_status;      //电压状态   0-正常 1-欠压
     uint8_t heattime;        //加热时间
     uint8_t heat_time_min;   //实时加热时间
     uint8_t clt_time;        //收集时间
@@ -129,7 +131,7 @@ typedef struct  _packed
     char csq[8];               //信号强度
     char net[8];               //网络
     char sim[8];               //SIM卡
-    char gps[8];               //定位类型
+    char gps[8];               //定位状态
     char gps_state[8];         //定位类型
     char tempture[12];         //温度
     char humidity[12];         //湿度
@@ -144,6 +146,7 @@ typedef struct  _packed
     char fuse_voltage[32];     //保险丝电压
     char iccid[32];            //SIM卡ICCID
     char imei[32];             //IMEI,唯一ID
+    char link_ip[32];
     char json_w_clock[128];    //修改时间
     char json_w_reset[128];    //
     char json_w_platform[128]; //
@@ -172,7 +175,11 @@ typedef struct  _packed
 #define  Heat_Pin GET_PIN(B,12)
 //采集/上仓门
 #define  Collect_fan_R GET_PIN(C, 5)
+#if PCB_V1 == 0
 #define  Collect_fan_L GET_PIN(B, 6)
+#else
+#define  Collect_fan_L GET_PIN(C, 4)
+#endif
 //下仓门
 #define  C_DOWN_R GET_PIN(B,0)
 #define  C_DOWN_L GET_PIN(B,1)
@@ -204,7 +211,6 @@ typedef struct  _packed
 /***************************高空测报灯*************************/
 
 //上仓门电机限位
-#define CTR_UPO_LIMIT GET_PIN(C,13)
 #define CTR_UPC_LIMIT GET_PIN(B,9)
 //下仓门电机限位
 #define CTR_DWO_LIMIT GET_PIN(B,5)
@@ -236,7 +242,9 @@ uint8_t ctr_Motor_xichong(uint8_t status_ws);
 uint8_t ctr_Motor_xifu(uint8_t status_ws);
 uint8_t ctr_Camera_Power(uint8_t status_ws);
 /*****************************5.0测报灯******************************/
-void ctr_turnv5(void);
+#define GUANG_SHAN GET_PIN(C,13)       //光栅
+#define MOTOR_86   GET_PIN(B,9)        //85电机限位
+void ctr_Motor_Driver_Power(uint8_t status_ws);
 /*****************************孢子仪**********************************/
 //制冷
 #define Cold_Pin GET_PIN(B,11)
@@ -276,12 +284,6 @@ uint8_t ctr_Fan_PUT(uint8_t status_ws);
 #define Motor_Direction_Ctr GET_PIN(B,15)               //IO输出,控制电机运动方向
 #define EMS_Dir GET_PIN(B,14)
 void ctr_Motor_Robot(uint8_t status_ws);
-/****************************定制色诱***************************************************/
-#define LIMIT_RESET GET_PIN(C,13)
-#define LIMIT_BOARD GET_PIN(B,9)
-#define KEY_RESET   GET_PIN(B,8)
-#define KEY_BACK    GET_PIN(B,5)
-int ctr_Color_board(uint8_t forward,uint16_t time_board);
 /***************************************************************/
 /***************************************************************/
 uint8_t ctr_Heat(uint8_t status_heat);          //加热
@@ -304,11 +306,7 @@ void HardWare_Check(uint8_t boot);              //自检
 void ResetInit(void);                           //上电复位
 void SunTest(void);                             //光控测试
 /*****************************************************/
-void WorkTask_XCT(void);
-/****************************************************/
-void WorkCheck(void);               //工作检测
-void WorkTask(void);                //工作任务
-//
+
 /***********************孢子仪****************************/
 
 /***************************************************/
@@ -317,7 +315,7 @@ int Control_clear(void);
 int Workstatus_check(void);
 int Work_Loop_Task(void);
 int Control_heat(void);
-
+int thread_485_play(void);
 
 int thread_delete_workloop(void);
 int thread_restart_workloop(void);

+ 418 - 117
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -23,7 +23,8 @@
 #include <ymodem.h>
 #include "beep.h"
 #include <selfcheck.h>
-#include <s2j.h>
+#include <user_mb_app.h>
+
 #define DBG_ENABLE
 #define DBG_COLOR
 #define DBG_TAG "dtu"
@@ -32,7 +33,7 @@
 
 
 #define DTU_THREAD_PRIORITY         6          //线程优先级
-#define DTU_THREAD_STACK_SIZE       2048        //线程栈空间大小
+#define DTU_THREAD_STACK_SIZE       4096        //线程栈空间大小
 #define DTU_THREAD_TIMESLICE        5           //时间片
 
 
@@ -57,6 +58,8 @@ struct  serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT;  /*初始化配
 
 static uint8_t makejson_sta = 0;
 
+extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
+
 static int DTU_uart2_init(void)
 {
         dtuserial  = rt_device_find(DTU_UART_NAME);
@@ -99,12 +102,12 @@ void DTU_Write(char *fmt, ...)
     rt_size_t str_length;
     va_start(ap,fmt);
     //str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 1, fmt, arg);
-    str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str) - 4, fmt, ap);
+    str_length = rt_vsnprintf(dtu_str, sizeof(dtu_str)-1, fmt, ap);
     va_end(ap);
-    if (str_length > 1024 - 4)
-        str_length = 1024 - 4;
+    if (str_length > 1024 - 1)
+        str_length = 1024 - 1;
     rt_device_write(dtuserial, 0, dtu_str, str_length);
-    rt_thread_mdelay(10);
+    rt_thread_mdelay(20);
 //    if(strstr(dtu_str,"volume")!=RT_NULL)
 //    {
 //        rt_device_write(dtuserial,0,dtu_conf,4);
@@ -126,27 +129,199 @@ static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
         {
             /* 消息队列满 */
             rt_kprintf("message queue full!\n");
+            rt_mq_control(&rx_mq_dtu, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
         }
         return result;
 }
+
+// 最大JSON缓冲区长度(建议根据设备内存调整)
+#define MAX_JSON_BUFFER 1024
+// 最大超时时间(单位:RT_TICK_PER_SECOND)
+#define JSON_PARSE_TIMEOUT 2
+
+// 全局缓冲区结构体
+static struct {
+    char buffer[MAX_JSON_BUFFER]; // 数据存储区
+    int index;                   // 当前写入位置
+    rt_tick_t last_received;     // 最后接收时间戳
+    int nested_level;            // 当前嵌套层数
+} json_ctx = {.index = 0, .last_received = 0, .nested_level = 0};
+
+
+// 自定义异常类型
+typedef enum {
+    JSON_OK,
+    JSON_INCOMPLETE,
+    JSON_INVALID_CHAR,
+    JSON_TOO_DEEP,
+    JSON_TOO_LONG
+} json_status_t;
+
+// 查找完整JSON边界(支持嵌套)
+static json_status_t find_json_boundary(int *start, int *end)
+{
+    *start = -1;
+    *end = -1;
+    int level = 0;
+
+    for (int i = 0; i < json_ctx.index; i++) {
+        if (json_ctx.buffer[i] == '{') {
+            if (level == 0) *start = i;
+            level++;
+            if (level > 32) return JSON_TOO_DEEP;
+        } else if (json_ctx.buffer[i] == '}') {
+            level--;
+            if (level < 0) return JSON_INVALID_CHAR;
+            if (level == 0 && *start != -1) {
+                *end = i;
+                return JSON_OK;
+            }
+        }
+    }
+
+    if (*start != -1) return JSON_INCOMPLETE;
+    return JSON_OK;
+}
+// 处理缓冲区超时
+static void check_timeout_reset(void)
+{
+    if (rt_tick_get() - json_ctx.last_received > JSON_PARSE_TIMEOUT * RT_TICK_PER_SECOND) {
+        rt_memset(json_ctx.buffer, 0, MAX_JSON_BUFFER);
+        json_ctx.index = 0;
+        json_ctx.nested_level = 0;
+        rt_kprintf("[JSON] Timeout reset\n");
+    }
+}
+#define RT_MIN(a, b) ((a) < (b) ? (a) : (b))
+// 核心处理函数
+void process_uart_data(const char *data, int length)
+{
+    // 有效性检查
+    if (data == NULL || length <= 0) return;
+    json_ctx.last_received = rt_tick_get();
+
+    // 缓冲区溢出保护
+    int remain_space = MAX_JSON_BUFFER - json_ctx.index - 1;
+    if (remain_space < length) {
+        rt_kprintf("[JSON] Buffer overflow (%d/%d)\n",
+                  json_ctx.index + length, MAX_JSON_BUFFER);
+        json_ctx.index = 0; // 清空缓冲区重新开始
+        return;
+    }
+
+    // 追加新数据
+    rt_memcpy(json_ctx.buffer + json_ctx.index, data, length);
+    json_ctx.index += length;
+    json_ctx.buffer[json_ctx.index] = '\0';
+
+    // 循环处理所有完整报文
+    while (1) {
+        int start_pos, end_pos;
+        json_status_t status = find_json_boundary(&start_pos, &end_pos);
+
+        switch (status) {
+        case JSON_OK:
+            if (start_pos != -1 && end_pos != -1) {
+                // 提取有效JSON内容
+                char json_str[512] = {0};
+                int json_len = end_pos - start_pos + 1;
+                rt_strncpy(json_str, json_ctx.buffer + start_pos,
+                          RT_MIN(sizeof(json_str)-1, json_len));
+
+                // 调用解析函数
+                if (parseDtu(json_str) == RT_EOK) {
+                    rt_kprintf("[JSON] Parsed: %.*s\n", json_len, json_str);
+                }
+
+                // 移动缓冲区剩余内容
+                int remain_data = json_ctx.index - (end_pos + 1);
+                if (remain_data > 0) {
+                    rt_memmove(json_ctx.buffer,
+                              json_ctx.buffer + end_pos + 1,
+                              remain_data);
+                }
+                json_ctx.index = remain_data;
+                json_ctx.buffer[json_ctx.index] = '\0';
+            } else {
+                return; // 无更多完整报文
+            }
+            break;
+
+        case JSON_INCOMPLETE:
+            return; // 等待更多数据
+
+        default:
+            rt_kprintf("[JSON] Error %d at pos %d\n", status, start_pos);
+            // 错误恢复:跳过错误数据
+            json_ctx.index = 0;
+            return;
+        }
+    }
+}
+
+
+
+
 /* 入口函数-指令接收*/
 static void dtu_thread_entry_recv(void *parameter)
 {
     struct rx_msg msg;
-    rt_err_t result;
-    rt_uint32_t rx_length;
-    rt_uint32_t rx_err = 0;
-    static char str_check[2]={'{','}'};
-    static char rx_buffer[512];
-    static char rx_buffer_tmp[512];
-    static char rx_buffer_tmp2[512];
+    rt_memset(&msg, 0, sizeof(msg));
+    static int rx_err = 0;
     while(1)
     {
-        rt_memset(&msg, 0, sizeof(msg));
+        //
         // 从消息队列中获取被回调函数放入消息队列中的内容
-        result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 50);
+        int result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 50);
+        if (result != RT_EOK){
+            rx_err ++;
+            if(rx_err==54000)//90分钟未接收到数据
+            {
+                if(device_status.version_type==6)
+                {
+                    LOG_E("RK3399 transter Error!");
+                    ctr_photo(OFF);
+                }
+                else {
+                    ctr_RTU_DTU(OFF);
+                }
+            }
+            if (rx_err==54100&&device_status.bat_status==0)
+            {
+                LOG_W("通信中断,RTU重新上电");
+                rx_err = 0;
+                ctr_RTU_DTU(ON);
+                ctr_photo(ON);
+            }
+            continue;
+        }
+        // 动态分配接收缓冲区
+        char *rx_buffer = rt_malloc(msg.size + 1);
+        if (!rx_buffer) {
+            LOG_E("Memory allocation failed");
+            continue;
+        }
+        // 安全读取数据
+        int rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
+        if (rx_length <= 0) {
+            rt_free(rx_buffer);
+            continue;
+        }
+        rx_buffer[rx_length] = '\0';
+        // 处理数据(新增调试接口)
+        LOG_I("Raw Data:%s-%d",rx_buffer, rx_length);
+
+        if(device_status.dtype==3)
+        {
+            HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
+            rt_timer_stop(timer_uart2);
+        }
+        process_uart_data(rx_buffer, rx_length);
+        rt_free(rx_buffer);
+        #if 0
         if(result == RT_EOK)
         {
+
             rx_err = 0;
             rx_length =(sizeof(rx_buffer) - 1) > msg.size ?
                     msg.size : sizeof(rx_buffer) - 1;
@@ -167,6 +342,7 @@ static void dtu_thread_entry_recv(void *parameter)
                 }
 
             }
+
             //过滤异常数据
             char str_check_head[2];
             char str_check_end[2];
@@ -187,48 +363,49 @@ static void dtu_thread_entry_recv(void *parameter)
                    else {
                        rt_sprintf(rx_buffer_tmp2,"%s",rx_buffer);
                        rt_sprintf(rx_buffer, "%s%s",rx_buffer_tmp,rx_buffer_tmp2);
-                       //rt_kprintf("rxbuffer:%s",rx_buffer);
                        parseDtu(rx_buffer);
                        rt_memset(rx_buffer,0,sizeof(rx_buffer));
                        rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
                        rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
                    }
-                   //rt_kprintf("%s",rx_buffer);
+
                  }
+            #endif
          }
-         else {
-                    rx_err ++;
-                    if(rx_err==54000)//90分钟未接收到数据
-                    {
-                        if(device_status.version_type==6)
-                        {
-                            LOG_E("RK3399 transter Error!");
-                            ctr_photo(OFF);
-                        }
-                        else {
-                            ctr_RTU_DTU(OFF);
-                        }
-                    }
-                    else if (rx_err==54100&&device_status.bat_status==0)
-                    {
-                        LOG_W("通信中断,RTU重新上电");
-                        rx_err = 0;
-                        ctr_RTU_DTU(ON);
-                        ctr_photo(ON);
-                    }
-               }
-            //rt_kprintf("%s\n",rx_json_buffer);
-            // 将内容写回到串口1
-            //rt_device_write(dtuserial, 0, &rx_json_buffer[0], rx_length);
+//         else {
+//
+//
+//    }
+}
+
+
+// 函数定义:判断数组中是否有大于 100 的元素
+int hasElementGreaterThan400(uint16_t arr[], int size) {
+    for (int i = 0; i < size; i++) {
+        if (arr[i] < 400) {
+            return 1; // 找到大于 100 的元素,返回 1
+        }
+    }
+    return 0; // 遍历完数组,没有找到大于 100 的元素,返回 0
+}
 
+int hasElementGreater_lessThan400(uint16_t arr[], int size) {
+    for (int i = 0; i < size; i++) {
+        if (arr[i] > 400) {
+            return 1; // 找到大于 100 的元素,返回 1
+        }
     }
+    return 0; // 遍历完数组,没有找到大于 100 的元素,返回 0
 }
+
 /*入口函数-指令发送*/
 static void dtu_thread_entry_send(void *parameter)
 {
 
     device_status.power_status = 1;
     device_status.num_updata = 0;
+    static uint16_t current_arry[10];
+    static uint8_t record_current = 0;
     rt_thread_delay(10000);
     static rt_uint16_t wait_i = 0;
     static rt_uint8_t check_i = 0;
@@ -242,72 +419,90 @@ static void dtu_thread_entry_send(void *parameter)
         now_tm =*localtime(&now_t);
         if(atoi(device_status.net)==0||atoi(device_status.gps)==1||(now_tm.tm_year+1900 >=2024))    //当前时间大于2024
         {
-                if(device_status.rain_status==1||device_status.temp_status==1)
+            if(device_status.rain_status==1||device_status.temp_status==1)
+            {
+                if(check_i==0)
                 {
-                    if(check_i==0)
-                    {
-                        check_i = 1;
-                        device_status.num_updata = 0;
-                    }
+                    check_i = 1;
+                    device_status.num_updata = 0;
                 }
-                else {
-                    check_i = 0;
+            }
+            else {
+                check_i = 0;
+            }
+            if(device_status.num_updata!=0)
+            {
+                device_status.num_updata--;
+                //屏幕休眠
+                if(device_status.num_updata==(device_status.dattim * 60-10))
+                {
+                    HMI_WRITE("sleep=%d",1);
                 }
-                if(device_status.num_updata!=0)
+                LOG_I("掉电检测:%d-%d",atoi(device_status.voltage),device_status.power_status);
+                //检测到电源掉电
+                if(atoi(device_status.voltage)<5&&device_status.power_status==1)
                 {
-                    device_status.num_updata--;
-                    //屏幕休眠
-                    if(device_status.num_updata==(device_status.dattim * 60-10))
+                    power_i++;
+                    //确定网络状态
+                    if(power_i==10)
                     {
-                        HMI_WRITE("sleep=%d",1);
+                        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;
                     }
-                    LOG_I("掉电检测:%d-%d",atoi(device_status.voltage),device_status.power_status);
-                    //检测到电源掉电
-                    if(atoi(device_status.voltage)<5&&device_status.power_status==1)
+                }
+                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%5==0&&atoi(device_status.power)>20)    //每过5S把电流值存入数组,连续10条数据的电流值大于400mA判断为正常
+                {
+                    current_arry[record_current] = atoi(device_status.power);
+                    record_current++;
+                    if(record_current==10)
                     {
-                        power_i++;
-                        //确定网络状态
-                        if(power_i==10)
+                        record_current = 0;
+                        if(hasElementGreaterThan400(current_arry, 10)==0)   //连续10条电流值大于400,灯管状态正常
                         {
-                            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;
+                            device_status.lamp_status = 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(hasElementGreater_lessThan400(current_arry,10)==0)   //连续10条电流值小于400,灯管状态异常
+                        {
+                            device_status.lamp_status = 1;
+                        }
+                        memset(current_arry,0,sizeof(current_arry));
                     }
                 }
-                else {
-                    char *readinfo =  makeJson_ReadInfo();
-                    rt_kprintf("upload data:%s\n",readinfo);
-                    DTU_Write("%s",readinfo);
-                    rt_free(readinfo);
-                    rt_thread_delay(1000);
-                    UpLoad_Data();
-                    if(atoi(device_status.fuse_voltage)<1)
-                    {
-                        rt_thread_delay(500);
-                        static char res[30];
-                        sprintf(res, "Fuse is fusing:%s",device_status.fuse_voltage);
-                        char * res_fuse_warn = makeJson_Warn(res,"device");
-                        DTU_Write("%s",res_fuse_warn);
-                        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 {
+                char *readinfo =  makeJson_ReadInfo();
+                rt_kprintf("upload data:%s\n",readinfo);
+                DTU_Write("%s",readinfo);
+                rt_free(readinfo);
+                rt_thread_delay(1000);
+                UpLoad_Data();
+                if(atoi(device_status.fuse_voltage)<1)
+                {
+                    rt_thread_delay(500);
+                    static char res[30];
+                    sprintf(res, "Fuse is fusing:%s",device_status.fuse_voltage);
+                    char * res_fuse_warn = makeJson_Warn(res,"device");
+                    DTU_Write("%s",res_fuse_warn);
+                    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 ++;
@@ -729,16 +924,8 @@ char * makeJson()
     char utos[5];
     if(device_status.gps==NULL)
     rt_sprintf(device_status.gps, "0");
-    //如果设备工作并且电流小于500,并且不是上电启动灯管异常
-    if(atoi(device_status.power)<400&&atoi(device_status.power)!=0&&device_status.work_status==1&&makejson_sta!=0)
-    {
-        #if LAMP_EN == 0
-        LOG_I("Current is:%d",atoi(device_status.power));
-        if(atoi(device_status.power)>10)        //过滤电流检测芯片损坏导致电流直为0 的异常
-        device_status.lamp_status = 1;
-        #endif
-    }
-    else {
+
+    if(device_status.work_status==0) {
         device_status.lamp_status = 0;
     }
     if(atoi(device_status.power)>5000)
@@ -1010,6 +1197,10 @@ char * makeJson()
     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);
     //数据上传间隔
@@ -1118,16 +1309,13 @@ int parseDtu(char *json_string)
     cJSON* project = NULL;  //Project
     cJSON* ds = NULL;   //设备状态
     cJSON* vt = NULL;   //版本类型
-//    cJSON* account_status = NULL;   //卡状态
-//    cJSON* data_plan = NULL;        //套餐
-//    cJSON* data_usage = NULL;       //已使用
-//    cJSON* expiry_date = NULL;      //到期时间
     cJSON* mqttcfg1 = NULL;
     cJSON* mqttcfg2 = NULL;
     cJSON* type =NULL;
     cJSON* hum = NULL;
     cJSON* tmp = NULL;
     cJSON* link_sta = NULL;
+    cJSON* link_ip = NULL;
     cJSON* value_commn= NULL;
     rt_kprintf("%s\n",json_string);
     cJSON *root = cJSON_Parse(json_string);
@@ -1139,12 +1327,100 @@ int parseDtu(char *json_string)
     }
     else
     {
+
           item_cmd = cJSON_GetObjectItem(root,"cmd");
+          cJSON* item_aplay = cJSON_GetObjectItem(root,"aplay");
           item_checkself = cJSON_GetObjectItem(root,"selfcheck");
           photolink = cJSON_GetObjectItem(root,"photolink");
           cJSON* ledsta = cJSON_GetObjectItem(root,"ledsta");
           cJSON* cam_cmd= cJSON_GetObjectItem(root,"cam_code");
+          cJSON* yolo_start = cJSON_GetObjectItem(root,"yolo");
           item_ext=cJSON_GetObjectItem(root,"ext");
+          if(yolo_start!=NULL)
+          {
+            if(strcmp(yolo_start->valuestring,"start")==0)  //”识别进程已启动“
+            {
+                //CAB6 B1F0 BDF8 B3CC D2D1 C6F4 B6AF
+                static USHORT sound_7[] = {0xCAB6,0xB1F0,0xBDF8,0xB3CC,0xD2D1,0xC6F4,0xB6AF};
+                _485_play(sound_7,7);
+            }
+          }
+          if(item_aplay!=NULL)
+          {
+              if(strcmp(item_aplay->valuestring,"data_upload")==0)  //数据上传中
+              {
+                  //CAFD BEDD C9CF B4AB D6D0
+                  static USHORT sound_0[] = {0xcafd,0xbedd,0xc9cf,0xb4ab,0xd6d0};
+                  _485_play(sound_0,5);
+              }else if(strcmp(item_aplay->valuestring,"kuaimen")==0)  //数据上传中
+              {
+                  //736F 756E 6431 3031
+                  static USHORT sound_1[] = {0x736f,0x756e,0x6431,0x3031};
+                  _485_play(sound_1,4);
+              }else if(strcmp(item_aplay->valuestring,"photouploadsuccess")==0)  //图片上传成功
+              {
+                  //C9CF B4AB B3C9 B9A6
+                  static USHORT sound_2[] = {0xc9cf,0xb4ab,0xb3c9,0xb9a6};
+                  _485_play(sound_2,4);
+              }else if(strcmp(item_aplay->valuestring,"photouploadfailed")==0)  //图片上传失败
+              {
+                  //C9CF B4AB CAA7 B0DC
+                  static USHORT sound_3[] = {0xc9cf,0xb4ab,0xcaa7,0xb0dc};
+                  _485_play(sound_3,4);
+              }else if(strcmp(item_aplay->valuestring,"welcom")==0)  //JETSON启动
+              {
+                  //4A45 5453 4F4E C6F4 B6AF
+                  static USHORT sound_4[] = {0x4A45,0x5453,0x4F4E,0xC6F4,0xB6AF};
+                  _485_play(sound_4,5);
+              }else if(strcmp(item_aplay->valuestring,"fdsucess")==0)  //升级文件下载成功
+              {
+                  //C9FD BCB6 CEC4 BCFE CFC2 D4D8 B3C9 B9A6
+                  static USHORT sound_5[] = {0xC9FD,0xBCB6,0xCEC4,0xBCFE,0xCFC2,0xD4D8,0xB3C9,0xB9A6};
+                  _485_play(sound_5,8);
+              }else if(strcmp(item_aplay->valuestring,"fdfailed")==0)  //”升级文件下载失败“
+              {
+                  //C9FD BCB6 CEC4 BCFE CFC2 D4D8 CAA7 B0DC
+                  static USHORT sound_6[] = {0xC9FD,0xBCB6,0xCEC4,0xBCFE,0xCFC2,0xD4D8,0xCAA7,0xB0DC};
+                  _485_play(sound_6,8);
+              }else if(strcmp(item_aplay->valuestring,"yolodone")==0)  //”识别进程已结束“
+              {
+                  //CAB6 B1F0 BDF8 B3CC D2D1 BDE1 CAF8
+                  static USHORT sound_8[] = {0xCAB6,0xB1F0,0xBDF8,0xB3CC,0xD2D1,0xBDE1,0xCAF8};
+                  _485_play(sound_8,8);
+              }else if(strcmp(item_aplay->valuestring,"onmessage")==0)  //”提示音“
+              {
+                  //sound10?
+                  static USHORT sound_9[] = {0xCAB6,0xB1F0,0xBDF8,0xB3CC,0xD2D1,0xBDE1,0xCAF8};
+                  _485_play(sound_9,8);
+              }else if(strcmp(item_aplay->valuestring,"startupdate")==0)  //”开始升级“
+              {
+                  //BFAA CABC C9FD BCB6
+                  static USHORT sound_10[] = {0xBFAA,0xCABC,0xC9FD,0xBCB6};
+                  _485_play(sound_10,4);
+              }else if(strcmp(item_aplay->valuestring,"updatesuccess")==0)  //”升级成功“
+              {
+                  //C9FD BCB6 B3C9 B9A6
+                  static USHORT sound_11[] = {0xC9FD,0xBCB6,0xB3C9,0xB9A6};
+                  _485_play(sound_11,4);
+              }else if(strcmp(item_aplay->valuestring,"updatefailed")==0)  //”升级失败“
+              {
+                  //C9FD BCB6 CAA7 B0DC
+                  static USHORT sound_12[] = {0xC9FD,0xBCB6,0xCAA7,0xB0DC};
+                  _485_play(sound_12,4);
+              }else if(strcmp(item_aplay->valuestring,"sound113")==0)  //”mqtt消息提示音“
+              {
+                  //736F 756E 6431 3133
+                  static USHORT sound_13[] = {0x736F,0x756E,0x6431,0x3133};
+                  _485_play(sound_13,4);
+              }else if(strcmp(item_aplay->valuestring,"net_connect")==0)  //"网络连接成功“
+              {
+                  //CDF8 C2E7 C1AC BDD3 B3C9 B9A6
+                  static USHORT sound_14[] = {0xCDF8,0xC2E7,0xC1AC,0xBDD3,0xB3C9,0xB9A6};
+                  _485_play(sound_14,6);
+              }
+
+
+          }
           if(cam_cmd!=NULL){
               //先检查定时器状态,否则会崩溃
               rt_timer_stop(timer_uart2);
@@ -1211,12 +1487,19 @@ int parseDtu(char *json_string)
           {
               if(strstr(item_cmd->valuestring,"takephoto")!=RT_NULL)
               {
-                  //HK_TakePhoto();
-                  device_status.photo_ws=1;
-                  char *photo = makeJson_Warn("takephoto","control");
-                  DTU_Write("%s",photo);
-                  rt_free(photo);
-                  rt_thread_delay(2000);
+                #if 0
+                ctr_led(ON);
+                //发送拍照指令
+                char *takephotojson = makeJson_takephoto();
+                DTU_Write("%s",takephotojson);
+                rt_free(takephotojson);
+                #else
+                device_status.photo_ws=1;
+                char *photo = makeJson_Warn("takephoto","control");
+                DTU_Write("%s",photo);
+                rt_free(photo);
+                rt_thread_delay(2000);
+                #endif
               }
               else if (strstr(item_cmd->valuestring,"json_w_clock")!=RT_NULL) {
                   rt_kprintf("查询时间配置!\n");
@@ -1320,6 +1603,16 @@ int parseDtu(char *json_string)
                       }
                       LOG_I("收到自检指令:%d",device_status.selfcheck_ws);
                   }
+                  else if(strstr(type->valuestring,"insect_kill")!=RT_NULL)
+                  {
+                      device_status.autotakepic = 10;
+                      LOG_W("收到害虫信号!");
+                  }
+                  else if(strstr(type->valuestring,"insect_save")!=RT_NULL)
+                  {
+                      device_status.autotakepic = 11;
+                      LOG_W("收到益虫信号!");
+                  }
               }
               //切换平台
               else if (strstr(item_cmd->valuestring,"platform")!=RT_NULL)
@@ -1500,6 +1793,7 @@ int parseDtu(char *json_string)
                   mqttcfg1 = cJSON_GetObjectItem(item_ext,"mqttcfg1");
                   mqttcfg2 = cJSON_GetObjectItem(item_ext,"mqttcfg2");
                   link_sta = cJSON_GetObjectItem(item_ext,"link_sta");
+                  link_ip = cJSON_GetObjectItem(item_ext,"link_ip");
                   photo_sta = cJSON_GetObjectItem(item_ext,"photo_sta");
                   cJSON *gps_inuse = cJSON_GetObjectItem(item_ext,"gps_inuse");
                   cJSON *gps_view = cJSON_GetObjectItem(item_ext,"gps_view");
@@ -1519,6 +1813,13 @@ int parseDtu(char *json_string)
                       HMI_WRITE("menu.cpu_temp.txt=\"%d.%d℃\"",atoi(value_commn->valuestring)/1000,atoi(value_commn->valuestring)%1000);
 
                   }
+                  if(link_ip!=NULL)
+                  {
+                      //sprintf(device_status.)
+                      sprintf(device_status.link_ip,"%s",link_ip->valuestring);
+                      //HMI_WRITE("menu.t0.txt=\"%s\"",link_ip->valuestring);
+                  }
+
                   if(strstr(device_status.imei,imei->valuestring)==RT_NULL)
                   {
                        rt_kprintf("Change IMEI:new:%s-old:%s",imei->valuestring,device_status.imei);
@@ -1628,7 +1929,6 @@ int parseDtu(char *json_string)
                       rt_sprintf(device_status.gps,"%s",gps->valuestring);
                       if(atoi(gps->valuestring)!=0)
                       {
-                          #if BOOT_ERR == 1
                            if(atoi(gps->valuestring)==1)
                            rt_sprintf(device_status.gps_state, "%s","GPS+BD");
 
@@ -1638,7 +1938,7 @@ int parseDtu(char *json_string)
                           if(gps_view!=NULL){
                               device_status.gps_view = atoi(gps_view->valuestring);
                           }
-                          #endif
+
                           if(strstr(device_status.lat,lat->valuestring)==NULL)
                           {
                               memset(device_status.lat,0,sizeof(device_status.lat));
@@ -2273,3 +2573,4 @@ void UpLoad_Data(void)
     //播放数据上传中语音
 }
 
+MSH_CMD_EXPORT(UpLoad_Data,UpLoad_Data);

+ 66 - 20
Application_cbd_apm32f1/applications/hmi.c

@@ -26,6 +26,7 @@
 #include "dtu_uart2.h"
 #include <fal.h>
 #include "selfcheck.h"
+#include <user_mb_app.h>
 #define DBG_ENABLE
 #define DBG_COLOR
 #define DBG_TAG "hmi"
@@ -45,11 +46,15 @@ static char msg_pool[512];
 
 static char rx_buffer[HMI_UART_RXBUFFER_SIZE + 1];
 
+static USHORT sound122[] = {0x736f,0x756e,0x6431,0x3232};
+
 void list_mem(void);
 int mb_master_samlpe();
 /**/
 Device_Status_typedef device_status;
 
+extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
+
 time_t time(time_t *t);
 
 /* 串口接收消息结构*/
@@ -137,6 +142,7 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
     {
         /* 消息队列满 */
         LOG_E("hmi message queue full!\n");
+        rt_mq_control(&rx_mq, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
     }
     return result;
 }
@@ -320,6 +326,8 @@ static void HMI_Decode(void)
             //更新熄屏时间
             if(device_status.thsp<60) device_status.thsp = device_status.thsp * 60;
             HMI_WRITE("thsp=%d",device_status.thsp);
+            //
+            HMI_WRITE("menu.t0.txt=\"%s\"",device_status.link_ip);
         }
         HMI_WRITE("menu.cam_sta.val=%d",device_status.camsta);
 
@@ -362,10 +370,28 @@ static void HMI_Decode(void)
     }
     //拍照
     else if(strstr(rx_buffer,"putTest.switchPhoto=1")!=NULL) {
+        #if 0
+        ctr_led(ON);
+        //发送拍照指令
+        char *takephotojson = makeJson_takephoto();
+        DTU_Write("%s",takephotojson);
+        rt_free(takephotojson);
+        HMI_WRITE("sysTest.switchPhoto.val=0");
+        #else
         device_status.photo_ws = 1;
+        #endif
     }
     else if (strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
+        #if 0
+        ctr_led(ON);
+        //发送拍照指令
+        char *takephotojson = makeJson_takephoto();
+        DTU_Write("%s",takephotojson);
+        rt_free(takephotojson);
+        HMI_WRITE("sysTest.switchPhoto.val=0");
+        #else
         device_status.photo_ws = 1;
+        #endif
     }
     //转盘复位
     else if (strstr(rx_buffer,"turn_init")!=NULL) {
@@ -520,6 +546,8 @@ static void HMI_Decode(void)
         ctr_lamp(ON,3);
         #endif
         DTU_Write("{\"cmd\":\"workstart\"}");
+        USHORT dkdg[] = {0xb4f2,0xbfaa,0xb5c6,0xb9dc};
+        _485_play(dkdg,4);
     }
 
     //关闭灯管
@@ -533,6 +561,8 @@ static void HMI_Decode(void)
         ctr_lamp(OFF,3);
         #endif
         DTU_Write("{\"cmd\":\"workdone\"}");
+        USHORT gbdg[] = {0xb9d8,0xb1d5,0xb5c6,0xb9dc};
+        _485_play(gbdg,4);
     }
     //关闭加热
     else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
@@ -1027,7 +1057,7 @@ static void HMI_Decode(void)
         strncpy(shakesec_str,var,2);
         if(atoi(shakesec_str)>=0&&atoi(shakesec_str)<=10)
         {
-            device_status.shake_sec =atoi(shakesec_str)*10; //
+            device_status.shake_sec =atoi(shakesec_str); //
         }
         else {
             LOG_E("设置失败!!!");
@@ -1170,7 +1200,7 @@ static void HMI_Decode(void)
     {
         HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
         HMI_WRITE("sysTest.heat_txt.txt=\"%s\"",device_status.heat_power);
-//        HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
+//      HMI_WRITE("sysTest.switchHeat.val=%d",device_status.heat_status);
     }
     //立即上传
     else if(strstr(rx_buffer,"uploaddata")!=RT_NULL)
@@ -1254,8 +1284,27 @@ static void HMI_Decode(void)
         HMI_WRITE("rtc3=%d",tm.tm_hour);
         HMI_WRITE("rtc4=%d",tm.tm_min);
         HMI_WRITE("rtc5=%d",tm.tm_sec);
-        device_status.selfcheck_ws = 2;
-        LOG_W("开始自检:%d",device_status.selfcheck_ws);
+        if(device_status.selfcheck_ws==2)
+        {
+            LOG_I("自检进行中!");
+        }else {
+            device_status.selfcheck_ws = 2;
+            LOG_W("开始自检:%d",device_status.selfcheck_ws);
+        }
+    }else if(strstr(rx_buffer,"haichong")!=NULL)
+    {
+        _485_play(sound122, 4);
+        HMI_WRITE("sysTest.result.txt=\"害虫测试!\"");
+        ctr_Motor_Driver_Power(ON);
+        //使用硬件定时器控制
+        device_status.autotakepic = 10;
+
+    }else if(strstr(rx_buffer,"yichong")!=NULL)
+    {
+        _485_play(sound122, 4);
+        HMI_WRITE("sysTest.result.txt=\"益虫测试!\"");
+        ctr_Motor_Driver_Power(ON);
+        device_status.autotakepic = 11;
     }
 }
 
@@ -1263,7 +1312,6 @@ static void HMI_Decode(void)
 //入口函数-电机控制及
 static void Ctr_Mortor_entry(void* parameter)
 {
-   rt_int16_t motor_current = 0;     //
    rt_uint16_t num_up_open = 200;    //20s
    rt_uint16_t num_up_close = 200;   //
    rt_uint16_t num_down_open = 200;  //
@@ -1274,20 +1322,8 @@ static void Ctr_Mortor_entry(void* parameter)
    //int current_t[200];
    /*孢子仪拍照数量*/
    rt_uint16_t photo_setup = 0;
-   #if Color_EN ==1
-   ctr_Color_board(RESET, 1200);
-   #endif
     while(1)
     {
-        #if Color_EN ==1
-        //定时执行把粘虫板更换的操作,每天一次
-        if(device_status.run_sta==5)
-        {
-            rt_thread_delay(2000);
-            device_status.run_sta = 0;
-            ctr_Color_board(OPEN, 1000);
-        }
-        #endif
         #if 1
         time_t time_reset12V;
         time(&time_reset12V);
@@ -1519,6 +1555,16 @@ static void Ctr_Mortor_entry(void* parameter)
             device_status.run_sta = 0;
             ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
          }
+        else if (device_status.autotakepic==10) {
+            hwtimer2_pwm3_output(1,20000,1,0);
+            device_status.autotakepic = 0;
+        }
+
+        else if (device_status.autotakepic==11) {
+            hwtimer2_pwm3_output(1,20000,1,1);
+            device_status.autotakepic = 0;
+        }
+
         if(device_status.fsl_sw==1)
         {
             ctr_Petroleum_jelly(10);
@@ -1676,7 +1722,7 @@ static void Ctr_Mortor_entry(void* parameter)
         }
         if(device_status.selfcheck_ws==2)
         {
-            selfcheck(1);
+           selfcheck(1);
         }
         rt_thread_delay(100);
     }
@@ -1976,7 +2022,7 @@ void Check_ParamConfig(void)
 #if SENSOR_EN==1
         mb_master_samlpe();
 #endif
-
+        thread_485_play();
 #if ROBOT_EN == 0
         uint16_t connect_num=0;
         //等待联网,
@@ -1993,7 +2039,7 @@ void Check_ParamConfig(void)
             connect_num++;
             LOG_I("联网中......%d",connect_num);
             //超时时间为3分钟
-            if(connect_num==180)
+            if(connect_num==180) //180
             {
                 device_status.timeSwitch = 0;
                 LOG_W("Time not set:%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);

+ 23 - 13
Application_cbd_apm32f1/applications/sample_mb_master.c

@@ -39,23 +39,29 @@ extern USHORT   usMRegInBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_INPUT_NREGS];
 extern SHORT usMRegHoldBuf[MB_MASTER_TOTAL_SLAVE_NUM][M_REG_HOLDING_NREGS];
 
 
+
+
+extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS)
+{
+    UCHAR SLAVE_ADDRESS = 0x10;
+    USHORT REGISTER_ADDRESS = 0x9c41;
+    eMBMasterReqErrCode _code_ret = eMBMasterReqWriteMultipleHoldingRegister(SLAVE_ADDRESS,          /* salve address */
+                                                                  REGISTER_ADDRESS,   /* register start address */
+                                                                  NREGS,     /* register total number */
+                                                                  Buffer,                /* data to be written */
+                                                                  RT_WAITING_FOREVER); /* timeout */
+    return _code_ret;
+}
+
+
+
 static void send_thread_entry(void *parameter)
 {
     BOOL IN_3A = 0;           //数据解析方式设置
     eMBMasterReqErrCode error_code = MB_MRE_NO_ERR;
     rt_uint16_t error_count = 0;
-    //USHORT data[3] = {0};
     while (1)
     {
-        /* Test Modbus Master */
-//        data[0] = (USHORT)(rt_tick_get() / 10);
-//        data[1] = (USHORT)(rt_tick_get() % 10);
-//        data[3] = data[1] + 1;
-//        error_code = eMBMasterReqWriteMultipleHoldingRegister(SLAVE_ADDR,          /* salve address */
-//                                                              MB_SEND_REG_START,   /* register start address */
-//                                                              MB_SEND_REG_NUM,     /* register total number */
-//                                                              data,                /* data to be written */
-//                                                              RT_WAITING_FOREVER); /* timeout */
 
         #if 0
         error_code = eMBMasterReqReadInputRegister(SLAVE_ADDR, MB_SEND_REG_START,3,1000);
@@ -80,7 +86,10 @@ static void send_thread_entry(void *parameter)
         }
         #endif
         if(device_status.sensor_485_sta!=200){
+
             error_code = eMBMasterReqReadHoldingRegister(SLAVE_ADDR, MB_SEND_REG_START,2,1000);//读多个保持寄存器
+            // 发送写多个保持寄存器请求
+            //error_code = eMBMasterReqWriteMultipleHoldingRegister(SLAVE_ADDRESS,REGISTER_ADDRESS,REGISTER_COUNT,usDataBuffer,1000);
             rt_kprintf("eMBMasterReqReadHoldingRegister: %d \n",error_code);//一直出错,我便把错误返回值打印出来
             if(error_code==0)
             {
@@ -117,7 +126,6 @@ static void mb_master_poll(void *parameter)
 {
     eMBMasterInit(MB_RTU, PORT_NUM, PORT_BAUDRATE, PORT_PARITY);
     eMBMasterEnable();
-
     while (1)
     {
         eMBMasterPoll();
@@ -127,6 +135,7 @@ static void mb_master_poll(void *parameter)
 
 int mb_master_samlpe(void)
 {
+    USHORT qidong[] = {0xbfd8,0xd6c6,0xc4a3,0xbfe9,0xd2d1,0xc6f4,0xb6af};
     static rt_uint8_t is_init = 0;
     rt_thread_t tid1 = RT_NULL, tid2 = RT_NULL;
 
@@ -145,7 +154,7 @@ int mb_master_samlpe(void)
         goto __exit;
     }
 
-    tid2 = rt_thread_create("md_m_send", send_thread_entry, RT_NULL, 512, MB_SEND_THREAD_PRIORITY, 10);
+    tid2 = rt_thread_create("md_m_send", send_thread_entry, RT_NULL, 1024, MB_SEND_THREAD_PRIORITY, 10);
     if (tid2 != RT_NULL)
     {
         rt_thread_startup(tid2);
@@ -154,8 +163,9 @@ int mb_master_samlpe(void)
     {
         goto __exit;
     }
-
     is_init = 1;
+    rt_thread_delay(10000);
+    _485_play(qidong,7);
     return RT_EOK;
 
 __exit:

+ 44 - 18
Application_cbd_apm32f1/applications/selfcheck.c

@@ -54,6 +54,17 @@ int selfcheck(uint8_t type)
     LOG_I("删除线程workloop:%d",thread_delete_workloop());
     //初始化硬件
     HardWare_Init(0);
+    //关闭上仓门
+    ctr_cangmen_down(CLOSE);
+    //关闭下仓门
+    ctr_cangmen_up(CLOSE);
+    for(int c=0;c<8;c++)
+    {
+        rt_thread_delay(2000);
+        HMI_WRITE("sysSet.va0.txt=\"等待上下仓门复位完成......\"");
+    }
+    ctr_cangmen_up(OFF);
+    ctr_cangmen_down(OFF);
     /********************************************************/
     //读取5次电流值,取平均值
     for(int i = 0;i<5;i++)
@@ -72,7 +83,12 @@ int selfcheck(uint8_t type)
         HMI_WRITE("selfcheck.t13.bco=2024");
         device_status.C01 &= ~(1<<12);
     }
-    if(atoi(device_status.gps_state)==0)
+    HMI_WRITE("sysSet.va0.txt=\"待机电流:%d\"",current_);
+    char *readinfo =  makeJson_ReadInfo();
+    DTU_Write("%s",readinfo);
+    rt_free(readinfo);
+    rt_thread_delay(1000);
+    if(atoi(device_status.gps)==0)
     {
         HMI_WRITE("selfcheck.t12.bco=63488");
         device_status.C01 |= (1<<11);
@@ -82,6 +98,7 @@ int selfcheck(uint8_t type)
         HMI_WRITE("selfcheck.t12.bco=2024");
         device_status.C01 &= ~(1<<11);
     }
+    rt_thread_delay(1000);
     if(Read_Ntc_Voltage()==0)
     {
         HMI_WRITE("selfcheck.t15.bco=63488");
@@ -89,6 +106,7 @@ int selfcheck(uint8_t type)
     else{
         HMI_WRITE("selfcheck.t15.bco=2024");
     }
+    rt_thread_delay(1000);
     if(device_status.bat_status==0)
     {
         HMI_WRITE("selfcheck.t5.bco=2024");
@@ -99,7 +117,8 @@ int selfcheck(uint8_t type)
         HMI_WRITE("selfcheck.t5.bco=63488");
         device_status.C01 |= (1<<4);
     }
-    if(device_status.rain_status)
+    rt_thread_delay(1000);
+    if(Read_Rain_Voltage()==0)
     {
         HMI_WRITE("selfcheck.t6.bco=63488");
         device_status.C01 |= (1<<5);
@@ -109,7 +128,7 @@ int selfcheck(uint8_t type)
         device_status.C01 &= ~(1<<5);
         HMI_WRITE("selfcheck.t6.bco=2024");
     }
-
+    rt_thread_delay(1000);
     if(device_status.temp_status)
     {
         HMI_WRITE("selfcheck.t8.bco=63488");
@@ -120,8 +139,13 @@ int selfcheck(uint8_t type)
         device_status.C01 &= ~(1<<7);
         HMI_WRITE("selfcheck.t8.bco=2024");
     }
-
-    if(device_status.sun_status)
+    int sensor_light_value = 0;
+    for(int i = 0;i<3;i++)
+    {
+        sensor_light_value += Read_Light_Voltage();
+        rt_thread_delay(500);
+    }
+    if(sensor_light_value<50)
     {
         HMI_WRITE("selfcheck.t7.bco=63488");
         device_status.C01 |= (1<<6);
@@ -132,6 +156,7 @@ int selfcheck(uint8_t type)
         HMI_WRITE("selfcheck.t7.bco=2024");
     }
 
+    HMI_WRITE("sysSet.va0.txt=\"光控传感器采样数值:%d\"",Read_Light_Voltage());
     rt_thread_delay(1000);
     /********************************************************/
     ctr_lamp(ON, 1);        //打开镇流器
@@ -149,13 +174,13 @@ int selfcheck(uint8_t type)
     {
         HMI_WRITE("selfcheck.t1.bco=2024");
         device_status.C01 &= ~(1<<0);
-        HMI_WRITE("sysSet.va0.txt=\"灯管正常\"");
+        HMI_WRITE("sysSet.va0.txt=\"灯管正常:%d\"",current_open);
     }
     else
     {
         HMI_WRITE("selfcheck.t1.bco=63488");
         device_status.C01 |= (1<<0);
-        HMI_WRITE("sysSet.va0.txt=\"灯管异常\"");
+        HMI_WRITE("sysSet.va0.txt=\"灯管异常:%d\"",current_open);
     }
     rt_thread_delay(1000);
     /********************************************************/
@@ -172,12 +197,12 @@ int selfcheck(uint8_t type)
     {
         HMI_WRITE("selfcheck.t9.bco=2024");
         device_status.C01 &= ~(1<<8);
-        HMI_WRITE("sysSet.va0.txt=\"上仓门正常\"");
+        HMI_WRITE("sysSet.va0.txt=\"上仓门正常:%d\"",current_open);
     }
     else{
         HMI_WRITE("selfcheck.t9.bco=63488");
         device_status.C01 |= (1<<8);
-        HMI_WRITE("sysSet.va0.txt=\"上仓门故障\"");
+        HMI_WRITE("sysSet.va0.txt=\"上仓门故障:%d\"",current_open);
     }
     rt_thread_delay(1000);
     /********************************************************/
@@ -194,12 +219,12 @@ int selfcheck(uint8_t type)
     {
         HMI_WRITE("selfcheck.t10.bco=2024");
         device_status.C01 &= ~(1<<9);
-        HMI_WRITE("sysSet.va0.txt=\"下仓门正常\"");
+        HMI_WRITE("sysSet.va0.txt=\"下仓门正常:%d\"",current_open);
     }
     else{
         HMI_WRITE("selfcheck.t10.bco=63488");
         device_status.C01 |= (1<<9);
-        HMI_WRITE("sysSet.va0.txt=\"下仓门故障\"");
+        HMI_WRITE("sysSet.va0.txt=\"下仓门故障:%d\"",current_open);
     }
     //开启加热
     rt_thread_delay(1000);
@@ -208,7 +233,7 @@ int selfcheck(uint8_t type)
     {
         HMI_WRITE("selfcheck.t2.bco=2024");
         device_status.C01 &= ~(1<<1);
-        HMI_WRITE("sysSet.va0.txt=\"加热正常\"");
+        HMI_WRITE("sysSet.va0.txt=\"加热正常:%d\"",atoi(device_status.heat_power));
     }
     else {
         ctr_Heat(ON);
@@ -224,13 +249,13 @@ int selfcheck(uint8_t type)
         {
             HMI_WRITE("selfcheck.t2.bco=2024");
             device_status.C01 &= ~(1<<1);
-            HMI_WRITE("sysSet.va0.txt=\"加热正常\"");
+            HMI_WRITE("sysSet.va0.txt=\"加热正常:%d\"",atoi(device_status.heat_power));
         }
         else
         {
             HMI_WRITE("selfcheck.t2.bco=63488");
             device_status.C01 |= (1<<1);
-            HMI_WRITE("sysSet.va0.txt=\"加热故障\"");
+            HMI_WRITE("sysSet.va0.txt=\"加热故障:%d\"",atoi(device_status.heat_power));
         }
     }
     ctr_Heat(OFF);
@@ -241,7 +266,7 @@ int selfcheck(uint8_t type)
     {
         rt_timer_start(timer_takephoto);
         HK_TakePhoto();
-        for(int i = 30;i>0;i--)
+        for(int i = 15;i>0;i--)
         {
             HMI_WRITE("sysSet.va0.txt=\"拍照中...%d\"",i);
             rt_thread_delay(1000);
@@ -264,18 +289,19 @@ int selfcheck(uint8_t type)
     }
     current_open = calculate_average(current_i,5);
     rt_thread_delay(1000);
-    if(atoi(device_status.power)-current_open>150)
+    if(current_open-current_>150)
     {
         HMI_WRITE("selfcheck.t11.bco=2024");
         device_status.C01 &= ~(1<<10);
-        HMI_WRITE("sysSet.va0.txt=\"清扫正常\"");
+        HMI_WRITE("sysSet.va0.txt=\"清扫正常:%d\"",atoi(device_status.power));
     }
     else
     {
         HMI_WRITE("selfcheck.t11.bco=63488");
         device_status.C01 |= (1<<10);
-        HMI_WRITE("sysSet.va0.txt=\"清扫故障\"");
+        HMI_WRITE("sysSet.va0.txt=\"清扫故障:%d\"",atoi(device_status.power));
     }
+    rt_thread_delay(1000);
     /*******************************************************/
     HMI_WRITE("sysSet.va0.txt=\"故障码:%d\"",device_status.C01);
     char *js = makeJson_C01_Warn(device_status.C01,1.0);

+ 21 - 3
Application_cbd_apm32f1/applications/sht30_collect.c

@@ -186,6 +186,7 @@ static void sht30_collect_thread_entry(void *parameter)
         rt_thread_mdelay(5000);
     }
 }
+
 static void Power_ReadCheck(void *parameter)
 {
     int rain_cnt = 0;
@@ -197,8 +198,15 @@ static void Power_ReadCheck(void *parameter)
     rt_thread_delay(1000);
     while(1)
     {
+        #if PCB_V1 == 0
         rt_uint16_t _24v_current_int = moving_average_filter_update(filter,Read_Real_Current());
-        sprintf(device_status.power,"%.2f",(float)(_24v_current_int-2430)/0.4);
+        if(_24v_current_int-2430>0)
+        {
+            sprintf(device_status.power,"%.2f",(float)(_24v_current_int-2430)/0.4);
+        }else {
+            sprintf(device_status.power,"0.0");
+        }
+
         //消除误差
         if(Read_Heat_Current()-2450<10)
         {
@@ -209,7 +217,11 @@ static void Power_ReadCheck(void *parameter)
             //rt_uint16_t _heat_current_int = moving_average_filter_update(filter_hi,Read_Heat_Current());
             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)
         {
@@ -342,8 +354,14 @@ int Read_Real_Current(void)
     adc1_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_1);
     /* 关闭通道 */
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_1);
+    #if PCB_V1 == 0
     //LOG_D("Read_Real_Current:%d,%d",adc1_value,adc1_value * REFER_VOLTAGE/CONVERT_BITS*15);
     return  (adc1_value * REFER_VOLTAGE/CONVERT_BITS*15);
+    #else
+    rt_adc_enable(adc_dev, 17);
+    in_adc_17 = rt_adc_read(adc_dev, 17);
+    return  (int)((ADC_VOL_BASE * (adc1_value*1.0)/(in_adc_17*1.0))*100000);
+    #endif
 }
 
 int Read_Heat_Current(void)
@@ -424,7 +442,7 @@ int Read_Rain_Voltage(void)
     adc11_light = rt_adc_read(adc_dev,ADC_DEV_CHANNLE_3);
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_3);
     HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
-    //rt_kprintf("read rain value:%d\n",adc11_light);
+    //LOG_D("read rain value:%d",adc11_light);
     return adc11_light;
 //    rt_pin_mode(RAIN_PIN,PIN_MODE_INPUT);
 //    return rt_pin_read(RAIN_PIN);

+ 43 - 0
Application_cbd_apm32f1/drivers/board.c

@@ -14,6 +14,7 @@
 
 
 TIM_HandleTypeDef htim3;
+TIM_HandleTypeDef htim2;
 TIM_HandleTypeDef htim8;
 ADC_HandleTypeDef hadc1;
 SPI_HandleTypeDef hspi1;
@@ -122,6 +123,47 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
   /* USER CODE END TIM8_MspPostInit 1 */
   }
 }
+
+static void MX_TIM2_Init(void)
+{
+
+  /* USER CODE BEGIN TIM2_Init 0 */
+   __HAL_RCC_TIM2_CLK_ENABLE();
+  /* USER CODE END TIM2_Init 0 */
+
+  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
+  TIM_MasterConfigTypeDef sMasterConfig = {0};
+
+  /* USER CODE BEGIN TIM2_Init 1 */
+
+  /* USER CODE END TIM2_Init 1 */
+  htim2.Instance = TIM2;
+  htim2.Init.Prescaler = 0;
+  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
+  htim2.Init.Period = 65535;
+  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
+  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
+  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
+  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
+  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
+  {
+    Error_Handler();
+  }
+  /* USER CODE BEGIN TIM2_Init 2 */
+
+  /* USER CODE END TIM2_Init 2 */
+
+}
+
 static void MX_TIM3_Init(void)
 {
 
@@ -441,6 +483,7 @@ static int SPI1_INIT(void)
 
 static int PWM_INIT(void)
 {
+    MX_TIM2_Init();
     MX_TIM3_Init();
     MX_TIM8_Init();
     return RT_EOK;

+ 4 - 2
Application_cbd_apm32f1/drivers/board.h

@@ -34,7 +34,7 @@ extern "C"
 #define ROM_END                ((uint32_t)(ROM_START + ROM_SIZE))
 
 #define RAM_START              (0x20000000)
-#define RAM_SIZE               (64 * 1024)
+#define RAM_SIZE               (128 * 1024)  //stm32 ram=64kb
 #define RAM_END                (RAM_START + RAM_SIZE)
 
 /*-------------------------- ROM/RAM CONFIG END --------------------------*/
@@ -250,8 +250,10 @@ extern "C"
  *
  */
 
-/*#define BSP_USING_TIM*/
+#define BSP_USING_TIM
 #ifdef BSP_USING_TIM
+#define BSP_USING_TIM2
+#define BSP_USING_TIM3
 /*#define BSP_USING_TIM15*/
 /*#define BSP_USING_TIM16*/
 /*#define BSP_USING_TIM17*/

+ 7 - 2
Application_cbd_apm32f1/drivers/drv_clk.c

@@ -17,7 +17,7 @@
 #define DBG_LVL DBG_LOG
 #include <rtdbg.h>
 
-void system_clock_config(int target_freq_Mhz)
+static void system_clock_config(void)
 {
     RCC_OscInitTypeDef RCC_OscInitStruct = {0};
     RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
@@ -78,6 +78,11 @@ INIT_BOARD_EXPORT(clock_information);
 
 void clk_init(char *clk_source, int source_freq, int target_freq)
 {
-    system_clock_config(target_freq);
+    /*
+     * Use SystemClock_Config generated from STM32CubeMX for clock init
+     * system_clock_config(target_freq);
+     */
+    //extern void SystemClock_Config(void);
+    system_clock_config();
 }
 

+ 3 - 0
Application_cbd_apm32f1/drivers/drv_hwtimer.c

@@ -463,6 +463,8 @@ void TIM1_BRK_TIM15_IRQHandler(void)
 }
 #endif
 
+
+
 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
 {
 #ifdef BSP_USING_TIM2
@@ -549,6 +551,7 @@ static int stm32_hwtimer_init(void)
 
     return result;
 }
+
 INIT_BOARD_EXPORT(stm32_hwtimer_init);
 
 #endif /* RT_USING_HWTIMER */

+ 1 - 2
Application_cbd_apm32f1/packages/ota_downloader-v1.0.0/src/ymodem_ota.c

@@ -112,10 +112,9 @@ void ymodem_ota(uint8_t argc, char **argv)
             return;
         }
     }
-    rt_console_set_device("uart2");
     rt_kprintf("Warning: Ymodem has started! This operator will not recovery.\n");
     rt_kprintf("Please select the ota firmware file and use Ymodem to send.\n");
-
+    rt_console_set_device("uart2");
     if (!rym_recv_on_device(&rctx, rt_console_get_device(), RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
                             ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND))
     {

+ 25 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,28 @@
+
+# 2025-04-15 更新说明
+#define VERSION_HK          "2.4.41(HK)"            //4.0海康-1200W
+#define VERSION_HK_2000W    "2.10.4(2000W)"         //4.0水稻 
+1. 消息队列满时清空消息队列;
+2. V4 清扫时间由40s降低为20s;
+3. 自检增加了更多的调试信息
+# 2025-04-10 更新说明
+#define VERSION_HK          "2.4.41(HK)"            //4.0海康-1200W
+#define VERSION_HK_2000W    "2.9.4(2000W)"         //4.0水稻 
+1. 光控检测优化,采集ADC数值进行检测,如果为0表示故障;
+2. 增加加热电流数据上报,字段current_heat;
+3. 屏幕震动时间设置单位由秒改为毫秒
+
+# 2025-03-18 更新说明
+#define VERSION_HK          "2.4.41(HK)"            //4.0海康-1200W
+#define VERSION_HK_2000W    "2.5.4(2000W)"         //4.0水稻 
+1. 灯管故障检测调整,电流值滤波;
+
+# 2025-03-18 更新说明
+#define VERSION_HK          "2.3.41(HK)"            //4.0海康-1200W
+#define VERSION_HK_2000W    "2.4.4(2000W)"         //4.0水稻 
+1. 修复备用电池供电时,电流显示负值;
+2. 修复自检定位状态始终显示失败的问题,字段错误,使用了gps_state,正确是gps
+3. 修复自检过程中点击自检重新开始自检.
 # 2025-01-23 更新说明
 1.  项目重建,使用rtthread4.1.1版本;
 2. 串口驱动框架适配V2版本

+ 2 - 2
CBD_FOTA_BootLoader/.settings/projcfg.ini

@@ -1,5 +1,5 @@
 #RT-Thread Studio Project Configuration
-#Fri Jan 10 16:52:36 CST 2025
+#Fri Mar 28 11:40:56 CST 2025
 project_type=rtt
 chip_name=STM32F103RE
 cpu_name=None
@@ -18,5 +18,5 @@ uart_name=uart1
 tx_pin_name=PA9
 rtt_nano_path=
 output_project_path=D\:\\RT-ThreadStudio\\workspace\\IOT_CBD_BZY_CTRL
-hardware_adapter=J-Link
+hardware_adapter=ST-LINK
 project_name=CBD_FOTA_BootLoader

+ 4 - 1
CBD_FOTA_BootLoader/drivers/drv_flash_f1.c

@@ -20,7 +20,7 @@
 #include "fal.h"
 #endif
 
-//#define DRV_DEBUG
+#define DRV_DEBUG
 #define LOG_TAG                "drv.flash"
 #include <drv_log.h>
 
@@ -91,6 +91,7 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
         LOG_E("write outrange flash size! addr is (0x%p)", (void *)(addr + size));
         return -RT_EINVAL;
     }
+    //LOG_D("stm32_flash_write:(0x%p)",addr);
     //APM32此处关闭中断
     __disable_irq();
     HAL_FLASH_Unlock();
@@ -102,6 +103,7 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
             if (*(rt_uint32_t *)addr != *(rt_uint32_t *)buf)
             {
                 result = -RT_ERROR;
+                LOG_D("addr ERROR!");
                 break;
             }
             addr += 4;
@@ -109,6 +111,7 @@ int stm32_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, size_t size)
         }
         else
         {
+            LOG_E("HAL_FLASH_Program ERROR at:(0x%p)!",addr);
             result = -RT_ERROR;
             break;
         }

+ 1 - 1
CBD_FOTA_BootLoader/libraries/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h

@@ -140,7 +140,7 @@ typedef struct
   */
 #define FLASH_LATENCY_0            0x00000000U               /*!< FLASH Zero Latency cycle */
 #define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
-#define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
+#define FLASH_LATENCY_2            FLASH_ACR_LATENCY_2       /*!< FLASH Two Latency cycles */
 
 /**
   * @}

+ 1 - 1
CBD_FOTA_BootLoader/packages/fal-v0.5.0/src/fal_partition.c

@@ -434,7 +434,7 @@ int fal_partition_write(const struct fal_partition *part, uint32_t addr, const u
     ret = flash_dev->ops.write(part->offset + addr, buf, size);
     if (ret < 0)
     {
-        log_e("Partition write error! Flash device(%s) write error!", part->flash_name);
+        log_e("Partition write error! Flash device(%s) write error:%d!", part->flash_name,ret);
     }
 
     return ret;

+ 1 - 1
CBD_FOTA_BootLoader/packages/ota_downloader-latest/src/ymodem_ota.c

@@ -112,7 +112,7 @@ void ymodem_ota(uint8_t argc, char **argv)
 
     rt_kprintf("Warning: Ymodem has started! This operator will not recovery.\n");
     rt_kprintf("Please select the ota firmware file and use Ymodem to send.\n");
-    rt_console_set_device("uart2");
+    //rt_console_set_device("uart2");
     if (!rym_recv_on_device(&rctx, rt_console_get_device(), RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
                             ymodem_on_begin, ymodem_on_data, NULL, RT_TICK_PER_SECOND))
     {