zhunk 1 gadu atpakaļ
vecāks
revīzija
f5004135c0

+ 0 - 14
Application_BZYV2-NHT/applications/control.c

@@ -2267,20 +2267,6 @@ u_int8_t alarmCheck(u_int8_t starthour,u_int8_t endhour)
 /* 入口函数-工作状态检测 */
 static void Work_status_thread_entry(void *parameter)
 {
-//    static uint16_t sun_status_num = 120;
-//    //如果是光控定时,进行光控监测的消抖
-//     if(device_status.timeSwitch==0&&device_status.sun_status==0)
-//     {
-//        rt_kprintf("光控定时!!!\n");
-//        while(sun_status_num!=0)
-//        {
-//            sun_status_num--;
-//            rt_thread_delay(1000);
-//            rt_kprintf("开机光控检测:%d\n",sun_status_num);
-//        }
-//        device_status.light_over_tim = device_status.sunBar * 3600;
-//        device_status.test_flag = 0;
-//     }
      while(1)
      {
             while(alarmCheck(device_status.collecting_sh1,device_status.collecting_eh1) == ON)

+ 1 - 1
Application_cbd_apm32f1/.config

@@ -80,7 +80,7 @@ CONFIG_RT_USING_DEVICE=y
 # CONFIG_RT_USING_DEVICE_OPS is not set
 # CONFIG_RT_USING_INTERRUPT_INFO is not set
 CONFIG_RT_USING_CONSOLE=y
-CONFIG_RT_CONSOLEBUF_SIZE=256
+CONFIG_RT_CONSOLEBUF_SIZE=1024
 CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
 # end of Kernel Device Object
 

+ 1 - 1
Application_cbd_apm32f1/.config.old

@@ -133,7 +133,7 @@ CONFIG_RT_USING_SERIAL=y
 CONFIG_RT_USING_SERIAL_V2=y
 CONFIG_RT_SERIAL_USING_DMA=y
 # CONFIG_RT_USING_CAN is not set
-# CONFIG_RT_USING_HWTIMER is not set
+CONFIG_RT_USING_HWTIMER=y
 # CONFIG_RT_USING_CPUTIME is not set
 # CONFIG_RT_USING_I2C is not set
 # CONFIG_RT_USING_PHY is not set

BIN
Application_cbd_apm32f1/.settings/.rtmenus


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

@@ -1,5 +1,5 @@
 #RT-Thread Studio Project Configuration
-#Thu Jan 23 17:40:17 CST 2025
+#Wed Feb 12 11:59:53 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=Application_cbd_apm32f1

+ 5 - 0
Application_cbd_apm32f1/applications/beep.c

@@ -85,6 +85,11 @@ void beep_set(uint32_t freq, uint32_t volume)
     rt_pwm_set(pwm_device, BEEP_PWM_CH, period, pulse);//channel,period,pulse
     rt_pwm_enable(pwm_device, BEEP_PWM_CH);
 }
+
+void pwm_stop(void){
+    rt_pwm_disable(pwm_device, BEEP_PWM_CH);
+}
+
 void Beep_Tip(uint16_t volnum)
 {
     rt_pin_mode(Beep, PIN_MODE_OUTPUT);

+ 1 - 0
Application_cbd_apm32f1/applications/beep.h

@@ -21,6 +21,7 @@ int pwm_off(uint8_t pwn_ch,rt_uint32_t pwm_freq);
 int pwm_on(uint8_t pwn_ch,rt_uint32_t pwm_freq);
 void beep_set(uint32_t freq, uint32_t volume);    //蜂鸣器设定
 void Beep_Tip(uint16_t volnum);
+void pwm_stop(void);
 /*****************************4.0******************************/
 void Motor_Qingsao_L_PWM(uint8_t on_off);
 void Motor_Qingsao_R_PWM(uint8_t on_off);

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 489 - 1957
Application_cbd_apm32f1/applications/control.c


+ 43 - 21
Application_cbd_apm32f1/applications/control.h

@@ -117,6 +117,7 @@ typedef struct  _packed
     uint8_t heat_sta;        //加热报警0-正常,1-异常
     uint8_t led_sta;         //补光灯报警0-正常,1-异常
     uint8_t selfcheck_ws;    //自检开关1-北大荒,2-标配
+    uint8_t step_focus;
     #if BOOT_ERR == 1
     uint8_t gps_inuse;
     uint8_t gps_view;
@@ -130,6 +131,8 @@ typedef struct  _packed
     rt_uint32_t light_over_tim;     //光控定时差秒数,镇流器的结束时间
     rt_uint32_t data_plan;          //流量套餐
     rt_uint32_t expiry_date;        //到期时间
+    double focus_value;
+
     int passWord;              //初始密码
     double process;
     long photo_stamp;           //采集时间戳
@@ -166,6 +169,27 @@ typedef struct  _packed
     char photolink[128];        //图片地址
 }Device_Status_typedef;
 
+
+/**************滑台数据********************/
+typedef struct
+{
+
+    uint32_t xdis;           //x轴坐标移动距离
+    uint32_t ydis;
+    uint32_t zdis;           //z轴坐标移动距离
+    uint16_t dxdis;          //x轴坐标蛇形移动间距距离
+    uint16_t dzdis;          //z轴坐标蛇形移动间距距离
+    uint8_t xdir;            //x轴坐标移动方向
+    uint8_t ydir;            //y轴坐标移动方向
+    uint8_t zdir;            //z轴坐标移动方向
+    uint8_t en_slide;        //
+    uint8_t zccwl_on;        //z轴限位开关信号   高电平为触发限位
+    uint8_t xccwl_on;        //x轴限位开关信号   高电平为触发限位
+    uint8_t pulse_period;    //滑台的运动速度  1为最高
+    uint8_t stop_flag;       //滑台停止标志位
+}Device_slide_typedef;
+
+
 /************************************************/
 #define ON 1
 #define OFF 0
@@ -206,7 +230,6 @@ typedef struct  _packed
 #define HK_IO GET_PIN(B,14)     //备用触发拍照
 //清扫限位
 #define CLEAR_R_LIMIT GET_PIN(C,13)
-#define CLEAR_L_LIMIT GET_PIN(B,9)
 
 /*****************************4.0定制多光源*********************************/
 #define LAMP_1_SW GET_PIN(B,10)
@@ -215,7 +238,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)
 #define CTR_DWC_LIMIT GET_PIN(B,8)
@@ -257,7 +279,7 @@ void ctr_turnv5(void);
 #define  TURN_ZP_L GET_PIN(B,1)
 //转盘限位
 #define LIMIT_0 GET_PIN(C,13)
-#define LIMIT_90 GET_PIN(B,9)
+
 //散热
 #define  Cool_Fan_R GET_PIN(C, 5)
 #define  Cool_Fan_L GET_PIN(C, 4)
@@ -278,20 +300,6 @@ void ctr_Petroleum_jelly(rt_uint32_t delay);        //凡士林
 #define FAN_I   GET_PIN(B,11)
 uint8_t ctr_Fan_IN(uint8_t status_ws);
 uint8_t ctr_Fan_PUT(uint8_t status_ws);
-/*******************************定制展厅机器人************************************/
-#define LIMIT_OPEN GET_PIN(B,8)
-#define LIMIT_CLOSE GET_PIN(B,5)
-#define Motor_Power GET_PIN(B,10)                       //电机驱动供电
-#define Motor_Direction_Button GET_PIN(B,9)             //IO输入,检测按键状态,用于控制方向
-#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);          //加热
@@ -319,15 +327,29 @@ void WorkTask_XCT(void);
 void WorkCheck(void);               //工作检测
 void WorkTask(void);                //工作任务
 //
-/***********************孢子仪****************************/
+/***********************孢子仪2.0****************************/
+#define X_ 0
+#define Y_ 1
+#define Z_ 2
+
+#define Limit_Motor_X GET_PIN(C,13)      //IO输入,X轴限位
+#define Limit_Motor_Z GET_PIN(B,9)     //IO输入,Y轴限位
+#define Limit_Motor_Y GET_PIN(B,8)     //IO输入,Z轴限位
+
+uint8_t ctr_swz(uint8_t status_swz);    //z轴的电机开关控制
+
+uint32_t ctr_move(uint8_t DIR_,uint8_t dir_,uint32_t dis_,uint8_t pulse);
+
+void slidelock();    //电机移动完毕后上锁
+
+void turnlimit(void);   //位移兼限位开关功能
 
 /***************************************************/
 //线程
-int Control_clear(void);
+
 int Workstatus_check(void);
 int Work_Loop_Task(void);
