Kaynağa Gözat

2.39.000(2000W)

zhunk 5 ay önce
ebeveyn
işleme
71056830fd

+ 65 - 10
Application_cbd_apm32f1/applications/control.c

@@ -1962,9 +1962,21 @@ static void Work_status_thread_entry(void *parameter)
         WorkCheck();
      }
 }
+//指令
+//
+
 /*入口函数-工作流程*/
 static void Work_Loop_thread_entry(void *parameter)
 {
+    const uint8_t open_Led[] = {0x02,0x06,0x00,0x32,0x00,0x01,0xE9,0xF6};   //02 06 00 32 00 01 E9 F6
+    const uint8_t close_Led[] = {0x02,0x06,0x00,0x32,0x00,0x00,0x28,0x36};   //02 06 00 32 00 01 E9 F6
+    const uint8_t motor1_Forword[] = {0x02,0x06,0x00,0x00,0x00,0x01,0x48,0x39};   //02 06 00 00 00 01 48 39
+    const uint8_t motor1_Backward[] = {0x02,0x06,0x00,0x00,0x00,0x02,0x08,0x38};   //02 06 00 00 00 01 48 39
+    const uint8_t motor1_Stop[] = {0x02,0x06,0x00,0x00,0x00,0x00,0x89,0xF9};   //02 06 00 00 00 01 48 39
+    const uint8_t motor2_Forword[] = {0x02,0x06,0x00,0x00,0x00,0x10,0x88,0x35};   //02 06 00 00 00 01 48 39
+    const uint8_t motor2_Backward[] = {0x02,0x06,0x00,0x00,0x00,0x20,0x88,0x31};   //02 06 00 00 00 01 48 39
+    const uint8_t motor2_Stop[] = {0x02,0x06,0x00,0x00,0x00,0x00,0x89,0xF9};   //02 06 00 00 00 01 48 39
+    const uint8_t get_status[] = {0x02,0x03,0x00,0x00,0x00,0x01,0x84,0x39};     //02 03 02 00 00 FC 44
     rt_thread_delay(1000);
     ResetInit();
     rt_pin_mode(CTR_UPC_LIMIT, PIN_MODE_INPUT);
@@ -2002,18 +2014,61 @@ static void Work_Loop_thread_entry(void *parameter)
             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++){
+                if(device_status.motor_active==0){
+                    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(1000);
+                    device_status.motor_active=1;
+                    ef_set_env_blob("motor_active", &device_status.motor_active, sizeof(device_status.motor_active));
+                }else{
+                    /* 发送 Modbus RTU 获取电机状态 */
+                    uart5_rx_flag = 0;   /* 先清除上次的接收标志 */
+                    Uart5_Write_Bin(get_status, sizeof(get_status));   /* 必须用_Bin,%s会截断0x00字节 */
+
+                    /* 等待回复,超时2秒上报预警 */
+                    rt_tick_t status_start = rt_tick_get();
+                    uint8_t status_timeout = 1;  /* 默认超时 */
+                    while(rt_tick_get() - status_start < 2 * RT_TICK_PER_SECOND) {
+                        if(uart5_rx_flag) {
+                            status_timeout = 0;   /* 收到回复 */
+                            LOG_I("电机状态查询有回复");
+                            break;
+                        }
+                        rt_thread_delay(50);   /* 每50ms轮询一次 */
+                    }
+                    if(status_timeout) {
+                        LOG_W("电机状态查询超时,发送预警!");
+                        char *warn = makeJson_Warn("485_motor_timeout", "get_status");
+                        if(warn) {
+                            DTU_Write("%s", warn);
+                            rt_free(warn);
+                        }
+                    }
+                    uart5_rx_flag = 0;   /* 重置标志,供下次使用 */
+
+                    Uart5_Write_Bin(motor1_Forword, sizeof(motor1_Forword));   //推杆打开
+                    rt_thread_delay(20000);
+                    Uart5_Write_Bin(motor2_Forword, sizeof(motor2_Forword));   //震动
+                    for(uint8_t i = 0; i < 30; i++){
+                        rt_thread_delay(1000);
+                        LOG_I("等待震动完成:%d",i);
+                    }
+                    Uart5_Write_Bin(motor2_Stop, sizeof(motor2_Stop));   //关闭震动
+                    rt_thread_delay(2000);
+                    Uart5_Write_Bin(motor1_Backward, sizeof(motor1_Backward));   //推杆关闭
                     rt_thread_delay(1000);
-                    LOG_I("等待震动完成:%d",i);
+                    device_status.motor_active=0;
+                    ef_set_env_blob("motor_active", &device_status.motor_active, sizeof(device_status.motor_active));
                 }
-                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);

+ 6 - 5
Application_cbd_apm32f1/applications/control.h

@@ -18,15 +18,15 @@
 
 #define LAMP_EN          0             //李新3灯管:0关闭,1打开
 #define PCB_V1           0             //1-旧PCB,0-新PCB(模块化)
