zhunk před 6 měsíci
rodič
revize
eb21425fa1

+ 85 - 90
Application_cbd_apm32f1/applications/control.c

@@ -1225,6 +1225,10 @@ void calorstat(uint16_t heat_time)
                 break;
                 break;
             }
             }
         }
         }
+        if(device_status.work_mode==1){
+            LOG_W("切换模式,退出加热!");
+            break;
+        }
         if(device_status.timeSwitch==0&&device_status.sun_status==1)
         if(device_status.timeSwitch==0&&device_status.sun_status==1)
         {
         {
             ctr_Heat(OFF);
             ctr_Heat(OFF);
@@ -1238,38 +1242,7 @@ void calorstat(uint16_t heat_time)
     ctr_Heat(OFF);
     ctr_Heat(OFF);
     //UpLoad_Data();      //加热结束的数据
     //UpLoad_Data();      //加热结束的数据
 }
 }
-//初始化所有控制驱动,关闭
-void HardWare_Init(uint8_t boot)
-{
-    Beep_Tip(200);
-    //关闭上仓门
-    ctr_cangmen_up(OFF);
-
-    if(device_status.dtype==3){
-        //关闭下仓门电机
-        ctr_cangmen_down(OFF);
-    }
-    //关闭镇流器
-    if(device_status.autotakepic==0)
-    ctr_lamp(OFF,1);
-
-    //关闭震动电机
-    ctr_shake(OFF,0);
-
-    //关闭加热
-    ctr_Heat(OFF);
-
-    //关闭补光灯
-    ctr_led(OFF);
-
-    //关闭12V供电(海康相机,RTU)
-    ctr_photo(OFF);
 
 
-    //关闭清扫电机驱动
-    ctr_clear(OFF);
-
-
-}
 //拍照
 //拍照
 void HK_TakePhoto(void)
 void HK_TakePhoto(void)
 {
 {
@@ -1338,35 +1311,14 @@ void SunTest(void)
 /*上电初始化*/
 /*上电初始化*/
 void ResetInit(void)
 void ResetInit(void)
 {
 {
-    if(device_status.dtype==7)
-    {
-        ctr_Motor_Driver(0, 0, 0, 0);
-        //关闭电磁阀
-        ctr_shake(OFF, 0);
-        //关闭加热
-        ctr_Heat(OFF);
-        //关闭制冷
-        ctr_Cold(OFF);
-        //关闭补光灯
-        if(device_status.photo_ws==0)   //解决工作结束后最后一张照片是黑tu,20260424
-            ctr_led(OFF);
-        //转盘复位
-        if(device_status.run_sta==0)
-            ctr_turn(0, 0);
-    }
     if(device_status.version_type!=6&&device_status.version_type!=7)
     if(device_status.version_type!=6&&device_status.version_type!=7)
     {
     {
         device_status.work_done = 1;
         device_status.work_done = 1;
            //1.打开路由器供电
            //1.打开路由器供电
-           if(device_status.power_status==1)
-           {
-#if   MATCH_DEVICE ==0
-               ctr_router(ON);
-#endif
-               ctr_RTU_DTU(ON);
-               //2.打开相机供电
-               ctr_photo(ON);
-           }
+           ctr_router(ON);
+           //2.打开相机供电
+           ctr_photo(ON);
+           ctr_RTU_DTU(ON);
            //3.关闭镇流器
            //3.关闭镇流器
            ctr_lamp(OFF,1);
            ctr_lamp(OFF,1);
            //4.关闭震动电机
            //4.关闭震动电机
@@ -1415,10 +1367,10 @@ void ResetInit(void)
             //1.打开路由器供电
             //1.打开路由器供电
 #if   MATCH_DEVICE ==0
 #if   MATCH_DEVICE ==0
             ctr_router(ON);
             ctr_router(ON);
-#endif
-            ctr_RTU_DTU(ON);
             //2.打开相机供电
             //2.打开相机供电
             ctr_photo(ON);
             ctr_photo(ON);
+#endif
+            ctr_RTU_DTU(ON);
         }
         }
         //5.关闭加热
         //5.关闭加热
         //6.关闭补光灯
         //6.关闭补光灯
@@ -1609,6 +1561,9 @@ void WorkTask(void)
     }
     }
     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)
     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)
     {
     {
+        if(device_status.work_mode==1){
+            break;
+        }
         device_status.work_done = 0;
         device_status.work_done = 0;
         if(clt_time==0)
         if(clt_time==0)
         {
         {
@@ -1660,6 +1615,9 @@ void WorkTask(void)
                 clt_time --;
                 clt_time --;
                 rt_thread_delay(1000);
                 rt_thread_delay(1000);
                 rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
                 rt_kprintf("正在收集.....剩余时间:%d分-%d秒\n",device_status.clt_time,clt_time);
+                if(device_status.work_mode==1){
+                    break;
+                }
                 //如果触发异常
                 //如果触发异常
                 if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
                 if(device_status.bat_status == 1 || device_status.temp_status == 1|| device_status.rain_status==1)
                 {
                 {
@@ -1735,6 +1693,10 @@ void WorkTask(void)
                 heat_time = device_status.heattime * 60;
                 heat_time = device_status.heattime * 60;
                 while(heat_time!=0)
                 while(heat_time!=0)
                 {
                 {
+                    if(device_status.work_mode==1)
+                    {
+                        break;
+                    }
                     heat_time--;
                     heat_time--;
                     LOG_I("正在加热状态!!!");
                     LOG_I("正在加热状态!!!");
                     rt_thread_delay(1000);
                     rt_thread_delay(1000);
@@ -1781,7 +1743,9 @@ void WorkTask(void)
              ctr_cangmen_down(OFF);
              ctr_cangmen_down(OFF);
              rt_thread_delay(1000);
              rt_thread_delay(1000);
             #endif
             #endif
-
+             if(device_status.work_mode==1){
+                 break;
+             }
             if(device_status.version_type==4||device_status.version_type==41||device_status.version_type==42||device_status.version_type==43)
             if(device_status.version_type==4||device_status.version_type==41||device_status.version_type==42||device_status.version_type==43)
             {
             {
                 //震动
                 //震动
@@ -1847,27 +1811,6 @@ void WorkTask(void)
 }
 }
 
 
 
 
-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);
-}
-
 #define PULES    1  //延时时间  ms 5.0测报灯电机归零延时使用
 #define PULES    1  //延时时间  ms 5.0测报灯电机归零延时使用
 
 
 void slidelock()
 void slidelock()
@@ -1907,11 +1850,67 @@ static void Work_Loop_thread_entry(void *parameter)
     rt_thread_delay(1000);
     rt_thread_delay(1000);
     ResetInit();
     ResetInit();
     rt_pin_mode(CTR_UPC_LIMIT, PIN_MODE_INPUT);
     rt_pin_mode(CTR_UPC_LIMIT, PIN_MODE_INPUT);
+    static struct tm tm_tg_run;
+    static uint8_t alarm_h,alarm_m,alarm_s;
     while(1)
     while(1)
     {
     {
-        if(device_status.dtype==3)
+        if(device_status.work_mode==0)
         {
         {
             WorkTask();
             WorkTask();
+        }else{
+            if(device_status.work_status==1){
+                ctr_lamp(ON, 1);
+            }else{
+                ctr_lamp(OFF, 1);
+            }
+            char buf[7] = {0};
+            // 拷贝闹钟字符串(保证安全截断)
+            rt_sprintf(buf, "%-6s", device_status.alarm_tg);
+
+            // 截取 时: 前2位
+            alarm_h = (buf[0] - '0') * 10 + (buf[1] - '0');
+            // 截取 分: 中间2位
+            alarm_m = (buf[2] - '0') * 10 + (buf[3] - '0');
+            // 截取 秒: 后2位
+            alarm_s = (buf[4] - '0') * 10 + (buf[5] - '0');
+            device_status.ctr_up_motor = 2;     //关闭上仓门
+            device_status.ctr_down_motor = 2;   //关闭下仓门
+            LOG_I("当前B模式,触发时间:%d:%d:%d",alarm_h,alarm_m,alarm_s);
+            //判断时间
+            time_t time_run_tg;
+            time(&time_run_tg);
+            tm_tg_run =*localtime(&time_run_tg);
+            LOG_I("当前时间:%d:%d:%d",tm_tg_run.tm_hour,tm_tg_run.tm_min,tm_tg_run.tm_sec);
+            if((tm_tg_run.tm_hour)==alarm_h&&(tm_tg_run.tm_min==alarm_m)&&(tm_tg_run.tm_sec>=alarm_s))
+            {
+                LOG_W("预制执行 开始!");
+                ctr_Cold(ON);    //推杆打开
+                rt_thread_delay(20000);
+                //震动
+                ctr_Collect_Fan(ON);
+                for(uint8_t i = 0; i < 30; i++){
+                    rt_thread_delay(1000);
+                    LOG_I("等待震动完成:%d",i);
+                }
+                ctr_Collect_Fan(OFF);
+                rt_thread_delay(2000);
+                ctr_Cold(OFF);   //推杆关闭
+                rt_thread_delay(2000);
+                char *temp_s =makeJson_Warn("执行完成", "预制模式");
+                DTU_Write("%s",temp_s);
+                rt_free(temp_s);
+                rt_thread_delay(2000);
+                //{"jsonrpc":"2.0","method":"COPY_IMAGE","params":{"st":20,"et":7},"id":1}
+                cJSON *params = cJSON_CreateObject();        // params 子对象
+                cJSON_AddNumberToObject(params, "st", device_status.startBar);     // st:20
+                cJSON_AddNumberToObject(params, "et", device_status.stopBar);      // et:7
+                char* temp = makeJsonRpc2_0("COPY_IMAGE", params, 1);
+                if(temp){
+                    DTU_Write(temp);
+                    free(temp);
+                }
+                rt_thread_delay(20000);
+            }
         }
         }
         rt_thread_delay(1000);
         rt_thread_delay(1000);
     }
     }
@@ -1946,10 +1945,6 @@ static void Control_Check_thread_entry(void *parameter)
     static int current_second = 0;
     static int current_second = 0;
     static int process = 0;
     static int process = 0;
 
 
-    #if MATCH_DEVICE == 1
-    rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
-    rt_pin_write(LED_P,ON);
-    #endif
     device_status.C01 = 0;
     device_status.C01 = 0;
     rt_thread_delay(10000);
     rt_thread_delay(10000);
 
 
@@ -1983,11 +1978,11 @@ static void Control_Check_thread_entry(void *parameter)
             }else {
             }else {
                 process = 0;
                 process = 0;
                 current_second = 0;
                 current_second = 0;
-#if MATCH_DEVICE == 1
-                if(device_status.rain_status==0)
+#if 0
+                if(device_status.rain_status==1)
                 {
                 {
-                    rt_pin_mode(LED_P, PIN_MODE_OUTPUT);
-                    rt_pin_write(LED_P,ON);
+                    LOG_E("雨控!");
+                    rt_thread_delay(10000);
                 }
                 }
 
 
                 //根据故障码 亮指示灯
                 //根据故障码 亮指示灯
@@ -2072,7 +2067,7 @@ static void Control_Check_thread_entry(void *parameter)
                 {
                 {
                     LOG_W("无故障!");
                     LOG_W("无故障!");
                     //发送绿灯常亮信号
                     //发送绿灯常亮信号
-                    write_single_holding_register(0x01,0x00C2,0x0013,1000);
+                    //write_single_holding_register(0x01,0x00C2,0x0013,1000);
                     //延时10S
                     //延时10S
                     rt_thread_delay(10000);
                     rt_thread_delay(10000);
                 }
                 }

+ 9 - 3
Application_cbd_apm32f1/applications/control.h

@@ -18,14 +18,16 @@
 
 
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
 #define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
 #define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
-#define MATCH_DEVICE     0             //比赛设备
+#define MATCH_DEVICE     1             //比赛设备
 #define SENSOR_EN        0             //温湿度:0关闭,1打开
 #define SENSOR_EN        0             //温湿度:0关闭,1打开
 #define UART_TEST_EN     0             ///串口测试0-关闭,1-启用
 #define UART_TEST_EN     0             ///串口测试0-关闭,1-启用
-#define TG_MODULE        0             //推杆电机结构模块化控制
+#define TG_MODULE        1             //推杆电机结构模块化控制
 #define DINGZHI_0722     0             //控制一个电机每天12点20工作12秒
 #define DINGZHI_0722     0             //控制一个电机每天12点20工作12秒
 #define QINGSAO_IO       1             //调整清扫顺序20250801
 #define QINGSAO_IO       1             //调整清扫顺序20250801
-
 #define WENKONG          0             //温控功能1-开启 0-关闭
 #define WENKONG          0             //温控功能1-开启 0-关闭
+#define YUKONG           0             //雨控功能1-开启 0-关闭
+#define QIANYA           0             //欠压功能1-开启 0-关闭
+
 
 
 #if MATCH_DEVICE == 1
 #if MATCH_DEVICE == 1
 #define LAMP_CURRENT    600
 #define LAMP_CURRENT    600
@@ -135,6 +137,9 @@ typedef struct  _packed
     uint8_t gps_inuse;
     uint8_t gps_inuse;
     uint8_t gps_view;
     uint8_t gps_view;
     uint8_t debug_ws;        //调试开关,把调试信息上报到MQTT
     uint8_t debug_ws;        //调试开关,把调试信息上报到MQTT
+    uint8_t work_mode;       //工作模式:0-正常   1-预制
+    uint8_t upan_sta;        //0:正常 1-未连接
+    uint16_t upan_photo_num;
     uint16_t dattim;         //数据上传间隔
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间
     uint16_t shake_sec;      //震动时间
     uint16_t thsp;           //息屏时间
     uint16_t thsp;           //息屏时间
@@ -149,6 +154,7 @@ typedef struct  _packed
     double process;
     double process;
     long photo_stamp;           //采集时间戳
     long photo_stamp;           //采集时间戳
     const char *coll_time[10];
     const char *coll_time[10];
+    char alarm_tg[12];         //闹钟时间
     char mqttcfg1[64];         //
     char mqttcfg1[64];         //
     char mqttcfg2[64];         //
     char mqttcfg2[64];         //
     char csq[8];               //信号强度
     char csq[8];               //信号强度

+ 231 - 98
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -51,6 +51,7 @@ struct rx_msg
     rt_size_t size;
     rt_size_t size;
 };
 };
 static struct rt_semaphore rx_sem;    /* 用于接收消息的信号量 */
 static struct rt_semaphore rx_sem;    /* 用于接收消息的信号量 */
+static struct rt_semaphore rx5_sem;    /* 用于接收消息的信号量 */
 static struct rt_mutex dtu_write_mutex;  /* DTU写互斥锁,防止多线程串口*/
 static struct rt_mutex dtu_write_mutex;  /* DTU写互斥锁,防止多线程串口*/
 
 
 
 
@@ -60,7 +61,7 @@ rt_thread_t dtu_send_data = RT_NULL;
 static lwjson_stream_parser_t lwparser;
 static lwjson_stream_parser_t lwparser;
 
 
 rt_device_t dtuserial;   /*串口设备句柄*/
 rt_device_t dtuserial;   /*串口设备句柄*/
-
+rt_device_t serial_485;
 static uint8_t makejson_sta = 0;
 static uint8_t makejson_sta = 0;
 
 
 extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
 extern eMBMasterReqErrCode _485_play(USHORT *Buffer,USHORT NREGS);
@@ -130,6 +131,88 @@ static int DTU_uart2_init(void)
 }
 }
 
 
 
 
+static int DTU_uart5_init(void)
+{
+        struct serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT;
+        serial_485  = rt_device_find("uart5");
+        if(serial_485==RT_NULL)
+        {
+            LOG_E("Find Device:uart5 Failed!");
+            return -1;
+        }
+        rt_device_close(serial_485);
+#ifdef  RT_USING_SERIAL_V2
+        /*修改串口配置参数*/
+        dtuconfig.baud_rate = BAUD_RATE_115200;  //修改波特率9600
+        dtuconfig.data_bits = DATA_BITS_8;     //数据位8c
+        dtuconfig.stop_bits = STOP_BITS_1;     //停止位1
+        #ifdef RT_USING_SERIAL_V2
+        dtuconfig.rx_bufsz = 1024;
+        dtuconfig.tx_bufsz = 1024;
+        #else
+        dtuconfig.bufsz = 1024;                 //缓冲区1k
+        #endif
+
+        dtuconfig.parity = PARITY_NONE;        //奇校验
+#endif
+        #ifdef RT_USING_SERIAL_X
+        rt_device_control(serial_485, RT_DEVICE_CTRL_CONFIG, &dtuconfig);
+        #else
+        /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
+        rt_device_control(serial_485, RT_DEVICE_CTRL_CONFIG, &dtuconfig);
+        #endif
+
+        /* step4:打开串口设备。以DMA接收及轮询发送模式打开串口设备 */
+        #ifdef RT_USING_SERIAL_X
+        if (rt_device_open(dtuserial, RT_DEVICE_OFLAG_RDWR
+    #ifdef RT_SERIAL_USING_DMA
+                               | RT_DEVICE_FLAG_DMA_RX
+                               | RT_DEVICE_FLAG_DMA_TX
+    #else
+                               | RT_DEVICE_FLAG_INT_RX
+                               | RT_DEVICE_FLAG_INT_TX
+    #endif
+                            ) != RT_EOK)
+        {
+            LOG_E("Open device: %s failed\n", DTU_UART_NAME);
+            return -1;
+        }
+#endif
+        #ifdef RT_USING_SERIAL_V2
+        rt_err_t uart_res = rt_device_open(serial_485, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
+        if(uart_res!=RT_EOK)
+        {
+            LOG_E("uart5打开失败!");
+        }else{
+            LOG_I("uart5 Open Success!");
+        }
+        #endif
+        #ifdef RT_USING_SERIAL_V1
+        rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_DMA_RX);  //RT_DEVICE_FLAG_DMA_RX
+        #endif
+
+        return RT_EOK;
+}
+
+
+
+/*数据发送*/
+void Uart5_Write(char *fmt, ...)
+{
+    va_list ap;
+    static char dtu_str[1024];
+    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)-1, fmt, ap);
+    va_end(ap);
+    if (str_length > 1024 - 1)
+        str_length = 1024 - 1;
+    rt_device_write(serial_485, 0, dtu_str, str_length);
+    LOG_D("Uart5_Write:%s",dtu_str);
+}
+
+
 
 
 /*数据发送*/
 /*数据发送*/
 void DTU_Write(char *fmt, ...)
 void DTU_Write(char *fmt, ...)
