From c8240d55741f0ed86099a0a8c616f4fc68372134 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期四, 25 十二月 2025 10:17:55 +0800
Subject: [PATCH] OTA功能测试完成,4G超时时间异常,出现4G中断情况,等杜工修改。

---
 STM32H743/APL/PathTest.c |   48 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/STM32H743/APL/PathTest.c b/STM32H743/APL/PathTest.c
index 4a8182a..c4329c6 100644
--- a/STM32H743/APL/PathTest.c
+++ b/STM32H743/APL/PathTest.c
@@ -421,12 +421,35 @@
 void OTATest_Poll(void)
 {
     HIDO_UINT32 current_tick = HIDO_TimerGetTick();
+    E_OTAState ota_state = OTA_GetState();
     
     // OTA妯″潡闇�瑕佸懆鏈熻皟鐢紙澶勭悊瑙e瘑浠诲姟锛�
     OTA_Poll();
     
-    // 闄愬埗妫�鏌ラ鐜�
-    if (current_tick - s_ota_test_ctx.last_check_tick < TEST_CHECK_INTERVAL) {
+    // 瓒呮椂妫�娴嬶細濡傛灉鐘舵�佸崱鍦ㄤ腑闂寸姸鎬佽秴杩囦竴瀹氭椂闂达紝瑙﹀彂澶辫触
+    static HIDO_UINT32 s_u32StateStartTick = 0;
+    static E_OTATestState s_eLastState = OTA_TEST_STATE_IDLE;
+    if (s_ota_test_ctx.state != s_eLastState) {
+        s_u32StateStartTick = current_tick;
+        s_eLastState = s_ota_test_ctx.state;
+    }
+    
+    // 妫�鏌ョ姸鎬佽秴鏃讹紙闄や簡IDLE銆丆OMPLETE銆丗AILED锛�
+    if (s_ota_test_ctx.state != OTA_TEST_STATE_IDLE && 
+        s_ota_test_ctx.state != OTA_TEST_STATE_COMPLETE &&
+        s_ota_test_ctx.state != OTA_TEST_STATE_FAILED) {
+        if (current_tick - s_u32StateStartTick > 60000) {  // 60绉掕秴鏃�
+            HIDO_Debug("[OTATest] State timeout! State=%d, OTAState=%d\r\n", 
+                       s_ota_test_ctx.state, ota_state);
+            s_ota_test_ctx.state = OTA_TEST_STATE_FAILED;
+        }
+    }
+    
+    // 闄愬埗妫�鏌ラ鐜囷紙浣嗕笅杞藉畬鎴愭椂绔嬪嵆妫�鏌ワ級
+    HIDO_BOOL bForceCheck = (s_ota_test_ctx.state == OTA_TEST_STATE_DOWNLOADING && 
+                             ota_state == OTA_STATE_DOWNLOAD_COMPLETE);
+    
+    if (!bForceCheck && (current_tick - s_ota_test_ctx.last_check_tick < TEST_CHECK_INTERVAL)) {
         return;
     }
     s_ota_test_ctx.last_check_tick = current_tick;
@@ -488,7 +511,7 @@
  */
 static void OTATest_StartDownload(void)
 {
-    const HIDO_CHAR *url = "http://123.57.87.125:7001/hfs/STM32H743.Bin";
+    const HIDO_CHAR *url = "http://39.99.43.227:8866/api/file/download/STM32H743.Bin";
     HIDO_INT32 ret;
     
     HIDO_Debug("[OTATest] ===== Starting OTA Firmware Download =====\r\n");
@@ -547,12 +570,13 @@
 static void OTATest_CheckDecryptStatus(void)
 {
     E_OTAState ota_state = OTA_GetState();
-    HIDO_UINT8 progress = OTA_GetProgress();
     
-    // 杩涘害鍙樺寲鏃舵墦鍗�
-    if (progress != s_ota_test_ctx.last_progress && progress % 10 == 0) {
-        HIDO_Debug("[OTATest] Decrypt progress: %u%%\r\n", progress);
-        s_ota_test_ctx.last_progress = progress;
+    // Check for retry (state went back to downloading or idle)
+    if (ota_state == OTA_STATE_DOWNLOADING || ota_state == OTA_STATE_IDLE) {
+         HIDO_Debug("[OTATest] OTA retry detected. Switching back to DOWNLOADING state.\r\n");
+         s_ota_test_ctx.state = OTA_TEST_STATE_DOWNLOADING;
+         s_ota_test_ctx.last_progress = 0;
+         return;
     }
     
     if (ota_state == OTA_STATE_DECRYPT_COMPLETE) {
@@ -580,6 +604,14 @@
 {
     E_OTAState ota_state = OTA_GetState();
     
+    // Check for retry (state went back to downloading or idle)
+    if (ota_state == OTA_STATE_DOWNLOADING || ota_state == OTA_STATE_IDLE) {
+         HIDO_Debug("[OTATest] OTA retry detected. Switching back to DOWNLOADING state.\r\n");
+         s_ota_test_ctx.state = OTA_TEST_STATE_DOWNLOADING;
+         s_ota_test_ctx.last_progress = 0;
+         return;
+    }
+    
     if (ota_state == OTA_STATE_VERIFY_SUCCESS) {
         ST_OTAInfo info;
         OTA_GetInfo(&info);

--
Gitblit v1.10.0