-#define MATCH_DEVICE     0             //比赛设备1-开启 0-关闭
+#define MATCH_DEVICE     1             //比赛设备1-开启 0-关闭
 #define SENSOR_EN        0             //温湿度:0关闭,1打开
 #define UART_TEST_EN     0             ///串口测试0-关闭,1-启用
 #define TG_MODULE        0             //推杆电机结构模块化控制
 #define DINGZHI_0722     0             //控制一个电机每天12点20工作12秒
 #define QINGSAO_IO       1             //调整清扫顺序20250801
-#define WENKONG          1             //温控功能1-开启 0-关闭
-#define YUKONG           1             //雨控功能1-开启 0-关闭
-#define QIANYA           1             //欠压功能1-开启 0-关闭
+#define WENKONG          0             //温控功能1-开启 0-关闭
+#define YUKONG           0             //雨控功能1-开启 0-关闭
+#define QIANYA           0             //欠压功能1-开启 0-关闭
 
 
 #if MATCH_DEVICE == 1
@@ -41,7 +41,7 @@
 #else
     #define VERSION_HK          "2.39.41(HK)"            //4.0海康-1200W
     #if TG_MODULE == 0
-    #define VERSION_HK_2000W    "2.39.4(2000W)"         //4.0水稻
+    #define VERSION_HK_2000W    "2.39.000(2000W)"         //4.0水稻
     #else
     #if MATCH_DEVICE == 1
     #define VERSION_HK_2000W    "3.3.4(TG)"             //推杆结构比赛设备
@@ -145,6 +145,7 @@ typedef struct  _packed
     uint8_t upan_sta;        //0:正常 1-未连接
     uint8_t rtu_isboot;
     uint8_t mock_uart2_timer_flag;
+    uint8_t motor_active;
     uint16_t upan_photo_num;
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间

+ 16 - 3
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -200,7 +200,7 @@ static int DTU_uart5_init(void)
 
 
 
-/*数据发送*/
+/* 数据发送*/
 void Uart5_Write(char *fmt, ...)
 {
     va_list ap;
@@ -216,6 +216,13 @@ void Uart5_Write(char *fmt, ...)
     LOG_D("Uart5_Write:%s",dtu_str);
 }
 
+/* 发送二进制数据(Modbus RTU 等),vsnprintf遇到0x00会截断,不能用%s */
+void Uart5_Write_Bin(const uint8_t *data, uint16_t len)
+{
+    if(data == RT_NULL || len == 0) return;
+    rt_device_write(serial_485, 0, data, len);
+}
+
 
 
 /*数据发送*/
@@ -254,8 +261,11 @@ void dtu_uart2_reinit_rx(void)
     LOG_I("dtu_uart2 rx_indicate re-registered");
 }
 
+volatile uint8_t uart5_rx_flag = 0;   /* 485收到数据标志,用于超时检测 */
+
 static rt_err_t uart5_input(rt_device_t dev, rt_size_t size)
 {
+    uart5_rx_flag = 1;                 /* 只要有数据到达就置标志 */
     rt_sem_release(&rx5_sem);
     return RT_EOK;
 }