-int Control_heat(void);
-
+int slide_Fresh(void);
 
 int thread_delete_workloop(void);
 int thread_restart_workloop(void);

+ 121 - 391
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -36,6 +36,7 @@
 
 
 Device_Status_typedef device_status;
+Device_slide_typedef slide_para;
 DataTemp data_arry;
 
 void list_mem(void);
@@ -148,20 +149,6 @@ static void dtu_thread_entry_recv(void *parameter)
             rx_length = rt_device_read(msg.dev, 0, &rx_buffer[0], rx_length);
             rx_buffer[rx_length] = '\0';
             LOG_D("recv data:%s",rx_buffer);
-            if(strstr(rx_buffer,"{")==RT_NULL||strstr(rx_buffer,"}")==RT_NULL)
-            {
-                if(device_status.dtype==7)
-                {
-                    HMI_WRITE("sysTest.result.txt=\"%s\"",rx_buffer);
-                }
-
-                if(device_status.dtype==3)
-                {
-                    HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
-                    rt_timer_stop(timer_uart2);
-                }
-
-            }
             //过滤异常数据
             char str_check_head[2];
             char str_check_end[2];
@@ -191,33 +178,9 @@ static void dtu_thread_entry_recv(void *parameter)
                    //rt_kprintf("%s",rx_buffer);
                  }
          }
-         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);
-
     }
 }
+#if 0
 /*入口函数-指令发送*/
 static void dtu_thread_entry_send(void *parameter)
 {
@@ -335,7 +298,7 @@ static void dtu_thread_entry_send(void *parameter)
     rt_thread_mdelay(1000);
     }
 }
-
+#endif
 /* 创建线程 */
 int dtu_data_play(void)
 {
@@ -352,6 +315,7 @@ int dtu_data_play(void)
     }
     /* 设置接收回调函数 */
     rt_device_set_rx_indicate(dtuserial, dtu_input);
+    #if 0
     /*创建线程-指令发送*/
     dtu_send_data = rt_thread_create("DTU_Uart_thread_send",
                                     dtu_thread_entry_send,RT_NULL,
@@ -359,6 +323,7 @@ int dtu_data_play(void)
                                     3,                              //优先级高是为了保证数据上传的频率的精确度
                                     20          //时间片
             );
+    #endif
     /* 创建线程-指令接收解析*/
     dtu_recv_data = rt_thread_create("DTU_Uart_thread_recv",
             dtu_thread_entry_recv, RT_NULL,
@@ -366,8 +331,8 @@ int dtu_data_play(void)
             DTU_THREAD_PRIORITY,
             DTU_THREAD_TIMESLICE);
     /* 如果获得线程控制块,启动这个线程 */
-    if(dtu_send_data!=RT_NULL)
-        rt_thread_startup(dtu_send_data);
+//    if(dtu_send_data!=RT_NULL)
+//        rt_thread_startup(dtu_send_data);
     /* 如果获得线程控制块,启动这个线程 */
     if (dtu_recv_data != RT_NULL)
         rt_thread_startup(dtu_recv_data);
@@ -676,10 +641,9 @@ char *makeJson_C01_Warn(uint16_t code,double process)
 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(atoi(device_status.power)<400&&device_status.work_status==1&&makejson_sta!=0)
     {
         #if LAMP_EN == 0
         LOG_I("Current is:%d",atoi(device_status.power));
@@ -687,9 +651,7 @@ char * makeJson()
         device_status.lamp_status = 1;
         #endif
     }
-    else {
-        device_status.lamp_status = 0;
-    }
+
     if(atoi(device_status.power)>5000)
         rt_sprintf(device_status.power,"0.01");
 
@@ -723,26 +685,7 @@ 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);
-    }
-    else if (device_status.version_type==6) {
-        rt_sprintf(device_status.driver,"%s-%s",VERSION_XCT,device_status.driver_4g);
-    }
-    else if (device_status.version_type==7) {
+    if (device_status.version_type==7) {
         rt_sprintf(device_status.driver,"%s-%s",VERSION_BZY,device_status.driver_4g);
     }
     if(device_status.sensor_485_sta!=0)
@@ -756,159 +699,39 @@ 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_status);
-        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)
+
+    if(device_status.dtype==7)
     {
-        char ct1[10],ct2[10];
+        char ct1[10],ct2[10],ct3[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_sprintf(ct3,"%d-%d",device_status.collecting_sh3,device_status.collecting_eh3);
         rt_kprintf("ct1-ct2:%s\n",ct1);
         device_status.coll_time[0] = ct1;
         device_status.coll_time[1] = ct2;
+        device_status.coll_time[2] = ct3;
         cJSON *data_clt = NULL;
-        data_clt = cJSON_CreateStringArray(device_status.coll_time,2);
+        data_clt = cJSON_CreateStringArray(device_status.coll_time,3);
         //工作状态
         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,"gps",device_status.gps);              //定位状态
     //开关状态
     rt_sprintf(utos, "%d",device_status.ds);
@@ -935,10 +758,6 @@ char * makeJson()
     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)
     {
@@ -950,6 +769,7 @@ char * makeJson()
     return p;
 }
 