@@ -148,6 +231,7 @@ void DTU_Write(char *fmt, ...)
     rt_mutex_release(&dtu_write_mutex);
     rt_mutex_release(&dtu_write_mutex);
     system_status.uart2_tx_bytes +=str_length;
     system_status.uart2_tx_bytes +=str_length;
     LOG_D("DTU_Write:%s",dtu_str);
     LOG_D("DTU_Write:%s",dtu_str);
+    Uart5_Write(dtu_str);
 }
 }
 /* 接收数据回调函数 */
 /* 接收数据回调函数 */
 static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
 static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
@@ -156,6 +240,12 @@ static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
     return RT_EOK;
     return RT_EOK;
 }
 }
 
 
+static rt_err_t uart5_input(rt_device_t dev, rt_size_t size)
+{
+    rt_sem_release(&rx5_sem);
+    return RT_EOK;
+}
+
 static void dtu_thread_entry_recv(void *parameter)
 static void dtu_thread_entry_recv(void *parameter)
 {
 {
     static char accum_buf[MAX_DTU_SIZE];  // 累积缓冲区(根据实际数据量调整)
     static char accum_buf[MAX_DTU_SIZE];  // 累积缓冲区(根据实际数据量调整)
@@ -202,6 +292,54 @@ static void dtu_thread_entry_recv(void *parameter)
           }
           }
     }
     }
 }
 }
