From 931a721e1703af4b676e1e16bff122f3d88ae147 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Wed, 13 Aug 2025 14:52:13 +0800 Subject: [PATCH] =?utf8?q?=E4=B8=AD=E9=97=B4=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../ble_service/bleservice/bleService.c | 2 +- .../slip/cat1Service/cat1_ai_server.cpp | 32 +++++++++---------- .../slip/tcpmanager/tcp_simple_manager.c | 25 ++++++++++++++- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 4bc19d0f1..f3657f5d6 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -2609,7 +2609,7 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) // uint32_t singlebuflen= ble_nus_max_data_len-20; uint32_t singlebuflen = 0; if(getselect4gorbtai() == 1) { - singlebuflen = 288*4;//4G + singlebuflen = 288*2;//4G } else { singlebuflen = ble_nus_max_data_len-20;//BT } diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp index 3ceb23b07..b2328d051 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp @@ -1411,7 +1411,7 @@ void bk_websocket_asr(void *data) { if (type == WS_TEXT) { if (false == aer_result_analysis(asr_recv_buf)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ASR result analysis failed"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ASR result analysis failed %s",asr_recv_buf); break; } } else if (type == WS_PONG) { @@ -2186,7 +2186,7 @@ void send_ai_bin(uint8_t *buf,uint32_t len) if (send_websocket_message(asr_client,( uint8_t *)buf,len,WS_BINARY)==0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n"); - msleep(10); + msleep(100); } else { @@ -2653,21 +2653,21 @@ void ai_cleanup_resources(void) { AI_LOCK(); // 首先关闭所有WebSocket连接 - if (chat_client) { - lwip_close_websocket_client(chat_client); - chat_client = NULL; - } - if (asr_client) { - lwip_close_websocket_client(asr_client); - asr_client = NULL; - } - if (tts_client) { - lwip_close_websocket_client(tts_client); - tts_client = NULL; - } + // if (chat_client) { + // lwip_close_websocket_client(chat_client); + // chat_client = NULL; + // } + // if (asr_client) { + // lwip_close_websocket_client(asr_client); + // asr_client = NULL; + // } + // if (tts_client) { + // lwip_close_websocket_client(tts_client); + // tts_client = NULL; + // } // 清理WebSocket消息队列 - ws_queues_deinit_all(); + // ws_queues_deinit_all(); // 清理互斥锁 if (g_ai_mutex) { @@ -2687,7 +2687,7 @@ void ai_cleanup_resources(void) { AI_UNLOCK(); // 最后清理TCP管理器 - tcp_simple_manager_deinit(); + // tcp_simple_manager_deinit(); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AI resources cleaned up"); } diff --git a/code/sdk/drivers/peripheral/slip/tcpmanager/tcp_simple_manager.c b/code/sdk/drivers/peripheral/slip/tcpmanager/tcp_simple_manager.c index 815b80525..eaf50b52d 100644 --- a/code/sdk/drivers/peripheral/slip/tcpmanager/tcp_simple_manager.c +++ b/code/sdk/drivers/peripheral/slip/tcpmanager/tcp_simple_manager.c @@ -661,6 +661,7 @@ static bool add_to_send_queue(tcp_connection_info_t* conn, const uint8_t* data, static bool process_send_queue(tcp_connection_info_t* conn) { if (!conn || conn->send_queue_count == 0) { + printf("conn->send_queue_count == 0\r\n"); return true; } @@ -670,10 +671,17 @@ static bool process_send_queue(tcp_connection_info_t* conn) uint8_t index = (conn->send_queue_head + i) % TCP_SEND_QUEUE_SIZE; tcp_send_queue_item_t* item = &conn->send_queue[index]; - if (!item->in_use) continue; + if (!item->in_use) + { + printf("item->in_use in_use\r\n"); + continue; + } /* 尝试发送数据 */ + printf("process_send_queue start\r\n"); + ssize_t sent = send(conn->sockfd, item->data, item->length, MSG_NOSIGNAL); + printf("process_send_queue %d %d\r\n",sent, item->length); if (sent == item->length) { /* 发送成功 */ @@ -691,6 +699,13 @@ static bool process_send_queue(tcp_connection_info_t* conn) /* 发送缓冲区满,稍后重试 */ all_sent = false; break; + } else if (errno == ENOTCONN || errno == ECONNRESET || errno == EPIPE) { + /* 连接已断开,清空整个发送队列 */ + printf("连接已断开,清空发送队列\n"); + conn->send_queue_count = 0; + conn->send_queue_head = 0; + memset(conn->send_queue, 0, sizeof(conn->send_queue)); + return false; // 表示需要重新建立连接 } else { /* 发送错误,标记为失败 */ printf("发送错误: %d, 连接可能已断开\n", errno); @@ -837,6 +852,14 @@ static void tcp_manager_io_thread(void* arg) /* 处理发送队列 */ process_send_queue(conn); } + else + { + if( conn->send_queue_count > 0) + { + printf("process_send_queue tcp_manager_io_thread %d %d\n",conn->send_queue_count,conn->sockfd); + } + + } } /* 处理连接状态变化 */ -- 2.17.1