+
 int Parse_Cam_Param(cJSON *param_msg)
 {
     cJSON* item_ext=cJSON_GetObjectItem(param_msg,"ext");
@@ -1006,9 +826,8 @@ int parseDtu(char *json_string)
     extern int rt_hw_rtc_init(void);
     char* json_s = NULL;
     cJSON* item_cmd = NULL;    //嵌套ext
+    cJSON* item_focus = NULL;
     cJSON* item_ext = NULL;    //嵌套ext
-    cJSON* item_checkself = NULL;
-    cJSON* photolink = NULL;
     cJSON* photo_sta = NULL;
     cJSON* hst  = NULL; //加热温度
     cJSON* collt  = NULL; //收集时间
@@ -1036,10 +855,6 @@ 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;
@@ -1047,7 +862,11 @@ int parseDtu(char *json_string)
     cJSON* tmp = NULL;
     cJSON* link_sta = NULL;
     cJSON* value_commn= NULL;
-    rt_kprintf("%s\n",json_string);
+    cJSON* movx = NULL;
+    cJSON* movy = NULL;
+    cJSON* movz = NULL;
+    cJSON* speed = NULL;
+    //rt_kprintf("%s\n",json_string);
     cJSON *root = cJSON_Parse(json_string);
     if(!root)
     {
@@ -1058,83 +877,106 @@ int parseDtu(char *json_string)
     else
     {
           item_cmd = cJSON_GetObjectItem(root,"cmd");
-          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");
           item_ext=cJSON_GetObjectItem(root,"ext");
-          if(cam_cmd!=NULL){
-              //先检查定时器状态,否则会崩溃
-              rt_timer_stop(timer_uart2);
-              LOG_I("cam_code");
-              if(cam_cmd->valueint==0){
-                  ctr_led(ON);
-                  HMI_WRITE("sysSet.va0.txt=\"相机已连接!\"");
-              }else{
-                  HMI_WRITE("sysSet.va0.txt=\"相机连接失败:%d!\"",cam_cmd->valueint);
-              }
-              if(item_ext!=NULL)
-                  Parse_Cam_Param(root);
+          item_focus = cJSON_GetObjectItem(root,"focus");
+          if(item_focus!=RT_NULL){
+              device_status.focus_value = item_focus->valuedouble;
           }
 
-          if(ledsta!=NULL)
+          if(item_cmd!=RT_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);
+              if(strstr(item_cmd->valuestring,"autotest")!=RT_NULL){
+                  device_status.auto_test_sw=1;
+              }else if (strstr(item_cmd->valuestring,"auto_focus")!=RT_NULL) {
+                  device_status.autotakepic = 2;
               }
-              else
-              {
-                  HMI_WRITE("selfcheck.t4.bco=63488");
-                  device_status.C01 |= (1<<3);
+              //补光灯开灯和关灯
+              if(strstr(item_cmd->valuestring,"ledon")!=RT_NULL){
+                  ctr_Cold(ON);
               }
-
-              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; //关闭
-              rt_sprintf(device_status.photolink,"%s",photolink->valuestring);
-              LOG_I("接收到图片地址:%s",device_status.photolink);
-              //上报自检结果
-              if(strlen(device_status.qianming)>=2){
-                  char *json_temp = makeJson_selfCheck_(1);
-                  DTU_Write("%s",json_temp);
-                  free(json_temp);
+              if(strstr(item_cmd->valuestring,"ledoff")!=RT_NULL){
+                  ctr_Cold(OFF);
+                  slidelock();
               }
-
-          }
-          if(item_checkself!=NULL){//自检签名
-              memset(device_status.qianming,0,sizeof(device_status.qianming));
-              device_status.photo_ws = 1;
-              LOG_I("自检签名:%s",item_checkself->valuestring);
-              sprintf(device_status.qianming,"%s",item_checkself->valuestring);
-              //生成自检应答json
-              char *json_temp = makeJson_selfCheck_(0);
-              DTU_Write("%s",json_temp);
-              free(json_temp);
-              ctr_lamp(ON, 1);
-              ctr_Heat(OFF);
-              //执行自检
-              device_status.selfcheck_ws = 1;
-          }
-          //item_data = cJSON_GetObjectItem(root,"data");
-          if(item_cmd!=RT_NULL)
-          {
-              if(strstr(item_cmd->valuestring,"takephoto")!=RT_NULL)
+              //采集风机开和关
+              if(strstr(item_cmd->valuestring,"windon")!=RT_NULL){
+                  ctr_router(ON);
+              }
+              if(strstr(item_cmd->valuestring,"windoff")!=RT_NULL){
+                  ctr_router(OFF);
+               }
+              //卷带电机执行旋转一次
+              if(strstr(item_cmd->valuestring,"translate")!=RT_NULL){
+                 turnlimit();
+              }
+             //读取滑台控制指令
+              if (strstr(item_cmd->valuestring,"slide")!=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);
+                 char dest[5]={0};
+                 movx = cJSON_GetObjectItem(item_ext,"movx");
+                 movy = cJSON_GetObjectItem(item_ext,"movy");
+                 movz = cJSON_GetObjectItem(item_ext,"movz");
+                 speed = cJSON_GetObjectItem(item_ext,"speed");
+
+                 if(speed!=RT_NULL){
+                     if(speed->type==cJSON_Number)
+                     slide_para.pulse_period = 1;//speed->valueint;
+                     LOG_D("设置滑台速度:%d",slide_para.pulse_period);
+                 }
+                 if(movx!=RT_NULL)
+                 {
+                     if(movx->type==cJSON_String)
+                     {
+                         LOG_D("MOVX:%d",strlen(movx->valuestring));
+                         if(strlen(movx->valuestring)==1) {                //如果字符串数值只有一位,则进行归零操作
+                             slide_para.en_slide = 3;
+                         }else{
+                             if(strstr(movx->valuestring,"f")!=RT_NULL) slide_para.xdir = 0;        //1位反向,0位正向;
+
+                             if(strstr(movx->valuestring,"b")!=RT_NULL) slide_para.xdir = 1;        //1位反向,0位正向;
+
+                             strncpy(dest,movx->valuestring+1,strlen(movx->valuestring)-1);
+                             slide_para.xdis = atoi(dest)/2;
+                             rt_kprintf("步进x:%d\n",slide_para.xdis);
+                             slide_para.en_slide = 1;
+                         }
+                     }
+                 }
+                 if(movy!=RT_NULL)
+                 {
+                     if(movy->type==cJSON_String)
+                     {
+                         LOG_D("MOVY LEN:%d",strlen(movy->valuestring));
+                         if(strlen(movy->valuestring)==1){
+                             slide_para.en_slide = 7;              //如果字符串数值只有一位,则进行归零操作
+                         }else {
+                             if(strstr(movy->valuestring,"f")!=RT_NULL)  slide_para.ydir = 0;        //1位反向,0位正向;
+                             if(strstr(movy->valuestring,"b")!=RT_NULL)  slide_para.ydir = 1;        //1位反向,0位正向;
+
+                             strncpy(dest,movy->valuestring+1,strlen(movy->valuestring)-1);
+                             slide_para.ydis = atoi(dest)/2;
+                             LOG_I("MOV Y STEP:%d",slide_para.ydis);
+                             slide_para.en_slide = 6;
+                       }
+                     }
+                 }
+                 if(movz!=RT_NULL)
+                 {
+                     if(movz->type==cJSON_String)
+                     {
+                         LOG_D("MOVZ:%d",sizeof(movz->valuestring));
+                         if(strlen(movz->valuestring)==1) {
+                             slide_para.en_slide = 4;              //如果字符串数值只有一位,则进行归零操作
+                         }else{
+                             if(strstr(movz->valuestring,"f")!=RT_NULL)  slide_para.zdir = 0;        //1位反向,0位正向;
+                             if(strstr(movz->valuestring,"b")!=RT_NULL)  slide_para.zdir = 1;        //1位反向,0位正向;
+                             strncpy(dest,movz->valuestring+1,strlen(movz->valuestring)-1);
+                             slide_para.zdis = atoi(dest)/2;
+                             rt_kprintf("步进z:%d\n",slide_para.zdis);
+                             slide_para.en_slide = 2;
+                         }
+                     }
+                 }
               }
               else if (strstr(item_cmd->valuestring,"json_w_clock")!=RT_NULL) {
                   rt_kprintf("查询时间配置!\n");
@@ -1194,26 +1036,6 @@ 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");
-                      DTU_Write("%s",turn_zp);
-                      rt_free(turn_zp);
-                      if(device_status.vol==0)
-                          device_status.vol = 111;
-                  }
                   else if (strstr(type->valuestring,"led_on")!=RT_NULL)
                   {
                       ctr_led(ON);
@@ -1335,10 +1157,6 @@ int parseDtu(char *json_string)
                   ef_set_env_blob("ds",&device_status.ds,sizeof(device_status.ds));        //
                   UpLoad_Data();
               }
-//              else if (strstr(item_cmd->valuestring,"log")!=RT_NULL) {
-//                  rt_thread_mdelay(2000);
-//                  //read_all_flash_log();
-//            }
               //设置温湿度
               else if (strstr(item_cmd->valuestring,"sensor")!=RT_NULL) {
                   //2022-04-12add:485传感器正常,不再解析服务器下发的温湿度数据
@@ -1390,16 +1208,6 @@ int parseDtu(char *json_string)
               }
               else if (strstr(item_cmd->valuestring,"synchronization")!=RT_NULL)
               {
-//                  #if Color_EN == 0
-//                  if(device_status.dtype==7)
-//                  {
-//                      DTU_Write("%s","SwversionV7");
-//                  }
-//                  else if (device_status.dtype==3)
-//                  {
-//                      DTU_Write("%s","SwversionV4");
-//                  }
-//                  #endif
                   device_status.refresh_timeout=0;
                   //driver_4g =  cJSON_GetObjectItem(item_ext,"version");
                   driver_4g = cJSON_GetObjectItem(item_ext,"dver");
@@ -1474,29 +1282,6 @@ int parseDtu(char *json_string)
                                 LOG_E("set_date failed!");
                             }
                       }
-//                      static char year_s[5],month_s[3],day_s[3],hour_s[3],min_s[3],sec_s[3];
-//                      strncpy(year_s, datetime->valuestring, 4);
-//                      strncpy(month_s,datetime->valuestring+4,2);
-//                      strncpy(day_s,datetime->valuestring+6,2);
-//                      strncpy(hour_s,datetime->valuestring+8,2);
-//                      strncpy(min_s,datetime->valuestring+10,2);
-//                      strncpy(sec_s,datetime->valuestring+12,2);
-//                      if(atoi(year_s)>=2024&&atoi(year_s)<3000&&atoi(month_s)>0&&atoi(month_s)<13&&atoi(day_s)>0&&atoi(day_s)<32)
-//                      {
-//                          if(set_date(atoi(year_s),atoi(month_s),atoi(day_s))==RT_EOK)
-//                          {
-//                              LOG_I("设置日期:%d年%d月%d日",atoi(year_s),atoi(month_s),atoi(day_s));
-//                              if(atoi(hour_s)>0&&atoi(hour_s)<=24&&atoi(min_s)>=0&&atoi(min_s)<=60&&atoi(sec_s)>=0&&atoi(sec_s)<=60)
-//                              {
-//                                  LOG_I("设置时间:%d时%d分%d秒",atoi(hour_s),atoi(min_s),atoi(sec_s));
-//                                  set_time(atoi(hour_s),atoi(min_s),atoi(sec_s));
-//                              }
-//                          }
-//                          else {
-//                              LOG_E("set_date failed!");
-//                              rt_hw_rtc_init();
-//                          }
-//                      }
                   }
 
                   LOG_I("参数同步:lat:%s lng:%s",lat->valuestring,lng->valuestring);
@@ -1621,7 +1406,7 @@ int parseDtu(char *json_string)
                   }
                   else if(device_status.num_updata!=0&&device_status.hmi_fresh==2)
                   {
-                      if(strstr(device_status.project,"A7_DTU_V3")!=RT_NULL)
+                      if(strstr(device_status.project,"A7_DTU_V3")!=RT_NULL||strstr(device_status.project,"Android11")!=RT_NULL)
                       {
                           UpLoad_Data();
                       }
@@ -1933,61 +1718,6 @@ int parseDtu(char *json_string)
                               }
 
                           }
-                          if(tt!=NULL)
-                          {
-                              if(tt->type==cJSON_Number)
-                              {
-                                  if(tt->valueint>=1&&tt->valueint<=10)
-                                  {
-                                      #if LAMP_EN == 0
-                                      device_status.sunBar = tt->valueint;
-                                      ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                      rt_kprintf("光控定时tt:%d\n",tt->valueint);
-                                      #else
-                                      if(tt->valueint==3||tt->valueint==6||tt->valueint==9)
-                                      {
-                                          device_status.sunBar = tt->valueint;
-                                          ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                          rt_kprintf("光控定时tt:%d\n",tt->valueint);
-                                      }
-                                      else
-                                      {
-                                          device_status.sunBar = 3;
-                                          rt_kprintf("三光源模式,禁止设置定时时长!!!\n");
-                                      }
-                                      #endif
-                                  }
-                                  else {
-                                      rt_kprintf("光控定时tt设置失败参数错误!!!\n");
-                                  }
-                              }
-                              else if (tt->type==cJSON_String) {
-                                  if(atoi(tt->valuestring)>=1&&atoi(tt->valuestring)<=10)
-                                  {
-                                      #if LAMP_EN == 0
-                                      device_status.sunBar = atoi(tt->valuestring);
-                                      ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                      rt_kprintf("光控定时tt:%d\n",atoi(tt->valuestring));
-                                      #else
-                                      if(atoi(tt->valuestring)%3==0)
-                                      {
-                                          device_status.sunBar = atoi(tt->valuestring);
-                                          ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));         //光控定时
-                                          LOG_I("光控定时tt:%d",atoi(tt->valuestring));
-                                      }
-                                      else
-                                      {
-                                          device_status.sunBar = 3;
-                                          LOG_W("三光源模式,禁止设置定时时长!!!");
-                                      }
-                                      #endif
-                                  }
-                                  else {
-                                      LOG_E("光控定时tt设置失败参数错误!!!");
-                                  }
-                              }
-
-                          }
                           if(htim!=NULL)
                           {
                               if(htim->type==cJSON_Number)

+ 204 - 566
Application_cbd_apm32f1/applications/hmi.c

@@ -36,7 +36,7 @@
 #define HMI_THREAD_STACK_SIZE       2048        //线程栈空间大小
 #define HMI_THREAD_TIMESLICE        10           //时间片
 
-#define CONTROL_MOTOR_PRIORITY      18
+#define CONTROL_MOTOR_PRIORITY      7
 #define CONTROL_MOTOR_STACK_SIZE    2048
 #define CONTROL_MOTOR_TIMESLICE     5
 
@@ -49,6 +49,7 @@ void list_mem(void);
 int mb_master_samlpe();
 /**/
 Device_Status_typedef device_status;
+Device_slide_typedef slide_para;
 
 time_t time(time_t *t);
 
@@ -457,16 +458,7 @@ static void HMI_Decode(void)
     else if (strstr(rx_buffer,"putTest.switchPic=1")!=NULL) {
         device_status.photo_ws = 1;
     }
-    //转盘复位
-    else if (strstr(rx_buffer,"turn_init")!=NULL) {
-        LOG_I("转仓复位!");
-        ctr_turn(0,0);
-    }
-    //转盘
-    else if (strstr(rx_buffer,"turn")!=NULL) {
-        LOG_I("转仓!");
-        ctr_turn(90,0);
-    }
+
     //打开电磁阀
     else if (strstr(rx_buffer,"putTest.switchDrop=1")!=NULL) {
         LOG_I("开始滴液!");
@@ -564,20 +556,6 @@ static void HMI_Decode(void)
         LOG_I("停止一键测试!!!");
         device_status.auto_test_sw=0;
     }
-    //清扫
-    else if (strstr(rx_buffer,"clear")!=NULL) {
-        rt_kprintf("\n清扫!\n");
-        if(device_status.version_type==4||device_status.version_type==41)
-        {
-            device_status.clear_status=1;
-        }
-        else if (device_status.version_type==1) {
-            turnzp();
-        }
-        else if (device_status.version_type==6) {
-            ctr_JD_Clear(ON);
-        }
-    }
     //震动
     else if (strstr(rx_buffer,"putTest.switchShake=1")!=NULL) {
         LOG_I("震动!");
@@ -634,69 +612,6 @@ static void HMI_Decode(void)
         ctr_Heat(ON);
         rt_kprintf("Open Heat!\n");
     }
-    //打开上仓门
-    else if(strstr(rx_buffer,"putTest.switchUp=1")!=NULL){
-        if(device_status.dtype==7)
-        {
-            ctr_lamp(ON, 1);
-            ctr_Motor_Driver(1, 0,1000000,500);
-            LOG_I("开始步进上行!");
-        }
-        else
-        {
-            rt_kprintf("Open UP!\n");
-            ctr_cangmen_up(OFF);
-            device_status.ctr_up_motor = 1;
-        }
-    }
-    //关闭上仓门
-    else if(strstr(rx_buffer,"putTest.switchUp=0")!=NULL){
-        if(device_status.dtype==7)
-        {
-            LOG_I("停止步进上行!");
-            ctr_lamp(OFF, 1);
-            ctr_Motor_Driver(0, 0,0,0);
-        }
-        else
-        {
-            rt_kprintf("CLOSE UP!\n");
-            ctr_cangmen_up(OFF);
-            device_status.ctr_up_motor = 2;
-        }
-
-    }
-    //打开下仓门
-    else if(strstr(rx_buffer,"putTest.switchDown=1")!=NULL){
-        if(device_status.dtype==7)
-        {
-            LOG_I("开始步进下行!");
-            ctr_lamp(ON, 1);
-            ctr_Motor_Driver(1, 1,1000000,500);
-        }
-        else
-        {
-            ctr_cangmen_down(OFF);
-            device_status.ctr_down_motor = 1;
-            rt_kprintf("Open down!\n");
-        }
-
-    }
-    //关闭下仓门
-    else if(strstr(rx_buffer,"putTest.switchDown=0")!=NULL){
-        if(device_status.dtype==7)
-        {
-            ctr_lamp(OFF, 1);
-            ctr_Motor_Driver(0, 0,0,0);
-            rt_kprintf("停止步进下行!\n");
-        }
-        else
-        {
-            ctr_cangmen_down(OFF);
-            device_status.ctr_down_motor = 2;
-            rt_kprintf("CLOSE down!\n");
-        }
-
-    }
     else if(strstr(rx_buffer,"putTest.Testpaichong")!=NULL){
         if(device_status.collt_box_sta==0){
             device_status.collt_box_sta = 111;
@@ -1321,18 +1236,6 @@ static void HMI_Decode(void)
             MA_save();
         }
     }
-    else if (strstr(rx_buffer,"putTest.switchFAN_PU=1")!=NULL) {
-        ctr_Fan_PUT(ON);
-    }
-    else if (strstr(rx_buffer,"putTest.switchFAN_PU=0")!=NULL) {
-        ctr_Fan_PUT(OFF);
-    }
-    else if (strstr(rx_buffer,"putTest.switchFAN_IN=1")!=NULL) {
-        ctr_Fan_IN(ON);
-    }
-    else if (strstr(rx_buffer,"putTest.switchFAN_IN=0")!=NULL) {
-        ctr_Fan_IN(OFF);
-    }
     else if(strstr(rx_buffer,"DisplayPower")!=RT_NULL)
     {
         HMI_WRITE("sysTest.sysTest_power.txt=\"%s\"",device_status.power);
@@ -1426,431 +1329,219 @@ static void HMI_Decode(void)
     }
 }
 