+
+static void uart5_thread_entry_recv(void *parameter)
+{
+    static char accum_buf[MAX_DTU_SIZE];  // 累积缓冲区(根据实际数据量调整)
+    static size_t accum_len = 0;        // 累积缓冲区当前长度
+    char ch;
+    while (1) {
+        /* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
+        while (rt_device_read(serial_485, -1, &ch, 1) != 1)
+        {
+            /* 阻塞等待接收信号量,等到信号量后再次读取数据 */
+            rt_sem_take(&rx5_sem, RT_WAITING_FOREVER);
+        }
+        accum_buf[accum_len++]=ch;
+        if (accum_len >= sizeof(accum_buf)) {
+            // 防止超范围
+            accum_len = 0;
+            lwjson_stream_reset(&lwparser);
+            continue;
+        }
+        lwjsonr_t ret;
+        ret = lwjson_stream_parse(&lwparser, ch); // 把串口数据逐字节的喂给解析器去解析
+        switch(ret)
+        {
+            case lwjsonERRJSON:             // 1, 无效的字符
+              case lwjsonSTREAMWAITFIRSTCHAR: // 2, 等待首字符
+                LOG_W("invalid JSON byte:%s[%x]",ch,ch);
+                break;
+              case lwjsonSTREAMINPROG:        // 3, 正在解析中
+                break;
+              case lwjsonSTREAMDONE:          // 4, 解析已完成
+                 parseDtu(accum_buf);
+                 accum_len = 0;
+                 memset(accum_buf,0,sizeof(accum_buf));
+                 //rt_thread_kill(dtu_send_data, SIGUSR2);
+                 lwjson_stream_reset(&lwparser);
+                 break;
+              case lwjsonERRMEM:             // 5, 嵌套的太深("LWJSON_CFG_STREAM_STACK_SIZE")
+                 LOG_E("parser stack overflow (ERRMEM), resetting parser!");
+                 lwjson_stream_reset(&lwparser);
+                 break;
+              default: // 流式解析时, 其它的返回值, 都不应该出现
+                  LOG_E("internal error, lwjson_stream_parse() returned: %d, data receive thread will exit!!!",ret);
+                  break;
+          }
+    }
+}
+
 // 解析时间戳并返回一个tm结构体
 // 解析时间戳并返回一个tm结构体
 struct tm* parseTimestamp(const char *timestamp) {
 struct tm* parseTimestamp(const char *timestamp) {
     if (strlen(timestamp) != 14) {
     if (strlen(timestamp) != 14) {
@@ -412,6 +550,7 @@ int dtu_data_play(void)
 {
 {
     lwjson_stream_init(&lwparser, NULL);
     lwjson_stream_init(&lwparser, NULL);
     DTU_uart2_init();
     DTU_uart2_init();
+    DTU_uart5_init();
     rt_err_t rm_dtu_result = rt_mutex_init(&dtu_write_mutex, "dtu_mtx", RT_IPC_FLAG_FIFO);
     rt_err_t rm_dtu_result = rt_mutex_init(&dtu_write_mutex, "dtu_mtx", RT_IPC_FLAG_FIFO);
     if (rm_dtu_result != RT_EOK)
     if (rm_dtu_result != RT_EOK)
     {
     {
@@ -419,8 +558,10 @@ int dtu_data_play(void)
     }
     }
     //初始化消息队列
     //初始化消息队列
     rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
     rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
+    rt_sem_init(&rx5_sem, "rx5_sem", 0, RT_IPC_FLAG_FIFO);
     /* 设置接收回调函数 */
     /* 设置接收回调函数 */
     rt_device_set_rx_indicate(dtuserial, dtu_input);
     rt_device_set_rx_indicate(dtuserial, dtu_input);
+    rt_device_set_rx_indicate(serial_485, uart5_input);
     /*创建线程-指令发送*/
     /*创建线程-指令发送*/
     dtu_send_data = rt_thread_create("DTU_Uart_thread_send",
     dtu_send_data = rt_thread_create("DTU_Uart_thread_send",
                                     dtu_thread_entry_send,RT_NULL,
                                     dtu_thread_entry_send,RT_NULL,
@@ -434,6 +575,17 @@ int dtu_data_play(void)
             DTU_THREAD_STACK_SIZE,
             DTU_THREAD_STACK_SIZE,
             DTU_THREAD_PRIORITY,
             DTU_THREAD_PRIORITY,
             DTU_THREAD_TIMESLICE);
             DTU_THREAD_TIMESLICE);
+#if MATCH_DEVICE == 1
+     rt_thread_t uart5_recv_data = rt_thread_create("Uart5_thread_recv",
+                uart5_thread_entry_recv, RT_NULL,
+                DTU_THREAD_STACK_SIZE,
+                7,
+                DTU_THREAD_TIMESLICE);
+
+    if (uart5_recv_data != RT_NULL)
+        rt_thread_startup(uart5_recv_data);
+#endif
+    //创建线程
     /* 如果获得线程控制块,启动这个线程 */
     /* 如果获得线程控制块,启动这个线程 */
 //    if(dtu_send_data!=RT_NULL)
 //    if(dtu_send_data!=RT_NULL)
 //        rt_thread_startup(dtu_send_data);
 //        rt_thread_startup(dtu_send_data);
@@ -1645,17 +1797,16 @@ int parseDtu(char *json_string)
           PARAMS = cJSON_GetObjectItem(root,"params");
           PARAMS = cJSON_GetObjectItem(root,"params");
           RESULT = cJSON_GetObjectItem(root,"result");
           RESULT = cJSON_GetObjectItem(root,"result");
           item_cmd = cJSON_GetObjectItem(root,"cmd");
           item_cmd = cJSON_GetObjectItem(root,"cmd");
-          cJSON* item_aplay = cJSON_GetObjectItem(root,"aplay");
           item_checkself = cJSON_GetObjectItem(root,"selfcheck");
           item_checkself = cJSON_GetObjectItem(root,"selfcheck");
           photolink = cJSON_GetObjectItem(root,"photolink");
           photolink = cJSON_GetObjectItem(root,"photolink");
           cJSON* ledsta = cJSON_GetObjectItem(root,"ledsta");
           cJSON* ledsta = cJSON_GetObjectItem(root,"ledsta");
           cJSON* cam_cmd= cJSON_GetObjectItem(root,"cam_code");
           cJSON* cam_cmd= cJSON_GetObjectItem(root,"cam_code");
-          cJSON* yolo_start = cJSON_GetObjectItem(root,"yolo");
           item_ext=cJSON_GetObjectItem(root,"ext");
           item_ext=cJSON_GetObjectItem(root,"ext");
           cJSON* cache_data_num = cJSON_GetObjectItem(root,"cache_data_num");
           cJSON* cache_data_num = cJSON_GetObjectItem(root,"cache_data_num");
           cJSON* cache_photo_num = cJSON_GetObjectItem(root,"cache_photo_num");
           cJSON* cache_photo_num = cJSON_GetObjectItem(root,"cache_photo_num");
           cJSON* mqtt_data_record_TF_Max = cJSON_GetObjectItem(root,"mqtt_data_record_TF_Max");
           cJSON* mqtt_data_record_TF_Max = cJSON_GetObjectItem(root,"mqtt_data_record_TF_Max");
           cJSON* picture_record_TF_Max = cJSON_GetObjectItem(root,"picture_record_TF_Max");
           cJSON* picture_record_TF_Max = cJSON_GetObjectItem(root,"picture_record_TF_Max");
+          cJSON* u_image_count = cJSON_GetObjectItem(root,"u_image_count");
           if(JSONRPC!=NULL){
           if(JSONRPC!=NULL){
               if(METHOD!=NULL){
               if(METHOD!=NULL){
                   if(strcmp(METHOD->valuestring,"sync_param")==0){
                   if(strcmp(METHOD->valuestring,"sync_param")==0){
@@ -1684,12 +1835,31 @@ int parseDtu(char *json_string)
                         }
                         }
                   }else if(strcmp(METHOD->valuestring,"systeminfo")==0) {
                   }else if(strcmp(METHOD->valuestring,"systeminfo")==0) {
                       upload_sys_monitor_info();
                       upload_sys_monitor_info();
+                  }else if(strcmp(METHOD->valuestring,"switch_mode")==0) {
+                      if(PARAMS !=NULL&&PARAMS->type==cJSON_Object){
+                          cJSON* mode = cJSON_GetObjectItem(PARAMS, "mode");
+                          if(mode!=NULL&&mode->type==cJSON_String){
+                              if(strcmp(mode->valuestring,"A")==0){
+                                  device_status.work_mode = 0;
+                                  ef_set_env_blob("work_mode", &device_status.work_mode, sizeof(device_status.work_mode));
+                                  LOG_W("修改工作模式:%d",device_status.work_mode);
+                              }else if(strcmp(mode->valuestring,"B")==0){
+                                  device_status.work_mode = 1;
+                                  ef_set_env_blob("work_mode", &device_status.work_mode, sizeof(device_status.work_mode));
+                                  LOG_W("修改工作模式:%d",device_status.work_mode);
+                              }
+                              static char temp[10];
+                              rt_sprintf(temp, "mode:%d",device_status.work_mode);
+                              DTU_Write("%s",makeJson_Warn(temp, "switch mode"));
+                          }
+                      }
                   }
                   }
                   else{
                   else{
                       LOG_W("未知的命令: %s", METHOD->valuestring);
                       LOG_W("未知的命令: %s", METHOD->valuestring);
                   }
                   }
 
 
               }
               }
+              //json rpc服务端响应
               if(RESULT!=NULL&&RESULT->type==cJSON_String)
               if(RESULT!=NULL&&RESULT->type==cJSON_String)
               {
               {
                   if(strcmp(RESULT->valuestring,"success")==0){
                   if(strcmp(RESULT->valuestring,"success")==0){
@@ -1697,6 +1867,8 @@ int parseDtu(char *json_string)
                           device_status.C01 = 0;
                           device_status.C01 = 0;
                           Stop_timer_Uart2();
                           Stop_timer_Uart2();
                       }
                       }
+                  }else{
+                      HMI_WRITE("menu.result.txt=\"%s\"",RESULT->valuestring);
                   }
                   }
               }
               }
           }
           }
@@ -1708,6 +1880,9 @@ int parseDtu(char *json_string)
           {
           {
               HMI_WRITE("recordcfg.pic_n_cfg.val=%d",picture_record_TF_Max->valueint);
               HMI_WRITE("recordcfg.pic_n_cfg.val=%d",picture_record_TF_Max->valueint);
           }
           }
+          if(u_image_count!=NULL){
+              HMI_WRITE("recordcfg.u_i_c.val=%d",u_image_count->valueint);
+          }
           if(cache_data_num!=NULL)
           if(cache_data_num!=NULL)
           {
           {
               HMI_WRITE("recordcfg.data_n.val=%d",cache_data_num->valueint);
               HMI_WRITE("recordcfg.data_n.val=%d",cache_data_num->valueint);
@@ -1723,91 +1898,7 @@ int parseDtu(char *json_string)
               DTU_Write(read_record);
               DTU_Write(read_record);
               free(read_record);
               free(read_record);
           }
           }
-          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){
           if(cam_cmd!=NULL){
               //先检查定时器状态,否则会崩溃
               //先检查定时器状态,否则会崩溃
               rt_timer_stop(timer_uart2);
               rt_timer_stop(timer_uart2);
@@ -1922,22 +2013,13 @@ int parseDtu(char *json_string)
               {
               {
                   type = cJSON_GetObjectItem(item_ext,"type");
                   type = cJSON_GetObjectItem(item_ext,"type");
                   cJSON *time_s = cJSON_GetObjectItem(item_ext,"time");
                   cJSON *time_s = cJSON_GetObjectItem(item_ext,"time");
-                  if(strstr(type->valuestring,"rtu_off_on")!=RT_NULL)
+                  if(strstr(type->valuestring,"rtu_off_on")!=RT_NULL)       //RTU重新上电
                   {
                   {
                       LOG_W("DTU 12V Power down");
                       LOG_W("DTU 12V Power down");
                       ctr_RTU_DTU(OFF);
                       ctr_RTU_DTU(OFF);
                       rt_thread_delay(5000);
                       rt_thread_delay(5000);
                       ctr_RTU_DTU(ON);
                       ctr_RTU_DTU(ON);
                   }
                   }
-                  //对焦拍照
-                  else if(strstr(type->valuestring,"auto_takephoto")!=RT_NULL)
-                  {
-                      device_status.autotakepic = 1;
-                      rt_thread_delay(2000);
-                      char *auto_takephoto = makeJson_Warn("send cmd success:auto_takephoto","control");
-                      DTU_Write("%s",auto_takephoto);
-                      rt_free(auto_takephoto);
-                  }
                   else if(strstr(type->valuestring,"takephoto")!=RT_NULL)
                   else if(strstr(type->valuestring,"takephoto")!=RT_NULL)
                   {
                   {
                       //HK_TakePhoto();
                       //HK_TakePhoto();
@@ -1994,6 +2076,51 @@ int parseDtu(char *json_string)
                   {
                   {
                       ctr_led(OFF);
                       ctr_led(OFF);
                   }
                   }
+                  //{"ext": {"type": "lamp_off"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"lamp_off")!=RT_NULL)
+                  {
+                      ctr_lamp(OFF,1);
+                  }
+                  //{"ext": {"type": "lamp_on"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"lamp_on")!=RT_NULL)
+                  {
+                      ctr_lamp(ON,1);
+                  }
+                  //{"ext": {"type": "heat_on"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"heat_on")!=RT_NULL)
+                  {
+                      ctr_Heat(ON);
+                  }
+                  //{"ext": {"type": "heat_off"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"heat_off")!=RT_NULL)
+                  {
+                      ctr_Heat(OFF);
+                  }
+                  //打开上仓门
+                  else if (strstr(type->valuestring,"up_door_open")!=RT_NULL)
+                  {
+                      device_status.ctr_up_motor = 1;
+                  }
+                  //关闭上仓门
+                  else if (strstr(type->valuestring,"up_door_close")!=RT_NULL)
+                  {
+                      device_status.ctr_up_motor = 2;
+                  }
+                  //打开下仓门
+                  else if (strstr(type->valuestring,"down_door_open")!=RT_NULL)
+                  {
+                      device_status.ctr_down_motor = 1;
+                  }
+                  //关闭下仓门
+                  else if (strstr(type->valuestring,"down_door_close")!=RT_NULL)
+                  {
+                      device_status.ctr_down_motor = 2;
+                  }
+                  //清扫
+                  else if (strstr(type->valuestring,"clear_on")!=RT_NULL)
+                  {
+                      device_status.clear_status = 1;
+                  }
                   //{"ext": {"type": "route_off","time": 5}, "cmd": "ctrl"}   //远程关闭路由器电源
                   //{"ext": {"type": "route_off","time": 5}, "cmd": "ctrl"}   //远程关闭路由器电源
                   else if (strstr(type->valuestring,"route_off")!=RT_NULL)
                   else if (strstr(type->valuestring,"route_off")!=RT_NULL)
                   {
                   {
@@ -2230,7 +2357,12 @@ int parseDtu(char *json_string)
                   cJSON *gps_view = cJSON_GetObjectItem(item_ext,"gps_view");
                   cJSON *gps_view = cJSON_GetObjectItem(item_ext,"gps_view");
                   //如果DTU的IMEI和FLash中的不一样,保存到FLASH
                   //如果DTU的IMEI和FLash中的不一样,保存到FLASH
                   value_commn = cJSON_GetObjectItem(item_ext,"photo_sta");
                   value_commn = cJSON_GetObjectItem(item_ext,"photo_sta");
-
+                  cJSON *upan_sta = cJSON_GetObjectItem(item_ext,"upan_sta");
+                  if(upan_sta!=NULL){
+                      device_status.upan_sta = upan_sta->valueint;
+                  }else{
+                      device_status.upan_sta = 1;
+                  }
                   if(photo_sta!=NULL){
                   if(photo_sta!=NULL){
                       device_status.camsta = photo_sta->valueint;
                       device_status.camsta = photo_sta->valueint;
                       LOG_I("相机状态:%d",device_status.camsta);
                       LOG_I("相机状态:%d",device_status.camsta);
@@ -2967,6 +3099,7 @@ int parseDtu(char *json_string)
                           rt_thread_delay(1000);
                           rt_thread_delay(1000);
                           MA_save();
                           MA_save();
                           rt_thread_delay(1000);
                           rt_thread_delay(1000);
+                          backup_param_to_rtu();
                }
                }
           }
           }
         cJSON_Delete(root);
         cJSON_Delete(root);

+ 1 - 0
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -61,6 +61,7 @@ void dtu_send_data_start(void);
 
 
 //{"cmd":"synchronization","ext":{"year":1,"month":1,"day":0,"hour":25,"min":0,"sec":0,"lat":"113.2056","lng":"21.0596","csq",31,"net",0,"iccid","123135453","imei":"895864646464464"}}
 //{"cmd":"synchronization","ext":{"year":1,"month":1,"day":0,"hour":25,"min":0,"sec":0,"lat":"113.2056","lng":"21.0596","csq",31,"net",0,"iccid","123135453","imei":"895864646464464"}}
 void DTU_Write(char *fmt, ...);
 void DTU_Write(char *fmt, ...);
+void Uart5_Write(char *fmt, ...);
 int dtu_data_play(void);
 int dtu_data_play(void);
 int parseDtu(char *json_string);
 int parseDtu(char *json_string);
 char *makeJson(void);
 char *makeJson(void);

+ 280 - 194
Application_cbd_apm32f1/applications/hmi.c

@@ -293,6 +293,7 @@ static void Hmi_thread_entry(void *parameter)
         device_status.collt_box_sta = 0;
         device_status.collt_box_sta = 0;
         device_status.run_sta = 0;
         device_status.run_sta = 0;
     }
     }
+    device_status.upan_sta = 1;
     device_status.camsta = 1;
     device_status.camsta = 1;
     while(1)
     while(1)
     {
     {
@@ -357,11 +358,168 @@ void Stop_timer_Uart2(void)
     }
     }
 }
 }
 
 
+static void refresh_hmi_Component(struct tm tm)
+{
+    char *readinfo =  makeJson_ReadInfo();
+    if(device_status.refresh_num==5)
+    {
+        device_status.refresh_num = 15;
+        DTU_Write("%s",readinfo);
+        //list_mem();
+        device_status.hmi_fresh = 1;
+        rt_thread_delay(100);
+    }
+    //在解析getinfo中清除超时
+    if(device_status.refresh_timeout==30)
+    {
+          rt_sprintf(device_status.sim,"1");
+          rt_sprintf(device_status.net,"1");
+          rt_sprintf(device_status.csq,"0");
+          device_status.upan_sta = 1;
+          device_status.camsta = 1;
+          device_status.link_sta=0;
+          device_status.refresh_timeout=0;
+    }
+    rt_free(readinfo);
+    device_status.refresh_num--;
+    device_status.refresh_timeout++;
+    if(device_status.version_type!=6)
+    {
+        HMI_WRITE("uploadSet.iccid.txt=\"%s\"",device_status.iccid);
+        if(strstr(device_status.mqttcfg1,"8.136.98.49")!=NULL)
+        {
+            HMI_WRITE("uploadSet.plt.val=%d",RESET);
+        }
+        else if (strstr(device_status.mqttcfg1,"120.27.222.26")!=NULL) {
+            HMI_WRITE("uploadSet.plt.val=%d",SET);
+        }
+        //HMI_WRITE("mqttcfg.mqtt1Message.txt=\"%s\"",device_status.mqttcfg1);
+        HMI_WRITE("uploadSet.t0.txt=\"%s\"",device_status.mqttcfg1);
+
+        //更新固件版本号
+        HMI_WRITE("debug.t3.txt=\"%s\"",device_status.driver);
+        //更新固件编译日期
+        HMI_WRITE("debug.t4.txt=\"%s\"",device_status.driver_compile);
+        //
+        HMI_WRITE("debug.t5.txt=\"%s\"",device_status.driver_bl);
+        HMI_WRITE("debug.t7.txt=\"%s\"",device_status.driver_compile);
+        //更新dtu/rtu版本
+        HMI_WRITE("debug.t9.txt=\"%s\"",device_status.driver_4g);
+        //更新时间
+        HMI_WRITE("menu.rtc.txt=\"%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);
+        HMI_WRITE("workSta.rtc.txt=\"%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);
+        HMI_WRITE("set.t0.txt=\"%d\"",tm.tm_hour);
+        HMI_WRITE("set.t1.txt=\"%d\"",tm.tm_min);
+        HMI_WRITE("set.t2.txt=\"%d\"",tm.tm_sec);
+        //更新电压
+        HMI_WRITE("workSta.vbat.txt=\"%s\"",device_status.voltage);
+        //更新电流
+        HMI_WRITE("workSta.power.txt=\"%s\"",device_status.power);
+        //更新温湿度数据
+        HMI_WRITE("workSta.envHum.val=%d",atoi(device_status.humidity));
+        HMI_WRITE("workSta.envTem.val=%d",atoi(device_status.tempture));
+        //更新电池状态
+        HMI_WRITE("workSta.batStatus.val=%d",device_status.bat_status);
+        //更新上仓门状态
+        HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
+        //更新下仓门状态
+        HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
+        //更新工作状态
+        HMI_WRITE("workSta.workStatus.val=%d",device_status.work_status);
+        //更新温控状态
+        HMI_WRITE("workSta.tempStatus.val=%d",device_status.temp_status);
+        //更新雨控状态
+        HMI_WRITE("workSta.rainStatus.val=%d",device_status.rain_status);
+        //更新光控状态
+        HMI_WRITE("workSta.sunStatus.val=%d",device_status.sun_status);
+        //更新收集时间
+        HMI_WRITE("sysSet.stime.val=%d",device_status.clt_time);
+        //更新加热时间
+        HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
+        HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
+        //
+        HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
+        //更新加热时间和温度
+        HMI_WRITE("workSta.heatTem.val=%d",device_status.heattem);
+        HMI_WRITE("sysSet.jheat.val=%d",device_status.heatvalue);
+        //更新加热状态
+        HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
+        //更新密码
+        HMI_WRITE("inputPasswd.pwdData.txt=\"8888\"");
+        //更新时间设置中的参数
+        //更新定时模式
+        HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
+        //更新光控定时时长
+        HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
+        //更新时控开始
+        HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
+        //更新时控结束
+        HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
+        //SIM卡状态
+        HMI_WRITE("workSta.bt0.val=%d",atoi(device_status.sim));
+        //ID
+        HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
+        HMI_WRITE("menu.deviceId.txt=\"%s\"",device_status.deviceId);
+        //HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
+        //数据上传间隔
+        HMI_WRITE("uploadSet.datt.val=%d",device_status.dattim);
+        //语音音量
+        HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
+        //更新熄屏时间
+        if(device_status.thsp<60) device_status.thsp = device_status.thsp * 60;
+        HMI_WRITE("thsp=%d",device_status.thsp);
+
+        if(strstr(device_status.link_ip,".")!=RT_NULL){
+            HMI_WRITE("menu.t0.txt=\"%s\"",device_status.link_ip);
+        }
+#if MATCH_DEVICE == 1
+        HMI_WRITE("menu.mode.val=%d",device_status.work_mode);
+        HMI_WRITE("menu.upan.val=%d",device_status.upan_sta);
+        HMI_WRITE("menu.alarm_tg.txt=\"%s\"",device_status.alarm_tg);
+        //更新有线连接状态
+        HMI_WRITE("menu.va_net.val=%d",0);
+#else
+        HMI_WRITE("menu.va_net.val=%d",device_status.link_sta);
+#endif
+    }
+    HMI_WRITE("menu.cam_sta.val=%d",device_status.camsta);
+    if(atoi(device_status.gps)==1){
+        HMI_WRITE("menu.gps_state.txt=\"定位成功:(%s)%d/%d\"",device_status.gps_state,device_status.gps_inuse,device_status.gps_view);
+    }else if(atoi(device_status.gps)==2){
+        HMI_WRITE("menu.gps_state.txt=\"定位成功:(基站)\"");
+    }
+
+    //更新联网状态
+    if(atoi(device_status.net)==1)
+    {
+        HMI_WRITE("menu.net.val=1");
+        HMI_WRITE("workSta.net.val=1");
+    }
+    else {
+        #if MATCH_DEVICE == 0
+        HMI_WRITE("workSta.net.val=0");
+        HMI_WRITE("menu.net.val=0");
+        //更新CSQ
+        HMI_WRITE("menu.csq_value.txt=\"%s\"",device_status.csq);
+        HMI_WRITE("menu.va_csq.val=%d",atoi(device_status.csq));
+        HMI_WRITE("workSta.csq_value.txt=\"%s\"",device_status.csq);
+        #else
+        HMI_WRITE("workSta.net.val=1");
+        HMI_WRITE("menu.net.val=1");
+        HMI_WRITE("menu.va_csq.val=0");
+        #endif
+    }
+    if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
+    {
+        HMI_WRITE("menu.net.val=1");
+        HMI_WRITE("workSta.net.val=2");
+    }
+    /**********************************************************************/
+}
 
 
 /***************************** 解析从屏幕收到的数据 begin **********************************/
 /***************************** 解析从屏幕收到的数据 begin **********************************/
 static void HMI_Decode(void)
 static void HMI_Decode(void)
 {
 {
-
     time_t now = time(RT_NULL);
     time_t now = time(RT_NULL);
     static struct tm tm;
     static struct tm tm;
     gmtime_r(&now, &tm);
     gmtime_r(&now, &tm);
@@ -369,151 +527,7 @@ static void HMI_Decode(void)
     static char *var;
     static char *var;
     if(device_status.refresh_num==0)  device_status.refresh_num = 10;
     if(device_status.refresh_num==0)  device_status.refresh_num = 10;
     if(strstr(rx_buffer,"getFullData") != NULL){
     if(strstr(rx_buffer,"getFullData") != NULL){
-        char *readinfo =  makeJson_ReadInfo();
-        if(device_status.refresh_num==5)
-        {
-            device_status.refresh_num = 15;
-            DTU_Write("%s",readinfo);
-            //list_mem();
-            device_status.hmi_fresh = 1;
-            rt_thread_delay(100);
-        }
-        //在解析getinfo中清除超时
-        if(device_status.refresh_timeout==30)
-        {
-              rt_sprintf(device_status.sim,"1");
-              rt_sprintf(device_status.net,"1");
-              rt_sprintf(device_status.csq,"0");
-              device_status.camsta = 1;
-              device_status.link_sta=0;
-              device_status.refresh_timeout=0;
-        }
-        rt_free(readinfo);
-        device_status.refresh_num--;
-        device_status.refresh_timeout++;
-        if(device_status.version_type!=6)
-        {
-            HMI_WRITE("uploadSet.iccid.txt=\"%s\"",device_status.iccid);
-            if(strstr(device_status.mqttcfg1,"8.136.98.49")!=NULL)
-            {
-                HMI_WRITE("uploadSet.plt.val=%d",RESET);
-            }
-            else if (strstr(device_status.mqttcfg1,"120.27.222.26")!=NULL) {
-                HMI_WRITE("uploadSet.plt.val=%d",SET);
-            }
-            //HMI_WRITE("mqttcfg.mqtt1Message.txt=\"%s\"",device_status.mqttcfg1);
-            HMI_WRITE("uploadSet.t0.txt=\"%s\"",device_status.mqttcfg1);
-
-            //更新固件版本号
-            HMI_WRITE("debug.t3.txt=\"%s\"",device_status.driver);
-            //更新固件编译日期
-            HMI_WRITE("debug.t4.txt=\"%s\"",device_status.driver_compile);
-            //
-            HMI_WRITE("debug.t5.txt=\"%s\"",device_status.driver_bl);
-            HMI_WRITE("debug.t7.txt=\"%s\"",device_status.driver_compile);
-            //更新dtu/rtu版本
-            HMI_WRITE("debug.t9.txt=\"%s\"",device_status.driver_4g);
-            //更新时间
-            HMI_WRITE("menu.rtc.txt=\"%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);
-            HMI_WRITE("workSta.rtc.txt=\"%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);
-            HMI_WRITE("set.t0.txt=\"%d\"",tm.tm_hour);
-            HMI_WRITE("set.t1.txt=\"%d\"",tm.tm_min);
-            HMI_WRITE("set.t2.txt=\"%d\"",tm.tm_sec);
-            //更新电压
-            HMI_WRITE("workSta.vbat.txt=\"%s\"",device_status.voltage);
-            //更新电流
-            HMI_WRITE("workSta.power.txt=\"%s\"",device_status.power);
-            //更新温湿度数据
-            HMI_WRITE("workSta.envHum.val=%d",atoi(device_status.humidity));
-            HMI_WRITE("workSta.envTem.val=%d",atoi(device_status.tempture));
-            //更新电池状态
-            HMI_WRITE("workSta.batStatus.val=%d",device_status.bat_status);
-            //更新上仓门状态
-            HMI_WRITE("workSta.upStatus.val=%d",device_status.up_status);
-            //更新下仓门状态
-            HMI_WRITE("workSta.downStatus.val=%d",device_status.down_status);
-            //更新工作状态
-            HMI_WRITE("workSta.workStatus.val=%d",device_status.work_status);
-            //更新温控状态
-            HMI_WRITE("workSta.tempStatus.val=%d",device_status.temp_status);
-            //更新雨控状态
-            HMI_WRITE("workSta.rainStatus.val=%d",device_status.rain_status);
-            //更新光控状态
-            HMI_WRITE("workSta.sunStatus.val=%d",device_status.sun_status);
-            //更新有线连接状态
-            HMI_WRITE("menu.va_net.val=%d",device_status.link_sta);
-            //更新CSQ
-            HMI_WRITE("menu.csq_value.txt=\"%s\"",device_status.csq);
-            HMI_WRITE("menu.va_csq.val=%d",atoi(device_status.csq));
-            HMI_WRITE("workSta.csq_value.txt=\"%s\"",device_status.csq);
-            //更新收集时间
-            HMI_WRITE("sysSet.stime.val=%d",device_status.clt_time);
-            //更新加热时间
-            HMI_WRITE("workSta.heatTime.val=%d",device_status.heattime);
-            HMI_WRITE("sysSet.jtime.val=%d",device_status.heattime);
-            //
-            HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
-            //更新加热时间和温度
-            HMI_WRITE("workSta.heatTem.val=%d",device_status.heattem);
-            HMI_WRITE("sysSet.jheat.val=%d",device_status.heatvalue);
-            //更新加热状态
-            HMI_WRITE("workSta.heatStatus.val=%d",device_status.heat_status);
-            //更新密码
-            HMI_WRITE("inputPasswd.pwdData.txt=\"8888\"");
-            //更新时间设置中的参数
-            //更新定时模式
-            HMI_WRITE("clockSet.timeSwitch.val=%d",device_status.timeSwitch);
-            //更新光控定时时长
-            HMI_WRITE("clockSet.sunBar.val=%d",device_status.sunBar);
-            //更新时控开始
-            HMI_WRITE("clockSet.startBar.val=%d",device_status.startBar);
-            //更新时控结束
-            HMI_WRITE("clockSet.stopBar.val=%d",device_status.stopBar);
-            //SIM卡状态
-            HMI_WRITE("workSta.bt0.val=%d",atoi(device_status.sim));
-            //ID
-            HMI_WRITE("menu.equipid.txt=\"%s\"",device_status.imei);
-            HMI_WRITE("menu.deviceId.txt=\"%s\"",device_status.deviceId);
-            //HMI_WRITE("workSta.equipid.txt=\"%s\"",device_status.imei);
-            //数据上传间隔
-            HMI_WRITE("uploadSet.datt.val=%d",device_status.dattim);
-            //语音音量
-            HMI_WRITE("sysSet.vol.val=%d",device_status.vol);
-            //更新熄屏时间
-            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);
-
-        if(atoi(device_status.gps)==1){
-            HMI_WRITE("menu.gps_state.txt=\"定位成功:(%s)%d/%d\"",device_status.gps_state,device_status.gps_inuse,device_status.gps_view);
-        }else if(atoi(device_status.gps)==2){
-            HMI_WRITE("menu.gps_state.txt=\"定位成功:(基站)\"");
-        }
-
-        //更新联网状态
-        if(atoi(device_status.net)==1)
-        {
-            HMI_WRITE("menu.net.val=1");
-            HMI_WRITE("workSta.net.val=1");
-        }
-        else {
-            #if MATCH_DEVICE == 0
-            HMI_WRITE("workSta.net.val=0");
-            HMI_WRITE("menu.net.val=0");
-            #else
-            HMI_WRITE("workSta.net.val=1");
-            HMI_WRITE("menu.net.val=1");
-            #endif
-        }
-        if(atoi(device_status.csq)==0&&atoi(device_status.net)==1)
-        {
-            HMI_WRITE("menu.net.val=1");
-            HMI_WRITE("workSta.net.val=2");
-        }
-        /**********************************************************************/
+        refresh_hmi_Component(tm);
     }
     }
     else if (strstr(rx_buffer,"getClockData")!=NULL) {
     else if (strstr(rx_buffer,"getClockData")!=NULL) {
         //更新定时模式
         //更新定时模式
@@ -617,6 +631,26 @@ static void HMI_Decode(void)
         LOG_I("停止一键测试!!!");
         LOG_I("停止一键测试!!!");
         device_status.auto_test_sw=0;
         device_status.auto_test_sw=0;
     }
     }
+    else if (strstr(rx_buffer,"putTest.switchCc=1")!=NULL)
+    {
+        LOG_I("推杆打开测试!!!");
+        ctr_Cold(ON);
+    }
+    else if (strstr(rx_buffer,"putTest.switchCc=0")!=NULL)
+    {
+        LOG_I("推杆关闭测试!!!");
+        ctr_Cold(OFF);
+    }
+    else if (strstr(rx_buffer,"putTest.shakeCc=1")!=NULL)
+    {
+        LOG_I("震动电机打开测试!!!");
+        ctr_Collect_Fan(ON);
+    }
+    else if (strstr(rx_buffer,"putTest.shakeCc=0")!=NULL)
+    {
+        LOG_I("震动电机关闭测试!!!");
+        ctr_Collect_Fan(OFF);
+    }
     else if (strstr(rx_buffer,"turnzp")!=NULL) {
     else if (strstr(rx_buffer,"turnzp")!=NULL) {
         LOG_W("转仓!");
         LOG_W("转仓!");
         device_status.clear_status=2;
         device_status.clear_status=2;
@@ -810,6 +844,56 @@ static void HMI_Decode(void)
             }
             }
         }
         }
     }
     }
+    //设置闹钟时间
+    else if (strstr(rx_buffer,"ALARM=")!=NULL)
+    {
+        char *var = strstr(rx_buffer,"=");
+        if (var == NULL) {
+            return;
+        }
+        var ++;
+
+        // ===================== 修复:去掉末尾的 \r 或 换行 =====================
+        // 遍历字符串,把 \r \n 全部替换成结束符
+        for (int i = 0; var[i] != '\0'; i++) {
+            if (var[i] == '\r' || var[i] == '\n') {
+                var[i] = '\0';
+                break;
+            }
+        }
+        if(var[6] != '\r') {
+            var[6] = '\0';
+        }
+        // 现在 var 只剩下干净的 6 位数字了
+        int len = strlen(var);
+        int is_valid = 1;
+
+        // 1. 必须是 6 个字符(已经去掉\r)
+        if (len != 6) {
+            is_valid = 0;
+        }
+        // 2. 必须全部是数字 0-9
+        else {
+            for (int i = 0; i < 6; i++) {
+                if (!(var[i] >= '0' && var[i] <= '9')) {
+                    is_valid = 0;
+                    break;
+                }
+            }
+        }
+
+        // 校验不通过:打印报错,不赋值
+        if (!is_valid) {
+            LOG_E("闹钟格式错误!必须是 6 位数字时间(如 150000),当前值:%s", var);
+            return;
+        }
+        // ======================================================================
+
+        // 格式正确才赋值
+        LOG_I("设置闹钟时间:%s",var);
+        rt_sprintf(device_status.alarm_tg, "%s", var);
+        ef_set_env_blob("alarm_tg", &device_status.alarm_tg, sizeof(device_status.alarm_tg));
+    }
     //设备编码设置
     //设备编码设置
     else if (strstr(rx_buffer,"deviceId=")!=NULL)
     else if (strstr(rx_buffer,"deviceId=")!=NULL)
     {
     {
@@ -927,14 +1011,6 @@ static void HMI_Decode(void)
                 ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
                 ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));
             }
             }
 
 
-//            time_t now;
-//            time(&now);
-//            static struct tm nowstamp;
-//            nowstamp =*localtime(&now);
-//            nowstamp.tm_hour = nowstamp.tm_hour - 8;
-//            static rt_uint32_t nowstamp_num = 0;
-//            nowstamp_num = mktime(&nowstamp);
-//            device_status.light_over_tim = device_status.sunBar * 3600 + nowstamp_num;
         }
         }
         else {
         else {
             LOG_E("参数设置异常(光控时长):%d!!!",atoi(value_str));
             LOG_E("参数设置异常(光控时长):%d!!!",atoi(value_str));
@@ -1443,22 +1519,38 @@ static void HMI_Decode(void)
             device_status.selfcheck_ws = 2;
             device_status.selfcheck_ws = 2;
             LOG_W("开始自检:%d",device_status.selfcheck_ws);
             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);
-//        ctr_xmove(400,200);//旋转清虫
-        //使用硬件定时器控制
-        device_status.autotakepic = 10;
-
-    }else if(strstr(rx_buffer,"yichong")!=NULL)
+    }else if(strstr(rx_buffer,"SwitchMode")!=NULL)
     {
     {
-        _485_play(sound122, 4);
-        HMI_WRITE("sysTest.result.txt=\"益虫测试!\"");
-//        ctr_Motor_Driver_Power(ON);
-//        ctr_xmove(400,200);//旋转清虫
-        device_status.autotakepic = 11;
+        device_status.work_mode = !device_status.work_mode;
+        ef_set_env_blob("work_mode", &device_status.work_mode, sizeof(device_status.work_mode));
+        LOG_W("修改工作模式:%d",device_status.work_mode);
+    }else if(strstr(rx_buffer,"DeleteUimage")!=NULL){
+        char* temp = makeJsonRpc2_0("upan_delete_image", NULL, 1);
+        if(temp){
+            DTU_Write(temp);
+            free(temp);
+        }
+    }else if(strstr(rx_buffer,"MOVE_IMAGE")!=NULL){
+        char* temp = makeJsonRpc2_0("MOVE_IMAGE", NULL, 1);
+        if(temp){
+            DTU_Write(temp);
+            free(temp);
+        }
+    }else if(strstr(rx_buffer,"COPY_IMAGE")!=NULL){
+        cJSON *params = cJSON_CreateObject();        // params 子对象
+        cJSON_AddNumberToObject(params, "st", device_status.startBar);     // st:20
+        cJSON_AddNumberToObject(params, "et", device_status.stopBar);      // et:7
+        char* temp = makeJsonRpc2_0("COPY_IMAGE", params, 1);
+        if(temp){
+            DTU_Write(temp);
+            free(temp);
+        }
+    }else if(strstr(rx_buffer,"UMOUNT_UPAN")!=NULL){
+            char* temp = makeJsonRpc2_0("UMOUNT_UPAN", NULL, 1);
+            if(temp){
+                DTU_Write(temp);
+                free(temp);
+            }
     }
     }
 }
 }
 
 