@@ -579,7 +589,11 @@ int dtu_data_play(void)
 {
     lwjson_stream_init(&lwparser, NULL);
     DTU_uart2_init();
+#if MATCH_DEVICE == 1
     DTU_uart5_init();
+    rt_sem_init(&rx5_sem, "rx5_sem", 0, RT_IPC_FLAG_FIFO);
+    rt_device_set_rx_indicate(serial_485, uart5_input);
+#endif
     rt_err_t rm_dtu_result = rt_mutex_init(&dtu_write_mutex, "dtu_mtx", RT_IPC_FLAG_FIFO);
     if (rm_dtu_result != RT_EOK)
     {
@@ -587,10 +601,9 @@ int dtu_data_play(void)
     }
     //初始化消息队列
     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(serial_485, uart5_input);
     /*创建线程-指令发送*/
     dtu_send_data = rt_thread_create("DTU_Uart_thread_send",
                                     dtu_thread_entry_send,RT_NULL,

+ 2 - 0
Application_cbd_apm32f1/applications/dtu_uart2.h

@@ -62,6 +62,8 @@ 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"}}
 void DTU_Write(char *fmt, ...);
 void Uart5_Write(char *fmt, ...);
+void Uart5_Write_Bin(const uint8_t *data, uint16_t len);
+extern volatile uint8_t uart5_rx_flag;   /* 485收到数据标志 */
 int dtu_data_play(void);
 int parseDtu(char *json_string);
 char *makeJson(void);

+ 28 - 3
Application_cbd_apm32f1/applications/hmi.c

@@ -615,21 +615,45 @@ static void HMI_Decode(void)
         LOG_I("推杆打开测试!!!");
         ctr_Cold(ON);
     }
+    else if (strstr(rx_buffer,"putTest.switchCc1=1")!=NULL)
+    {
+        LOG_I("推杆2打开测试!!!");
+        const uint8_t motor1_Forword[] = {0x02,0x06,0x00,0x00,0x00,0x01,0x48,0x39};   //02 06 00 00 00 01 48 39
+        Uart5_Write_Bin(motor1_Forword, sizeof(motor1_Forword));
+    }
     else if (strstr(rx_buffer,"putTest.switchCc=0")!=NULL)
     {
         LOG_I("推杆关闭测试!!!");
         ctr_Cold(OFF);
     }
+    else if (strstr(rx_buffer,"putTest.switchCc1=0")!=NULL)
+    {
+        LOG_I("推杆2关闭测试!!!");
+        const uint8_t motor1_Backward[] = {0x02,0x06,0x00,0x00,0x00,0x02,0x08,0x38};   //02 06 00 00 00 01 48 39
+        Uart5_Write_Bin(motor1_Backward, sizeof(motor1_Backward));
+    }
     else if (strstr(rx_buffer,"putTest.shakeCc=1")!=NULL)
     {
         LOG_I("震动电机打开测试!!!");
         ctr_Collect_Fan(ON);
     }
+    else if (strstr(rx_buffer,"putTest.shakeCc1=1")!=NULL)
+    {
+        LOG_I("震动电机1打开测试!!!");
+        const uint8_t motor2_Forword[] = {0x02,0x06,0x00,0x00,0x00,0x10,0x88,0x35};   //02 06 00 00 00 01 48 39
+        Uart5_Write_Bin(motor2_Forword, sizeof(motor2_Forword));
+    }
     else if (strstr(rx_buffer,"putTest.shakeCc=0")!=NULL)
     {
         LOG_I("震动电机关闭测试!!!");
         ctr_Collect_Fan(OFF);
     }
+    else if (strstr(rx_buffer,"putTest.shakeCc1=0")!=NULL)
+    {
+        LOG_I("震动电机1关闭测试!!!");
+        const uint8_t motor2_Stop[] = {0x02,0x06,0x00,0x00,0x00,0x00,0x89,0xF9};   //02 06 00 00 00 01 48 39
+        Uart5_Write_Bin(motor2_Stop, sizeof(motor2_Stop));
+    }
     else if (strstr(rx_buffer,"turnzp")!=NULL) {
         LOG_W("转仓!");
         device_status.clear_status=2;
@@ -1797,7 +1821,7 @@ void Check_ParamConfig(void)
         device_status.collecting_eh1 = 10;
         device_status.collecting_sh2 = 14;
         device_status.collecting_eh2 = 16;
-        device_status.cold_sw = 0;
+        device_status.motor_active = 0;
         device_status.heat_sw = 0;
         device_status.cul_time = 1;
         device_status.run_sta = 0;
@@ -1831,7 +1855,7 @@ void Check_ParamConfig(void)
         ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1));        //上传平台
 
         ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time));     //采集时间
-        ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw));        //制冷开关
+        ef_set_env_blob("motor_active",&device_status.motor_active,sizeof(device_status.motor_active));        //制冷开关
         ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw));        //加热开关
         ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1));        //风机开关
         ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1));        //采集时间
@@ -1890,7 +1914,7 @@ void Check_ParamConfig(void)
         ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL);                    //平台地址
         /*孢子仪*/
         ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL);                    //培养时间
-        ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL);                       //制冷开关
+        ef_get_env_blob("motor_active",&device_status.motor_active,sizeof(device_status.motor_active),NULL);        //电机
         ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL);                       //加热开关
         ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL);  //采集开始1
         ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL);  //采集结束1
@@ -1984,6 +2008,7 @@ void Check_ParamConfig(void)
         LOG_I("deviceId:%s",device_status.deviceId);
         LOG_I("handle_bugger:%d",device_status.handle_bugger);
         LOG_I("alarm_tg:%s",device_status.alarm_tg);
+        LOG_I("motor_active:%d",device_status.motor_active);
     }
     //RTC时间判断,如果当前年份小于2020,提示需要设置时间,切换为光控
     if(device_status.update_flag==1)

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

@@ -78,7 +78,7 @@ static const ef_env default_env_set[] = {
         {"json_w_platform","0"},
         {"run_sta","0"},    //孢子仪,运行状态
         {"cul_time","1"},   //孢子仪,培养时间
-        {"cold_sw","0"},           //
+        {"motor_active","0"},           //
         {"wind_sw","0"},           //
         {"run_sta","0"},           //
         {"collecting_sh1","0"},    //

+ 3 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,6 @@
+# 2026-06-10 更新说明
+	#define VERSION_HK_2000W    "2.40.000()"         //4.0水稻
+	1、增加485多通道电机驱动模块适配,用于控制地笼上的接虫盒;
 # 2026-06-08 更新说明
 	#define VERSION_HK_2000W    "2.39.4(2000W-111)"         //4.0水稻
 	1、震动功能优化,100ms间隔停顿1000ms;