+#define EPS 1e-3
+// 找出一维数组中最大数的索引
+int findMaxIndex(double arr[], int size) {
+    int maxIndex = 0; // 假设最大值的索引为0
 
+    for (int i = 1; i < size; i++) {
+        if ((arr[i] - arr[maxIndex])>EPS) {
+            maxIndex = i; // 更新最大值的索引
+        }
+    }
+
+    return maxIndex;
+}
 //入口函数-电机控制及
 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;  //
-   rt_uint16_t num_down_close = 200;  //
-   rt_int16_t photo_led_sec = 900;  //55S
-   rt_uint8_t num_tg_open = 200;    //20S
-   rt_uint8_t num_tg_init = 200;
-   //int current_t[200];
-   /*孢子仪拍照数量*/
-   rt_uint16_t photo_setup = 0;
-   #if Color_EN ==1
-   ctr_Color_board(RESET, 1200);
-   #endif
+
+   rt_uint8_t maxIndex = 0;
+
+   /*孢子仪2.0*/
+   const int maxIterations = 20; // 最大迭代次数,可根据实际情况调整
+   const int stepS = 2;    // 对焦步长
+   double allSharpness[maxIterations];    // 当前图像清晰度评价值
+   char tmp_s[10];
+   char tmp[10];
     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);