@@ -1531,13 +1623,11 @@ static void Ctr_Mortor_entry(void* parameter)
             ctr_cangmen_down(OPEN);
             ctr_cangmen_down(OPEN);
             num_down_open--;
             num_down_open--;
             #if TG_MODULE ==1
             #if TG_MODULE ==1
-            if(rt_pin_read(CTR_UPC_LIMIT)==0){
+            if(rt_pin_read(CTR_UPC_LIMIT)==1){
                 ctr_cangmen_down(OFF);
                 ctr_cangmen_down(OFF);
                 Beep_Tip(2000);
                 Beep_Tip(2000);
-                while(rt_pin_read(CTR_UPC_LIMIT)==0){
-                    ctr_cangmen_down(OPEN);
-                    rt_thread_delay(1000);
-                }
+                ctr_cangmen_down(OPEN);
+                Beep_Tip(2000);
                 num_down_open = 200;
                 num_down_open = 200;
                 device_status.ctr_down_motor = 1;
                 device_status.ctr_down_motor = 1;
             }
             }
@@ -1741,11 +1831,13 @@ void Check_ParamConfig(void)
         device_status.cul_time = 1;
         device_status.cul_time = 1;
         device_status.run_sta = 0;
         device_status.run_sta = 0;
         device_status.handle_bugger = 0;    //默认排虫
         device_status.handle_bugger = 0;    //默认排虫
