zhunk 5 miesięcy temu
rodzic
commit
6f3fc66107

+ 31 - 12
Application_cbd_apm32f1/applications/control.c

@@ -1121,18 +1121,43 @@ void ctr_TG_Clear(uint16_t clear_timeout)
     HMI_WRITE("cangWei.rotateFlag.val=%d",0);
     HMI_WRITE("sysTest.switchClear.val=%d",0);
 }
-//DTU,RTU供电
+// 全局静态变量,保存上次关闭的 tick
+static rt_uint32_t s_last_off_tick = 0;
+
 void ctr_RTU_DTU(uint8_t status_rtu)
 {
+    // 1. 先设置引脚模式(只需要设置一次即可,放这里也兼容多次调用)
     rt_pin_mode(RTU_DTU, PIN_MODE_OUTPUT);
-    if(status_rtu==ON)
+
+    if (status_rtu == ON)
     {
-        rt_pin_write(RTU_DTU,ON);
+        // 开机逻辑:必须满足冷却时间才能开机
+        rt_uint32_t current_tick = rt_tick_get();
+        rt_uint32_t cool_ticks = 30 * RT_TICK_PER_SECOND; // 30秒
+        if (s_last_off_tick != 0)
+        {
+            rt_uint32_t diff_tick = current_tick - s_last_off_tick;
+            if (diff_tick < cool_ticks)
+            {
+                // 未冷却完成,计算剩余时间
+                rt_uint32_t wait_ticks = cool_ticks - diff_tick;
+                rt_uint32_t wait_ms   = wait_ticks * (1000 / RT_TICK_PER_SECOND);
+                LOG_W("RTU电源关闭后需等待 %d ms 冷却, 禁止开机", wait_ms);
+                // 阻塞等待冷却(如果不允许阻塞,就直接return,不要delay)
+                rt_thread_delay(wait_ticks);
+            }
+        }
+        // 冷却完成,执行开机
+        rt_pin_write(RTU_DTU, ON);
+        s_last_off_tick = 0; // 清除关机时间
+        LOG_W("RTU电源启动!!!");
     }
     else
     {
-        LOG_W("RTU电源复位!!!");
-        rt_pin_write(RTU_DTU,OFF);
+        // 关机逻辑:记录关机时刻tick
+        rt_pin_write(RTU_DTU, OFF);
+        s_last_off_tick = rt_tick_get();
+        LOG_W("RTU电源关闭:%d",s_last_off_tick);
     }
 }
 //海康拍照
