From d487f58c6be4ed22f735d12861b59b85c3a924b9 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期六, 20 十二月 2025 21:53:25 +0800
Subject: [PATCH] HTTP下载路径文件成功,解析路径文件成功,CRC用的软件,硬件解析不对。准备改BOOT

---
 STM32H743/APL/TCPClient.c |   83 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 73 insertions(+), 10 deletions(-)

diff --git a/STM32H743/APL/TCPClient.c b/STM32H743/APL/TCPClient.c
index c81ce15..ea43844 100644
--- a/STM32H743/APL/TCPClient.c
+++ b/STM32H743/APL/TCPClient.c
@@ -15,11 +15,11 @@
 #include "string.h"
 #include "HIDO_Timer.h"
 #include "HIDO_Util.h"
-#include "Battery.h"
+//#include "Battery.h"
 #include "global_param.h"
 #include "AppConfig.h"
-#include "OTA.h"
-#include "Log.h"
+//#include "OTA.h"
+//#include "Log.h"
 #include "Uart.h"
 
 /*******************************************************************************
@@ -29,20 +29,17 @@
 /*******************************************************************************
  *                             Type Definition                                 *
  *******************************************************************************/
-typedef enum
-{
-    TCP_CLIENT_STATE_IDLE,
-    TCP_CLIENT_STATE_CONNECTING,
-    TCP_CLIENT_STATE_CONNECTED,
-}E_TCPClientState;
+
 
 /*******************************************************************************
  *                             Local Variable                                  *
  *******************************************************************************/
 HIDO_INT32 l_i32TCPClientID = 0;
-static E_TCPClientState l_eTCPClientState = TCP_CLIENT_STATE_IDLE;
+E_TCPClientState l_eTCPClientState = TCP_CLIENT_STATE_IDLE;  /* 瀵煎嚭渚汸athTest浣跨敤 */
 static HIDO_UINT32 l_u32HeartBeatTick = 0;
 static HIDO_UINT8 l_au8CmdBuff[1024];
+static HIDO_BOOL l_bTCPPaused = HIDO_FALSE;  /* TCP鏆傚仠鏍囧織锛堣矾寰勪笅杞芥湡闂达級 */
+static E_TCPClientState l_eSavedTCPState = TCP_CLIENT_STATE_IDLE;  /* 淇濆瓨鐨凾CP鐘舵�� */
 
 /*******************************************************************************
  *                        Local Function Declaration                           *
@@ -146,6 +143,11 @@
 u32 TCPfailetimer;
 HIDO_INT32 TCPClient_Poll(void)
 {
+    // 濡傛灉TCP琚殏鍋滐紙璺緞涓嬭浇鏈熼棿锛夛紝涓嶈繘琛岄噸杩炴搷浣�
+    if (l_bTCPPaused) {
+        return HIDO_OK;
+    }
+    
     if (Internet_IsIPReady() == HIDO_TRUE)
     {
         HIDO_UINT32 u32CurTick = HIDO_TimerGetTick();
@@ -198,7 +200,68 @@
 HIDO_INT32 TCPClient_Init(void)
 {
     l_eTCPClientState = TCP_CLIENT_STATE_IDLE;
+    l_bTCPPaused = HIDO_FALSE;
     Socket_Create(&l_i32TCPClientID, SOCKET_TYPE_TCP, TCPClient_SocketEventProc, HIDO_NULL);
 
     return HIDO_OK;
 }
+
+/*******************************************************************************
+ * Function Name     : TCPClient_Pause
+ * Description       : 鏆傚仠TCP杩炴帴锛堢敤浜庤矾寰勪笅杞芥湡闂撮伩鍏嶅樊鍒嗘暟鎹共鎵帮級
+ * Input             : None
+ * Output            : None
+ * Return            : HIDO_OK
+ *******************************************************************************/
+HIDO_INT32 TCPClient_Pause(void)
+{
+    if (l_bTCPPaused) {
+        HIDO_Debug("[TCPClient] Already paused\r\n");
+        return HIDO_OK;
+    }
+    
+    HIDO_Debug("[TCPClient] Pausing TCP connection...\r\n");
+    
+    // 淇濆瓨褰撳墠鐘舵��
+    l_eSavedTCPState = l_eTCPClientState;
+    
+    // 濡傛灉褰撳墠宸茶繛鎺ワ紝鍏抽棴杩炴帴
+    if (l_eTCPClientState == TCP_CLIENT_STATE_CONNECTED || 
+        l_eTCPClientState == TCP_CLIENT_STATE_CONNECTING) {
+        Socket_Close(l_i32TCPClientID);
+        l_eTCPClientState = TCP_CLIENT_STATE_IDLE;
+        HIDO_Debug("[TCPClient] TCP connection closed\r\n");
+    }
+    
+    // 璁剧疆鏆傚仠鏍囧織
+    l_bTCPPaused = HIDO_TRUE;
+    
+    return HIDO_OK;
+}
+
+/*******************************************************************************
+ * Function Name     : TCPClient_Resume
+ * Description       : 鎭㈠TCP杩炴帴锛堣矾寰勪笅杞藉畬鎴愬悗锛�
+ * Input             : None
+ * Output            : None
+ * Return            : HIDO_OK
+ *******************************************************************************/
+HIDO_INT32 TCPClient_Resume(void)
+{
+    if (!l_bTCPPaused) {
+        HIDO_Debug("[TCPClient] Not paused, no need to resume\r\n");
+        return HIDO_OK;
+    }
+    
+    HIDO_Debug("[TCPClient] Resuming TCP connection...\r\n");
+    
+    // 娓呴櫎鏆傚仠鏍囧織
+    l_bTCPPaused = HIDO_FALSE;
+    
+    // 閲嶇疆鐘舵�佷负IDLE锛岃Poll鍑芥暟鑷姩閲嶈繛
+    l_eTCPClientState = TCP_CLIENT_STATE_IDLE;
+    
+    HIDO_Debug("[TCPClient] TCP will reconnect automatically\r\n");
+    
+    return HIDO_OK;
+}

--
Gitblit v1.10.0