+        device_status.work_mode = 0;
         sprintf(device_status.driver, "%s",VERSION_HK);
         sprintf(device_status.driver, "%s",VERSION_HK);
         sprintf(device_status.deviceId,"0");
         sprintf(device_status.deviceId,"0");
         rt_sprintf(device_status.tempture, "-15");
         rt_sprintf(device_status.tempture, "-15");
         rt_sprintf(device_status.humidity, "31");
         rt_sprintf(device_status.humidity, "31");
         rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
         rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
+        rt_sprintf(device_status.alarm_tg,"220000");
         ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave));  //
         ef_set_env_blob("iSave", &device_status.iSave, sizeof(device_status.iSave));  //
         ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
         ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
         ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
         ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));
@@ -1777,7 +1869,8 @@ void Check_ParamConfig(void)
         ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));      //
         ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));      //
         ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
         ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
         ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
         ef_set_env_blob("handle_bugger", &device_status.handle_bugger, sizeof(device_status.handle_bugger));
-
+        ef_set_env_blob("work_mode", &device_status.work_mode, sizeof(device_status.work_mode));
+        ef_set_env_blob("alarm_tg", &device_status.alarm_tg, sizeof(device_status.alarm_tg));
         LOG_I("SOFTWARE VERSION:%s",device_status.driver);
         LOG_I("SOFTWARE VERSION:%s",device_status.driver);
         LOG_I("Default paramconf is:");
         LOG_I("Default paramconf is:");
         LOG_I("stime:%d",device_status.iSave);
         LOG_I("stime:%d",device_status.iSave);