-        static struct tm alarm_reset12V;
-        alarm_reset12V =*localtime(&time_reset12V);
-        if((alarm_reset12V.tm_hour)==8&&(alarm_reset12V.tm_min==19)&&(alarm_reset12V.tm_sec==50))
-        {
-            ctr_RTU_DTU(OFF);
-            rt_thread_delay(1000*10);
-            ctr_RTU_DTU(ON);
-        }
-        #endif
-        if(device_status.ctr_up_motor==1)
-        {
-            #if 0
-            if(num_up_open==200&&device_status.clear_status==0&&device_status.work_status==1)
-            {
-                motor_current = atoi(device_status.power);
-                LOG_D("上仓门待机电流:%d",motor_current);
+        if(device_status.autotakepic==2){
+            memset(allSharpness,0,sizeof(allSharpness));
+            for(int i = 0; i < 3; i++){
+                slide_para.ydir = 1;        //1位反向,0位正向;
+                slide_para.ydis = stepS;
+                slide_para.en_slide = 6;
+                while(slide_para.en_slide!=0)
+                {
+                    rt_thread_delay(3000);
+                }
+                allSharpness[i] =  device_status.focus_value;
             }
-            //打开上仓门
-            if(num_up_open<200)
-            #endif
-            ctr_cangmen_up(OPEN);
-            num_up_open--;
-//            current_t[num_up_open] = atoi(device_status.power);
-            if (num_up_open == 0)
-            {
-                ctr_cangmen_up(OFF);
-                num_up_open = 200;
-//                bubblesort(current_t, 200);
-//                if(current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
-//                {
-//                    LOG_E("上仓门打开电机电流不足:%d!!!",current_t[199]);
-//                    char * ctr_cm_up_warn = makeJson_Warn("电流不足,打开", "上仓门电机");
-//                    DTU_Write("%s",ctr_cm_up_warn);
-//                    rt_free(ctr_cm_up_warn);
-//                }
+            //归位
+            for(int i = 3; i < 9; i++){
+                slide_para.ydir = 0;        //1位反向,0位正向;
+                slide_para.ydis = stepS;
+                slide_para.en_slide = 6;
+                while(slide_para.en_slide!=0)
+                {
+                    rt_thread_delay(3000);
+                }
+                if(i>=6)    //过了初始位置再进行记录
+                    allSharpness[i-3] =  device_status.focus_value;
             }
-//            else {
-//                LOG_D("上仓门打开电流:%d",current_t[num_up_open]);
-//            }
-        }
-        else if(device_status.ctr_up_motor==2)
-        {
-//            if(num_up_close==200&&device_status.clear_status==0&&device_status.work_status==1)
-//            {
-//                motor_current = atoi(device_status.power);
-//                LOG_D("上仓门待机电流:%d",motor_current);
-//            }
-//            if(num_up_close<200)
-            ctr_cangmen_up(CLOSE);
-            num_up_close --;
-//            current_t[num_up_close] = atoi(device_status.power);
-            if (num_up_close == 0)
-            {
-                ctr_cangmen_up(OFF);
-                num_up_close= 200;
-//                bubblesort(current_t, 200);
-//                if(current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
-//                {
-//
-//                    LOG_E("上仓门电机电流不足!!!-%d",current_t[199]);
-//                    char * ctr_cm_up_warn = makeJson_Warn("电流不足,关闭", "上仓门电机");
-//                    DTU_Write("%s",ctr_cm_up_warn);
-//                    rt_free(ctr_cm_up_warn);
-//                }
+            //检索最大清晰度位置
+            int max_i = findMaxIndex(allSharpness,6);
+
+            for(int i = 0; i < 6-max_i; i++){
+                slide_para.ydir = 1;        //1位反向,0位正向;
+                slide_para.ydis = stepS;
+                slide_para.en_slide = 6;
+                while(slide_para.en_slide!=0)
+                {
+                    rt_thread_delay(3000);
+                }
             }
-            //LOG_D("上仓门关闭电流:%d",current_t[num_up_close]);
+            char *photo_f = makeJson_Warn("auto_focus","focus_done");
+            DTU_Write("%s",photo_f);
+            rt_free(photo_f);
+            device_status.autotakepic = 0;
         }
-        if (device_status.ctr_down_motor == 1)
+        /*对焦拍照*/
+        if(device_status.autotakepic==1)
         {
-//            if(num_down_open==200&&device_status.clear_status==0&&device_status.work_status==1)
-//            {
-//                motor_current = atoi(device_status.power);
-//                LOG_D("下仓门待机电流:%d",motor_current);
-//            }
-//            if(num_down_open<200)
-            ctr_cangmen_down(OPEN);
-            num_down_open--;
-//            current_t[num_down_open] = atoi(device_status.power);
-            //如果关闭仓门1S后检测不到电流增大,则判定为异常
-            if (num_down_open == 0)
-            {
-                ctr_cangmen_down(OFF);
-                num_down_open = 200;
-//                bubblesort(current_t, 200);
-//                if (current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
-//                {
-//                    LOG_E("下仓门电机电流不足!!!-%d",current_t[199]);
-//                    char * ctr_cm_down_warn = makeJson_Warn("电流不足,打开", "下仓门电机");
-//                    DTU_Write("%s",ctr_cm_down_warn);
-//                    rt_free(ctr_cm_down_warn);
-//                }
+            memset(allSharpness,0,sizeof(allSharpness));
+            device_status.step_focus = 1;
+            slide_para.en_slide =3;     //X轴复位
+            while(slide_para.en_slide!=0){
+                LOG_D("等待X轴电机完成复位!");
+                rt_thread_delay(1000);
             }
-//            LOG_D("下仓门打开电流:%d",current_t[num_down_open]);
-        }
-        else if (device_status.ctr_down_motor == 2)
-        {
-//            if(num_down_close==200&&device_status.clear_status==0&&device_status.work_status==1)
-//            {
-//                motor_current = atoi(device_status.power);
-//                LOG_D("下仓门待机电流:%d",motor_current);
-//            }
-//            if(num_down_close<200)
-            ctr_cangmen_down(CLOSE);
-            num_down_close--;
-//            current_t[num_down_close] = atoi(device_status.power);
 
-            if (num_down_close == 0)
-            {
-               ctr_cangmen_down(OFF);
-               num_down_close = 200;
-//               bubblesort(current_t, 200);
-//               //如果关闭仓门5S后检测不到电流增大,则判定为异常
-//               if (current_t[199]-motor_current<100&&device_status.clear_status==0&&device_status.work_status==1&&motor_current!=0&&motor_current<5000)
-//               {
-//                   LOG_E("下仓门关闭电机电流不足!!!-%d",current_t[199]);
-//                   char * ctr_cm_down_warn = makeJson_Warn("电流不足,关闭", "下仓门电机");
-//                   DTU_Write("%s",ctr_cm_down_warn);
-//                   rt_free(ctr_cm_down_warn);
-//
-//               }
-            }
-//            LOG_D("下仓门关闭电流:%d",current_t[num_down_close]);
-        }
-        if(device_status.sun_test==1)
-        {
-            SunTest();
-        }
-        //拍照
-        if(device_status.photo_ws==1)
-        {
-            struct timeval tv;
-            gettimeofday(&tv, NULL);
-            device_status.photo_stamp = tv.tv_sec-8*3600;
-            if(photo_led_sec==900)
-                ctr_led(ON);
-            //打开补光灯
-            if(photo_led_sec==800)
-            {
-                LOG_I("测试拍照!");
-                #if 1
-                char *takephotojson = makeJson_takephoto();
-                DTU_Write("%s",takephotojson);
-                rt_free(takephotojson);
-                #endif
-                rt_thread_delay(5000);  //延时
-            }
-            //15S后执行拍照
-            else if (photo_led_sec==750)
-            {
-                DTU_Write("takephoto.mp3");
-                //延时
+            slide_para.en_slide =4;     //Z轴复位
+            while(slide_para.en_slide!=0){
+                LOG_D("等待Z轴电机完成复位!");
                 rt_thread_delay(1000);
-                LOG_I("测试拍照!");
-                Hk_Take_io();
             }
-            photo_led_sec--;
-            if(photo_led_sec==300)    //
-            {
-                ctr_led(OFF);
-                photo_led_sec = 900;
-                device_status.photo_ws = 0;
-                HMI_WRITE("sysTest.switchPhoto.val=0");
-                HMI_WRITE("sysTest.switchFill.val=0");
+
+            slide_para.en_slide = 7;    //Y轴复位
+            while(slide_para.en_slide!=0){
+                LOG_D("等待Y轴电机完成复位!");
+                rt_thread_delay(1000);
             }
-        }else{
-            photo_led_sec = 900;
-        }
-        /*对焦拍照*/
-        if(device_status.autotakepic==1)
-        {
-            DTU_Write("autotakephoto");
-            HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
-            //打开步进电机驱动器电源
-            ctr_lamp(ON, 1);
-            //打开补光灯
-            ctr_led(ON);
-            //电机向下运动
-            ctr_Motor_Driver(1, 1, 1000000,1000);
-            rt_thread_delay(1000);
-            LOG_I("电机到达下方!!!");
-            Hk_Take_io();
-            rt_thread_delay(1000);
-            LOG_I("电机开始向上!!!");
-            rt_pin_write(Motor_EN, 1);
-            rt_pin_write(Motor_DIR, 0);
-            beep_set(1000000, 200000);      //2kzh - 50%
-            while(rt_pin_read(LIMIT_UP)==1)
-            {
-                HMI_WRITE("sysTest.result.txt=\"对焦拍照触发次数:%d\"",photo_setup);
-                HMI_WRITE("sysTest.auto_flag.txt=\"AutoTeststart\"");
-                rt_pin_write(Motor_EN, 0);
-                beep_set(0, 0);//驱动器失能
-                Hk_Take_io();              //触发拍照
-                rt_thread_mdelay(200);   //10ms
-                rt_pin_write(Motor_EN, 1);
-                beep_set(1000000, 200000); //驱动器使能
-                rt_thread_mdelay(100);   //10ms
-                beep_set(0, 0); //驱动器失能
-                rt_pin_write(Motor_EN, 0);
-                if(photo_setup>300)         //限制最大拍照数量
-                {
-                    ctr_led(OFF);
-                    device_status.autotakepic=0;
-                    rt_pin_write(Motor_EN, 0); //驱动器失能
-                    beep_set(1000000, 0);      //2kzh - 50%
-                    HMI_WRITE("sysTest.switchAutopic.val=%d",0);
-                    HMI_WRITE("sysTest.auto_flag.txt=\"\"");
-                    ctr_lamp(OFF, 1);
-                    break;
+
+            //再次检测Y轴是否复位成功
+            if(rt_pin_read(Limit_Motor_Y)==1){
+                slide_para.en_slide = 7;    //Y轴复位
+                while(slide_para.en_slide!=0){
+                    LOG_D("Again:等待Y轴电机完成复位!");
+                    rt_thread_delay(1000);
                 }
-                photo_setup++;
-                LOG_I("对焦拍照:%d",photo_setup);
             }
-            DTU_Write("takephotodone");
-            ctr_led(OFF);
-            rt_pin_write(Motor_EN, 0); //驱动器失能
-            beep_set(1000000, 0);      //2kzh - 50%
-            HMI_WRITE("sysTest.switchAutopic.val=%d",0);
-            device_status.autotakepic=0;
-            photo_setup = 0;
-            HMI_WRITE("sysTest.auto_flag.txt=\"\"");
-            HMI_WRITE("sysTest.switchAutopic.val=%d",0);
-            //关闭步进电机驱动器电源
-            ctr_lamp(OFF, 1);
-            //重置运行标志位
-            device_status.run_sta = 0;
-            ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));
-         }
-        if(device_status.fsl_sw==1)
-        {
-            ctr_Petroleum_jelly(10);
-        }
 
-        if(device_status.collt_box_sta==111){
-            ctr_Fan_IN(ON);   //推杆电机收缩(供电打开,复位)
-            num_tg_init--;
-            if(num_tg_init%10==0)
-                HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
-            if(num_tg_init==0){
-                HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
-                ctr_Fan_PUT(ON);
-                num_tg_init = 200;
-                device_status.collt_box_sta=112;
+            if(rt_pin_read(Limit_Motor_Y)==0){
+                slide_para.ydir = 1;        //1位反向,0位正向;
+                slide_para.ydis = 8600;     //
+                slide_para.en_slide = 6;
+                ctr_Cold(ON);                         //ctr_router(ON);  打开补光灯
+                while(slide_para.en_slide!=0){
+                    LOG_D("等待Y轴电机完成移位:%d",slide_para.ydis);
+                    rt_thread_delay(2000);
+                }
             }
-        }else if(device_status.collt_box_sta==112){
-            num_tg_open--;
-            if(num_tg_open%10==0)
-                HMI_WRITE("sysTest.result.txt=\"开始执行排虫:%d\"",num_tg_open/10);
-            if(num_tg_open==0){
-                HMI_WRITE("sysTest.result.txt=\"排虫复位中\"");
-                ctr_Fan_PUT(OFF);
-                num_tg_open = 200;
-                device_status.collt_box_sta=113;
+#if 0
+            slide_para.pulse_period = 20;  //修改滑台的脉宽为20ms
+            //遍历所有位置,粗对焦
+            for(int i = 0; i < maxIterations; i++){
+                slide_para.ydir = 0;        //1位反向,0位正向;
+                slide_para.ydis = stepS;
+                slide_para.en_slide = 6;
+                while(slide_para.en_slide!=0)
+                {
+                    rt_thread_delay(2500);
+                }
+                allSharpness[i] =  device_status.focus_value;
+                if(device_status.focus_value > 10.0) break;
             }
-        }else if(device_status.collt_box_sta==113){
-            num_tg_init--;
-            if(num_tg_init%10==0)
-                HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
-            if(num_tg_init==0){
-                HMI_WRITE("sysTest.result.txt=\"排虫机执行已完成!\"");
-                ctr_Fan_PUT(OFF);
-                ctr_Fan_IN(OFF);
-                num_tg_init = 200;
-                device_status.collt_box_sta=0;
+            for(int i = 0; i < maxIterations; i++){
+                sprintf(tmp_s, "%f",allSharpness[i]);
+                rt_kprintf("-%s",tmp_s);
             }
-        }
+            maxIndex = findMaxIndex(allSharpness,maxIterations);    //最大清晰度的位置
 
-        if(device_status.run_sta==111){         //排虫-收缩
-            ctr_Fan_IN(ON);   //推杆电机收缩(供电打开,复位)
-            ctr_Fan_PUT(OFF);
-            num_tg_init--;
-            if(num_tg_init%10==0)
-                HMI_WRITE("sysTest.result.txt=\"排虫复位中:%d\"",num_tg_init/10);
-            if(num_tg_init==0){
-                HMI_WRITE("sysTest.result.txt=\"排虫复位完成\"");
-                ctr_Fan_IN(OFF);
-                num_tg_init = 200;
-                device_status.run_sta=0;
-            }
-        }else if(device_status.run_sta==112){   //收虫-推出
-            ctr_Fan_IN(ON);
-            ctr_Fan_PUT(ON);
-            num_tg_open--;
-            if(num_tg_open%10==0)
-                HMI_WRITE("sysTest.result.txt=\"开始执行收虫:%d\"",num_tg_open/10);
-            if(num_tg_open==0){
-                HMI_WRITE("sysTest.result.txt=\"收虫中...\"");
-                ctr_Fan_PUT(OFF);
-                ctr_Fan_IN(OFF);
-                num_tg_open = 200;
-                device_status.run_sta=0;
+
+            for(int i = 0; i < (maxIterations-maxIndex); i++){      //运动到该位置
+                slide_para.ydir = 1;        //1位反向,0位正向;
+                slide_para.ydis = stepS;
+                slide_para.en_slide = 6;
+                while(slide_para.en_slide!=0)
+                {
+                    rt_thread_delay(2500);
+                }
             }
-        }
+            slide_para.pulse_period = 1;  //修改滑台的脉宽为20ms
+#endif
+
+//            //细对焦
+//            memset(allSharpness,0,sizeof(allSharpness));
+//            for(int i = 0; i < 3; i++){
+//                slide_para.ydir = 1;        //1位反向,0位正向;
+//                slide_para.ydis = stepS;
+//                slide_para.en_slide = 6;
+//                while(slide_para.en_slide!=0)
+//                {
+//                    rt_thread_delay(3000);
+//                }
+//                allSharpness[i] =  device_status.focus_value;
+//            }
+//            //归位
+//            for(int i = 3; i < 9; i++){
+//                slide_para.ydir = 0;        //1位反向,0位正向;
+//                slide_para.ydis = stepS;
+//                slide_para.en_slide = 6;
+//                while(slide_para.en_slide!=0)
+//                {
+//                    rt_thread_delay(3000);
+//                }
+//                if(i>=6)    //过了初始位置再进行记录
+//                    allSharpness[i-3] =  device_status.focus_value;
+//            }
+//            //检索最大清晰度位置
+//            int max_i= findMaxIndex(allSharpness,6);
+//
+//            for(int i = 0; i < 6-max_i; i++){
+//                slide_para.ydir = 1;        //1位反向,0位正向;
+//                slide_para.ydis = stepS;
+//                slide_para.en_slide = 6;
+//                while(slide_para.en_slide!=0)
+//                {
+//                    rt_thread_delay(3000);
+//                }
+//            }
 
+            //生成JSON指令
+            //sprintf(tmp, "%f",device_status.focus_value);
+            char *photo = makeJson_Warn("mov_init_y","takephoto_done");
+            DTU_Write("%s",photo);
+            rt_free(photo);
+            device_status.autotakepic = 0;
+        }
+        if(device_status.fsl_sw==1)
+        {
+            ctr_Petroleum_jelly(10);
+        }
         //一键测试
         if(device_status.auto_test_sw==1)
         {
-            HMI_WRITE("sysTest.auto_flag.txt=\"Autotest\"");
-            //转盘复位
-            LOG_I("转盘复位!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:转盘复位!\"");
-            rt_thread_delay(2000);
-            ctr_turn(0,0);
-            //转90
-            LOG_I("第一次转盘!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:第一次转盘!\"");
-            ctr_turn(90,0);
-            rt_thread_delay(2000);
-            //推杆电机:测试粘附:
-            LOG_I("涂凡士林!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:涂凡士林!\"");
-            ctr_Petroleum_jelly(10);
-            rt_thread_delay(2000);
-            //转90
-            LOG_I("第二次转盘!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:第二次转盘!\"");
-            ctr_turn(90,0);
-            rt_thread_delay(2000);
-            //采集,打开风机
-            LOG_I("采集,打开风机!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:采集,打开风机!\"");
-            ctr_Collect_Fan(ON);
-            rt_thread_delay(5000);
-            LOG_I("采集结束,关闭风机!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:采集结束,关闭风机!\"");
-            rt_thread_delay(2000);
-            ctr_Collect_Fan(OFF);
-            //散热
-            LOG_I("打开散热!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:打开散热!\"");
-            rt_thread_delay(2000);
-            ctr_Cool_Fan(ON);
-            rt_thread_delay(5000);
-            LOG_I("关闭散热!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:关闭散热!\"");
-            rt_thread_delay(2000);
-            ctr_Cool_Fan(OFF);
-            //转90
-            LOG_I("第三次转盘!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:第三次转盘!\"");
-            ctr_turn(90,0);
-            rt_thread_delay(5000);
-            //滴液
-            LOG_I("开始滴液!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:开始滴液!\"");
-            rt_thread_delay(2000);
-            ctr_shake(ON,device_status.shake_sec);
-            rt_thread_delay(5000);
-            LOG_I("停止滴液!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:停止滴液!\"");
-            rt_thread_delay(2000);
-            //加热
-            LOG_I("开始加热!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:开始加热!\"");
-            rt_thread_delay(2000);
-            ctr_Heat(ON);
-            rt_thread_delay(5000);
-            LOG_I("停止加热!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:停止加热!\"");
-            rt_thread_delay(2000);
-            ctr_Heat(OFF);
-            //制冷
-            LOG_I("开始制冷!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:开始制冷!\"");
-            rt_thread_delay(2000);
-            ctr_Cold(ON);
-            rt_thread_delay(5000);
-            LOG_I("停止制冷!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:停止制冷!\"");
-            rt_thread_delay(2000);
-            ctr_Cold(OFF);
-            //转90
-            LOG_I("第四次转盘!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:第四次转盘!\"");
-            ctr_turn(90,0);
-            LOG_I("打开补光灯!!!");
-            HMI_WRITE("sysTest.result.txt=\"一键测试:打开补光灯!\"");
-            rt_thread_delay(2000);
-            ctr_led(ON);
+            //开始采集风机持续5S
+            ctr_router(ON);
+            rt_thread_delay(1000*120);
+            //关闭采集风机
+            ctr_router(OFF);
+            //胶带传送
+            turnlimit();
+            //滑台归位,自动对焦
+            //拍一张照片上传到平台
             device_status.autotakepic=1;
             device_status.auto_test_sw=0;
-            HMI_WRITE("sysTest.auto_flag.txt=\"\"");
         }
-        if(device_status.selfcheck_ws==2)
-        {
-            selfcheck(1);
-        }
-        rt_thread_delay(100);
+        rt_thread_delay(10);
     }
 }
 /*屏幕写数据*/
 int Hmi_Fresh(void)
 {
+    #if 0
     //初始化串口4
     HMI_uart4_init();
     rt_err_t ret = RT_EOK;
@@ -1869,6 +1560,17 @@ int Hmi_Fresh(void)
                             HMI_THREAD_STACK_SIZE,
                             HMI_THREAD_PRIORITY,
                             HMI_THREAD_TIMESLICE);
+    /* 如果获得线程控制块,启动这个线程 */
+    if (hmi1 != RT_NULL)
+    {
+       rt_thread_startup(hmi1);
+    }
+    else
+    {
+        LOG_E("rt_thread_startup hmi1 failed!");
+    }
+    #endif
+
     /*部分控制的线程*/
     ctr_motor = rt_thread_create("Ctr motor",
                             Ctr_Mortor_entry,
@@ -1880,22 +1582,13 @@ int Hmi_Fresh(void)
     {
         rt_thread_startup(ctr_motor);
     }
-    /* 如果获得线程控制块,启动这个线程 */
-    if (hmi1 != RT_NULL)
-    {
-       rt_thread_startup(hmi1);
-    }
-    else
-    {
-       ret = RT_ERROR;
-    }
     //定时器,串口通信超时监测20S
     timer_uart2 = rt_timer_create("t_uart2",t_uart2_callback,RT_NULL, 20000, RT_TIMER_FLAG_ONE_SHOT);
     if(timer_uart2==RT_NULL)
     {
         LOG_E("rt_timer_create timer_uart2 failed!");
     }
-    return ret;
+    return 0;
 }
 void Check_ParamConfig(void)
 {
@@ -1919,8 +1612,8 @@ void Check_ParamConfig(void)
     {
         device_status.iSave=FLASH_FLAG;
         /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
-        device_status.dtype = 3;
-        device_status.version_type = 4; //4.0
+        device_status.dtype = 7;
+        device_status.version_type = 7; //4.0
         device_status.Power_Type = 0;   //0-交流供电;1-直流供电
         device_status.clt_time = 10;    //收集时间
         device_status.heattime = 10;    //加热时间
@@ -2050,45 +1743,9 @@ void Check_ParamConfig(void)
             device_status.dattim = 10;
         }
         /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
-        if(device_status.dtype!=7)
-        {
-            device_status.dtype = 3;
-        }
-        else {
-            device_status.version_type = 7;
-        }
-        if(device_status.version_type==0)
-        {
-            app_partion_backup();   //固件备份至df_area
-            device_status.version_type = 41;
-            rt_sprintf(device_status.driver, "%s",VERSION_HK);
-            ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));
-        }
-        else if(device_status.version_type==1)
-        {
-            rt_sprintf(device_status.driver, "%s",VERSION_ZP);
-        }
-        else if (device_status.version_type==11)
-        {
-            rt_sprintf(device_status.driver, "%s",VERSION_GK);
-        }
-        else if (device_status.version_type==4)
-        {
-            rt_sprintf(device_status.driver, "%s",VERSION_HK_2000W);
-        }
-        else if (device_status.version_type==41) {
-            rt_sprintf(device_status.driver, "%s",VERSION_HK);
-        }
-        else if (device_status.version_type==5) {
-            rt_sprintf(device_status.driver, "%s",VERSION_V5);
-        }
-        else if (device_status.version_type==6)
-        {
-            //打开相机供电;
-            ctr_Camera_Power(ON);
-            rt_sprintf(device_status.driver, "%s",VERSION_XCT);
-        }
-        else if (device_status.version_type==7) {
+        device_status.dtype = 7;
+        device_status.version_type = 7;
+        if (device_status.version_type==7) {
             rt_sprintf(device_status.driver, "%s",VERSION_BZY);
             //异常处理:20230331,修复第一段开始时间等于第二段结束时间的情况
             if(device_status.collecting_eh1==device_status.collecting_eh2&&device_status.collecting_sh2!=device_status.collecting_eh2)
@@ -2096,19 +1753,7 @@ void Check_ParamConfig(void)
                 device_status.collecting_eh2 = device_status.collecting_sh2 + 2;
             }
         }
-        else if (device_status.version_type==30) {
-            rt_sprintf(device_status.driver, "%s",VERSION_Robot);
-        }
-        /*定制三色光源*/
-        #if LAMP_EN == 1
-            if(device_status.sunBar%3!=0)
-            {
-                device_status.sunBar = 3;
-            }
-//            device_status.timeSwitch = 1;
-//            device_status.startBar = 20;
-//            device_status.stopBar = 23;
-        #endif
+
         LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
         LOG_I("read flash paramconfis:%d-%s-%s",device_status.version_type,device_status.driver_bl,device_status.driver_compile);
         LOG_I("开机次数:%d",device_status.rebootcnt);
@@ -2147,16 +1792,11 @@ void Check_ParamConfig(void)
         rt_sprintf(device_status.net,"1");
         rt_sprintf(device_status.csq,"0");
         rt_sprintf(device_status.sim,"1");
-
-        ctr_router(ON);
+        rt_sprintf(device_status.gps, "0");
         Hmi_Fresh();
-        if(device_status.dtype!=7)
-        {
-            Control_clear();
-            Control_heat();
-        }
         dtu_data_play();
         sht30_collect();
+        slide_Fresh();
 #if SENSOR_EN==1
         mb_master_samlpe();
 #endif
@@ -2167,9 +1807,8 @@ void Check_ParamConfig(void)
         while(atoi(device_status.net)==1)
         {
             if(Read_Real_Voltage()/100>5&&device_status.power_status==0)
-            ctr_RTU_DTU(ON);
-            if(device_status.dtype==7)
-            HMI_WRITE("sysTest.auto_flag.txt=\"0\"");
+                ctr_RTU_DTU(ON);
+
             char *readinfo =  makeJson_ReadInfo();
             DTU_Write("%s",readinfo);
             rt_free(readinfo);
@@ -2187,8 +1826,6 @@ void Check_ParamConfig(void)
                 #endif
                 break;
             }
-            if(tm.tm_year>=2021)
-            break;
         }
         connect_num = 0;
         while(atoi(device_status.net)==0)
@@ -2200,9 +1837,10 @@ void Check_ParamConfig(void)
             connect_num++;
             if(connect_num>5) break;
         }
-        if(device_status.version_type==6) device_status.timeSwitch = 1;
         DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
         rt_thread_delay(1000);
+        device_status.num_updata = 1;
+        UpLoad_Data();
 #endif
     }
 }

+ 7 - 97
Application_cbd_apm32f1/applications/sht30_collect.c

@@ -149,26 +149,6 @@ static void sht30_collect_thread_entry(void *parameter)
     static int checknightnum = 0;
     while (1)
     {
-        if(Read_Light_Voltage()>500)
-        {
-            checklightnum++;
-            if(checklightnum==20)
-            {
-                device_status.sun_status = 1;
-                device_status.C01 |= (1<<6);
-                checklightnum =0;
-            }
-
-        }
-        else {
-            checknightnum ++;
-            if(checknightnum==20)
-            {
-                device_status.C01 &= ~(1<<6);
-                device_status.sun_status = 0;
-                checknightnum = 0;
-            }
-        }
         //温控
         if(atoi(device_status.tempture)>=device_status.tph||atoi(device_status.tempture)<=device_status.tpl)
         {
@@ -180,13 +160,11 @@ static void sht30_collect_thread_entry(void *parameter)
             device_status.C01 &= ~(1<<7);
             device_status.temp_status = 0;
         }
-        LOG_I("光控计数:%d-%d",checklightnum,checknightnum);
         rt_thread_mdelay(5000);
     }
 }
 static void Power_ReadCheck(void *parameter)
 {
-    int rain_cnt = 0;
     int bat_cnt = 0;
     int RV;
     MovingAverageFilter* filter = moving_average_filter_init(10);
@@ -195,7 +173,7 @@ static void Power_ReadCheck(void *parameter)
     rt_thread_delay(1000);
     while(1)
     {
-        sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current())-2465)/0.4);
+        sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current()))/100.0*2.5);
         //消除误差
         if(Read_Heat_Current()-2465<10)
         {
@@ -213,69 +191,21 @@ static void Power_ReadCheck(void *parameter)
         if (Read_Real_Voltage()/100<12)
         {
             //关闭外设
-            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
         }
         if(atof(device_status.voltage)<22.0)    //小于22.0V,并且持续10S,欠压
         {
-            #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 {
+       {
             RV = 10000 * (4096 - Read_Ntc_Voltage()) / Read_Ntc_Voltage();
             if(TempCalculate(RV, 3950, 10000)-TempCalculate(RV, 3950, 10000)>10)
             {
@@ -288,28 +218,6 @@ static void Power_ReadCheck(void *parameter)
                     device_status.heattem = 25;
                 }
             }
-            //雨控
-            if(Read_Rain_Voltage()>250&&device_status.selfcheck_ws==0)
-            {
-                device_status.C01 |= (1<<5);
-                device_status.rain_status = 1;
-                ctr_lamp(OFF,1);
-                ctr_lamp(OFF,2);
-                ctr_lamp(OFF,3);
-                rain_cnt = 0;
-            }
-            else {
-                rain_cnt++;
-                //雨控消抖,1分钟
-                if(rain_cnt%10==0)
-                    LOG_D("rain_cnt:%d-value:%d",rain_cnt,Read_Rain_Voltage());
-                if(rain_cnt==600&&Read_Rain_Voltage()<250)
-                {
-                    rain_cnt = 0;
-                    device_status.rain_status = 0;
-                    device_status.C01 &= ~(1<<5);
-                }
-            }
         }
         if(bat_cnt>=15){  //持续10s
             bat_cnt = 0;
@@ -326,6 +234,7 @@ static void Power_ReadCheck(void *parameter)
     }
     moving_average_filter_free(filter);
     moving_average_filter_free(filter_v);
+    moving_average_filter_free(filter_hi);
 }
 /*读取电流值*/
 int Read_Real_Current(void)