@@ -1506,7 +1531,7 @@ void WorkCheck(void)
         else // 光控模式
         {
             LOG_I("光控定时模式!");
-            if(device_status.sun_status == 0 && device_status.light_over_tim != 0)
+            if(device_status.sun_status == 0 && device_status.light_over_tim > 0)
             {
                 device_status.light_over_tim--;
                 light_timeout = 3600;  // 重置超时计数器
@@ -1532,12 +1557,6 @@ void WorkCheck(void)
                 if(light_timeout == 0) {
                     device_status.light_over_tim = 0;
                     light_timeout = 3600;  // 重置防止负数
-                }
-
-                // 白天且倒计时结束:重置夜晚时长
-                if(device_status.light_over_tim == 0 &&
-                   device_status.sun_status == 1)
-                {
                     device_status.light_over_tim = device_status.sunBar * 3600;
                 }
             }

+ 7 - 5
Application_cbd_apm32f1/applications/control.h

@@ -24,9 +24,9 @@
 #define TG_MODULE        1             //推杆电机结构模块化控制
 #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
@@ -44,9 +44,9 @@
     #define VERSION_HK_2000W    "2.36.4(2000W)"         //4.0水稻
     #else
     #if MATCH_DEVICE == 1
-    #define VERSION_HK_2000W    "3.0.4(TG)"             //推杆结构比赛设备
+    #define VERSION_HK_2000W    "3.2.4(TG)"             //推杆结构比赛设备
     #else
-    #define VERSION_HK_2000W    "2.9.4(TG110)"             //推杆结构
+    #define VERSION_HK_2000W    "2.11.4(TG111)"             //推杆结构
     #endif
     #endif
 #endif
@@ -143,6 +143,8 @@ typedef struct  _packed
     uint8_t debug_ws;        //调试开关,把调试信息上报到MQTT
     uint8_t work_mode;       //工作模式:0-正常   1-预制
     uint8_t upan_sta;        //0:正常 1-未连接
+    uint8_t rtu_isboot;
+    uint8_t mock_uart2_timer_flag;
     uint16_t upan_photo_num;
     uint16_t dattim;         //数据上传间隔
     uint16_t shake_sec;      //震动时间

+ 13 - 7
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -464,8 +464,7 @@ static void dtu_thread_entry_send(void *parameter)
                 if(atoi(device_status.voltage)>12&&device_status.power_status==0)      //电压正常
                 {
                     device_status.power_status = 1;
-                    //重启
-                    rt_hw_cpu_reset();
+                    ctr_RTU_DTU(ON);
                 }
                 if(device_status.work_status==1&&device_status.num_updata%10==0&&atoi(device_status.power)>20)    //每过10S把电流值存入数组,连续10条数据的电流值大于400mA判断为正常
                 {
@@ -1874,14 +1873,21 @@ int parseDtu(char *json_string)
               //json rpc服务端响应
               if(RESULT!=NULL&&RESULT->type==cJSON_String)
               {
-                  if(strcmp(RESULT->valuestring,"success")==0){
-                      if(device_status.C01==100){
-                          device_status.C01 = 0;
-                          Stop_timer_Uart2();
+                  if(RESULT!=NULL && RESULT->type==cJSON_Object){
+                      cJSON* message = cJSON_GetObjectItem(RESULT, "message");
+                      if(message!=NULL && message->type==cJSON_String){
+                          if(strcmp(message->valuestring,"success")==0){
+                              device_status.rtu_isboot = 0;
+                          }
+                      }else{
+                          HMI_WRITE("menu.result.txt=\"%s\"",RESULT->valuestring);
                       }
-                  }else{
+                  }
+                  if(RESULT!=NULL && RESULT->type==cJSON_String){
                       HMI_WRITE("menu.result.txt=\"%s\"",RESULT->valuestring);
                   }
+
+
               }
           }
           if(mqtt_data_record_TF_Max!=NULL)

+ 24 - 45
Application_cbd_apm32f1/applications/hmi.c

@@ -326,36 +326,14 @@ static void Hmi_thread_entry(void *parameter)
     }
 }
 /*******************************************************************************************/
-static void t_uart2_callback(void *parameter)
-{
-    HMI_WRITE("sysSet.va0.txt=\"指令超时,请重试...\"");
-    LOG_E("t_uart2_callback");
-    uart2_timeout_flag = RT_TRUE;
-}
-
-
 void Start_timer_Uart2(void)
 {
-    if(timer_uart2!=RT_NULL)
-    {
-        rt_timer_start(timer_uart2);
-    }
-    else
-    {
-        LOG_E("timer_uart2 start Failed!");
-    }
+    device_status.mock_uart2_timer_flag = 1;
 }
 
 void Stop_timer_Uart2(void)
 {
-    if(timer_uart2!=RT_NULL)
-    {
-        rt_timer_stop(timer_uart2);
-    }
-    else
-    {
-        LOG_E("timer_uart2 stop Failed!");
-    }
+    device_status.mock_uart2_timer_flag = 0;
 }
 
 static void refresh_hmi_Component(struct tm tm)
@@ -889,7 +867,6 @@ static void HMI_Decode(void)
             return;
         }
         // ======================================================================
-
         // 格式正确才赋值
         LOG_I("设置闹钟时间:%s",var);
         rt_sprintf(device_status.alarm_tg, "%s", var);
@@ -1564,7 +1541,8 @@ static void Ctr_Mortor_entry(void* parameter)
    rt_uint16_t num_down_open = 200;  //     下仓门打开时间
    rt_uint16_t num_down_close = 200;  //    下仓门关闭时间
    rt_int16_t photo_led_sec = 900;  //55S
-
+   static rt_uint16_t rtu_isboot_cnt = 0;
+   static rt_uint16_t mock_uart2_timer_cnt = 0;
    static rt_uint16_t route_off_t = 0;
    device_status.route_off_t = 0;
 
@@ -1580,7 +1558,7 @@ static void Ctr_Mortor_entry(void* parameter)
         {
             char *rep = makeJsonRpc2_0("reboot",NULL, 1);
             if(rep){
-                device_status.C01 = 100;
+                device_status.rtu_isboot = 1;
                 DTU_Write(rep);
                 //启动超时定时器
                 Start_timer_Uart2();
@@ -1588,11 +1566,25 @@ static void Ctr_Mortor_entry(void* parameter)
             }
             rt_thread_delay(1000);
         }