@@ -1790,6 +1883,7 @@ void Check_ParamConfig(void)
         LOG_I("jheat:%d",device_status.heatvalue);
         LOG_I("jheat:%d",device_status.heatvalue);
         LOG_I("thsp:%d", device_status.thsp);
         LOG_I("thsp:%d", device_status.thsp);
         LOG_I("passwd:%d",device_status.passWord);
         LOG_I("passwd:%d",device_status.passWord);
+        LOG_I("alarm_tg:%s",device_status.alarm_tg);
 
 
     }//从easyflash读取参数配置
     }//从easyflash读取参数配置
     else if (device_status.iSave==FLASH_FLAG) {
     else if (device_status.iSave==FLASH_FLAG) {
@@ -1835,6 +1929,8 @@ void Check_ParamConfig(void)
         ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL);              //供电类型
         ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL);              //供电类型
         ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL);                    //设备编码
         ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL);                    //设备编码
         ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL);     //排虫
         ef_get_env_blob("handle_bugger",&device_status.handle_bugger,sizeof(device_status.handle_bugger),NULL);     //排虫
+        ef_get_env_blob("work_mode",&device_status.work_mode,sizeof(device_status.work_mode),NULL);                 //工作模式
+        ef_get_env_blob("alarm_tg",&device_status.alarm_tg,sizeof(device_status.alarm_tg),NULL);                    //闹钟
         device_status.light_over_tim = device_status.sunBar * 3600;                                                 //光控计数
         device_status.light_over_tim = device_status.sunBar * 3600;                                                 //光控计数
         device_status.work_done = 0;
         device_status.work_done = 0;
         //工作完成标志位
         //工作完成标志位