@@ -339,12 +248,13 @@ int Read_Real_Current(void)
     }
     HAL_ADCEx_Calibration_Start(adc_dev->parent.user_data);
     rt_adc_enable(adc_dev, ADC_DEV_CHANNLE_1);
-    //rt_adc_enable(adc_dev, 17);
+    rt_adc_enable(adc_dev, 17);
     adc1_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_1);
+    in_adc_17 = rt_adc_read(adc_dev, 17);
     /* 关闭通道 */
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_1);
     //LOG_D("Read_Real_Current:%d,%d",adc1_value,adc1_value * REFER_VOLTAGE/CONVERT_BITS*15);
-    return  (adc1_value * REFER_VOLTAGE/CONVERT_BITS*15);
+    return  (ADC_VOL_BASE * (adc1_value*1.0)/(in_adc_17*1.0))*100000;
 }
 
 int Read_Heat_Current(void)
@@ -392,7 +302,7 @@ int Read_Real_Voltage(void)
     adc0_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_0);
     /* 关闭通道 */
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_0);
-    return  (adc0_value * REFER_VOLTAGE/CONVERT_BITS*12)+20;
+    return  (adc0_value * REFER_VOLTAGE/CONVERT_BITS*12);
 }
 /*读取保险丝的电压值*/
 int Read_Fuse_Voltage(void)

+ 1 - 1
Application_cbd_apm32f1/rtconfig.h

@@ -52,7 +52,7 @@
 
 #define RT_USING_DEVICE
 #define RT_USING_CONSOLE
-#define RT_CONSOLEBUF_SIZE 256
+#define RT_CONSOLEBUF_SIZE 1024
 #define RT_CONSOLE_DEVICE_NAME "uart1"
 /* end of Kernel Device Object */
 #define RT_VER_NUM 0x40101

+ 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
+#Wed Feb 12 12:00:09 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