-        if(uart2_timeout_flag == RT_TRUE){
-            uart2_timeout_flag = RT_FALSE;
-            ctr_RTU_DTU(OFF);
-            rt_thread_delay(1000*30);
-            ctr_RTU_DTU(ON);
+        if(device_status.rtu_isboot == 1){
+            rtu_isboot_cnt++;
+            if(rtu_isboot_cnt>=200)
+            {
+                device_status.rtu_isboot = 0;
+                rtu_isboot_cnt = 0;
+                ctr_RTU_DTU(OFF);
+                rt_thread_delay(1000*31);
+                ctr_RTU_DTU(ON);
+            }
+        }else{
+            rtu_isboot_cnt = 0;
+        }
+        if(device_status.mock_uart2_timer_flag==1){
+            mock_uart2_timer_cnt++;
+            if(mock_uart2_timer_cnt>=200){
+                mock_uart2_timer_cnt = 0;
+                device_status.mock_uart2_timer_flag = 0;
+            }
         }
         #endif
         if(device_status.ctr_up_motor==1)
@@ -1767,12 +1759,6 @@ int Hmi_Fresh(void)
     {
        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;
 }
 void Check_ParamConfig(void)
@@ -2029,26 +2015,19 @@ void Check_ParamConfig(void)
         rt_sprintf(device_status.csq,"0");
         rt_sprintf(device_status.sim,"1");
         Sys_Motor_Task();
-
         ctr_router(ON);
-
         Hmi_Fresh();
-
         Control_clear();
         Control_Check();    //自检
-
         dtu_data_play();
         sht30_collect();
 #if SENSOR_EN==1
         mb_master_samlpe();
 #endif
-
         uint16_t connect_num=0;
         //等待联网,
         while(atoi(device_status.net)==1)
         {
-            if(Read_Real_Voltage()/100>5&&device_status.power_status==0)
-                ctr_RTU_DTU(ON);
             char *readinfo =  makeJson_ReadInfo();
             DTU_Write("%s",readinfo);
             rt_free(readinfo);

+ 1 - 1
Application_cbd_apm32f1/packages/ota_downloader-v1.0.0/tools/ota_packager/rt_ota_packaging_tool.exe.config

@@ -6,5 +6,5 @@
   <runtime>
     <enforceFIPSPolicy enabled="false" />
   </runtime>
-  <configs SELEFILE="" SAVEFILE="" COMPRESS="0" CRYPT="0" KEY="" IV="" NAME="" VERSION="" />
+  <configs SELEFILE="D:\RT-ThreadStudio\workspace\IOT_CBD_BZY_CTRL\Application_cbd_apm32f1\Debug\rtthread.bin" SAVEFILE="D:\RT-ThreadStudio\workspace\IOT_CBD_BZY_CTRL\Application_cbd_apm32f1\Debug\rtthread.rbl" COMPRESS="0" CRYPT="0" KEY="" IV="" NAME="app" VERSION="1.68.*" />
 </configuration>

+ 1 - 1
Application_cbd_apm32f1/packages/syswatch-latest/src/syswatch.c

@@ -396,7 +396,7 @@ static void syswatch_thread_entry(void *parameter)
         time_t now;
         time(&now);
         alarm_new =*localtime(&now);
-        if((alarm_new.tm_hour)==8&&(alarm_new.tm_min==20)&&(alarm_new.tm_sec==0))
+        if((alarm_new.tm_hour)==8&&(alarm_new.tm_min==10)&&(alarm_new.tm_sec==0))
         {
             #if ROBOT_EN == 0 && DINGZHI_0722 == 0
             rt_hw_cpu_reset();

+ 16 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,19 @@
+# 2026-06-03 更新说明
+    #if MATCH_DEVICE == 1
+    #define VERSION_HK_2000W    "3.2.4(TG)"             //推杆结构比赛设备
+    #else
+    #define VERSION_HK_2000W    "2.11.4(TG111)"             //推杆结构
+    #endif
+	1、MCU定时重启时间修改为8:10在RTU之前,这样出现参数异常时,RTU这时正常运行可以恢复参数;
+# 2026-06-02 更新说明
+    #if MATCH_DEVICE == 1
+    #define VERSION_HK_2000W    "3.1.4(TG)"             //推杆结构比赛设备
+    #else
+    #define VERSION_HK_2000W    "2.10.4(TG111)"             //推杆结构
+    #endif
+	1、修复定时重启RTU软重启后继续触发硬重启,有概率导致RTU无法启动;
+	2、删除uart2_timer,改用线程超时;
+	3、RTU电源控制函数增加间隔限制30S;
 # 2026-05-29 更新说明
 	"2.9.4(TG110)"
 	1. 增加远程设置触发时间;