@@ -1849,7 +1945,7 @@ void Check_ParamConfig(void)
              ResetParamDefault_DC();
              ResetParamDefault_DC();
         }
         }
         if(device_status.heatvalue==0) device_status.heatvalue = 100;
         if(device_status.heatvalue==0) device_status.heatvalue = 100;
-
+        if(device_status.work_mode>1) device_status.work_mode = 0;
         /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
         /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
         if(device_status.dtype!=7)
         if(device_status.dtype!=7)
         {
         {
@@ -1916,6 +2012,7 @@ void Check_ParamConfig(void)
         LOG_I("PowerType:%d",device_status.Power_Type);
         LOG_I("PowerType:%d",device_status.Power_Type);
         LOG_I("deviceId:%s",device_status.deviceId);
         LOG_I("deviceId:%s",device_status.deviceId);
         LOG_I("handle_bugger:%d",device_status.handle_bugger);
         LOG_I("handle_bugger:%d",device_status.handle_bugger);
+        LOG_I("alarm_tg:%s",device_status.alarm_tg);
     }
     }
     //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
     //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
     if(device_status.update_flag==1)
     if(device_status.update_flag==1)
@@ -1931,14 +2028,9 @@ void Check_ParamConfig(void)
         rt_sprintf(device_status.csq,"0");
         rt_sprintf(device_status.csq,"0");
         rt_sprintf(device_status.sim,"1");
         rt_sprintf(device_status.sim,"1");
         Sys_Motor_Task();
         Sys_Motor_Task();
-#ifdef RT_USING_ALARM
-        alarm_app_router();
-#endif
-#if MATCH_DEVICE== 0
+
         ctr_router(ON);
         ctr_router(ON);
-#else
-        ctr_router(OFF);
-#endif
+
         Hmi_Fresh();
         Hmi_Fresh();
 
 
         Control_clear();
         Control_clear();
@@ -1965,17 +2057,9 @@ void Check_ParamConfig(void)
             //超时时间为3分钟
             //超时时间为3分钟
             #if MATCH_DEVICE == 1
             #if MATCH_DEVICE == 1
             if(connect_num==60) //180
             if(connect_num==60) //180
-            {
-                device_status.timeSwitch = 1;
-                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);
-                #if 0
-                set_date(2020, 1, 1);
-                set_time(0, 0, 0);
-                #endif
-                break;
-            }
             #else
             #else
             if(connect_num==180) //180
             if(connect_num==180) //180
+            #endif
             {
             {
                 device_status.timeSwitch = 0;
                 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);
                 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);
@@ -1985,7 +2069,7 @@ void Check_ParamConfig(void)
                 #endif
                 #endif
                 break;
                 break;
             }
             }
-            #endif
+
         }
         }
         connect_num = 0;
         connect_num = 0;
         while(atoi(device_status.net)==0)
         while(atoi(device_status.net)==0)
@@ -1997,7 +2081,9 @@ void Check_ParamConfig(void)
             connect_num++;
             connect_num++;
             if(connect_num>5) break;
             if(connect_num>5) break;
         }
         }
-
+        #if MATCH_DEVICE == 1
+        device_status.timeSwitch = 1;
+        #endif
         DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
         DTU_Write("%s",makeJson_Warn("turnon", "device_stm32"));
         rt_thread_delay(1000);
         rt_thread_delay(1000);
         dtu_send_data_start();
         dtu_send_data_start();

+ 0 - 2
Application_cbd_apm32f1/applications/selfcheck.c

@@ -52,8 +52,6 @@ int selfcheck(uint8_t type)
     int current_,current_open = 0;
     int current_,current_open = 0;
     //删除workloop线程 防止自动运行干扰
     //删除workloop线程 防止自动运行干扰
     LOG_I("删除线程workloop:%d",thread_delete_workloop());
     LOG_I("删除线程workloop:%d",thread_delete_workloop());
-    //初始化硬件
-    HardWare_Init(0);
     //关闭上仓门
     //关闭上仓门
     ctr_cangmen_down(CLOSE);
     ctr_cangmen_down(CLOSE);
     //关闭下仓门
     //关闭下仓门

+ 4 - 0
Application_cbd_apm32f1/applications/sht30_collect.c

@@ -188,6 +188,7 @@ static void adc_collect_thread_entry(void *parameter)
             device_status.temp_status = 0;
             device_status.temp_status = 0;
         }
         }
 #endif
 #endif
+#if YUKONG == 1
         //雨控
         //雨控
         if(rain_value>250&&device_status.selfcheck_ws==0)
         if(rain_value>250&&device_status.selfcheck_ws==0)
         {
         {
@@ -214,6 +215,7 @@ static void adc_collect_thread_entry(void *parameter)
                 device_status.rain_status = 0;
                 device_status.rain_status = 0;
             }
             }
         }
         }
+#endif
         if(log_cnt==50){   //每5s打印
         if(log_cnt==50){   //每5s打印
             log_cnt = 0;
             log_cnt = 0;
             LOG_I("光控计数:light:%d-night:%d",checklightnum,checknightnum);
             LOG_I("光控计数:light:%d-night:%d",checklightnum,checknightnum);
@@ -260,6 +262,7 @@ static void Power_ReadCheck(void *parameter)
         sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current()/100*2.5))+20.0);
         sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current()/100*2.5))+20.0);
         #endif
         #endif
         //LOG_I("负载电流:%s,加热电流:%s",device_status.power,device_status.heat_power);
         //LOG_I("负载电流:%s,加热电流:%s",device_status.power,device_status.heat_power);
+#if QIANYA == 1
         if (Read_Real_Voltage()/100<12)
         if (Read_Real_Voltage()/100<12)
         {
         {
             //关闭外设
             //关闭外设
@@ -285,6 +288,7 @@ static void Power_ReadCheck(void *parameter)
         #endif
         #endif
             ctr_photo(ON);                //打开相机供电
             ctr_photo(ON);                //打开相机供电
         }
         }
+#endif
         //
         //
         if(device_status.dtype==3)
         if(device_status.dtype==3)
         {
         {

+ 3 - 2
Application_cbd_apm32f1/applications/sys_monitor.c

@@ -25,7 +25,7 @@ System_stats_t system_status;
 
 
 static void sys_monitor_thread_entry(void *parameter)
 static void sys_monitor_thread_entry(void *parameter)
 {
 {
-    uint8_t sec_t;
+    uint8_t sec_t = 0;
     system_status.lamp_start_time = 0;
     system_status.lamp_start_time = 0;
     system_status.heat_start_time = 0;
     system_status.heat_start_time = 0;
     while(1)
     while(1)
@@ -67,7 +67,8 @@ static void sys_monitor_thread_entry(void *parameter)
 
 
             LOG_D("灯管累计运行:%d S",system_status.lamp_running_time/RT_TICK_PER_SECOND);
             LOG_D("灯管累计运行:%d S",system_status.lamp_running_time/RT_TICK_PER_SECOND);
             LOG_D("加热累计运行:%d S",system_status.heater_running_time/RT_TICK_PER_SECOND);
             LOG_D("加热累计运行:%d S",system_status.heater_running_time/RT_TICK_PER_SECOND);
-
+            LOG_D("雨控触发值:%d",system_status.rain_value);
+            LOG_D("雨控触发次数:%d",system_status.rain_control_triggers);
         }
         }
     }
     }
 }
 }

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

@@ -88,7 +88,9 @@ static const ef_env default_env_set[] = {
         {"Power_Type","0"},        //供电类型
         {"Power_Type","0"},        //供电类型
         {"deviceId","0"},          //BDH设备编码
         {"deviceId","0"},          //BDH设备编码
         {"handle_bugger","0"},     //虫子处理,收虫,排虫
         {"handle_bugger","0"},     //虫子处理,收虫,排虫
-        {"heat_sw","0"}
+        {"heat_sw","0"},
+        {"workmode","0"},           //模式,0正常 1-预制
+        {"alarm_tg","220000"}
 };
 };
 static char log_buf[RT_CONSOLEBUF_SIZE];
 static char log_buf[RT_CONSOLEBUF_SIZE];
 static struct rt_semaphore env_cache_lock;
 static struct rt_semaphore env_cache_lock;

+ 4 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,7 @@
+# 2026-05-14 更新说明
+	"2.8.4(TG)"
+	1. B模式下,根据工作状态字段开关灯管
+	2. 解决屏幕上网线接入状态闪烁问题
 # 2026-04-23 更新说明
 # 2026-04-23 更新说明
 	"2.7.4(TG)"
 	"2.7.4(TG)"
 	"2.36.4(2000W)"
 	"2.36.4(2000W)"