1.4GAi关闭一些高频打印,关闭触摸屏幕打印
authorluozheng <1732036298@qq.com>
Thu, 21 Aug 2025 10:22:59 +0000 (18:22 +0800)
committerluozheng <1732036298@qq.com>
Thu, 21 Aug 2025 10:22:59 +0000 (18:22 +0800)
2.修改TCP_MANAGER_THREAD_STACK_SIZE大小
3.tcp_simple_manager文件打印

code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h
code/sdk/drivers/peripheral/slip/tcpmanager/tcp_simple_manager.c
code/sdk/drivers/peripheral/slip/tcpmanager/tcp_simple_manager.h
code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/pointer_input_device.cpp

index c9540ab..9583743 100644 (file)
@@ -137,6 +137,7 @@ namespace OHOS
         model->stop_uapi_stop_tts_timer();
         remove_4GAI_vote(); // 移除4g投票
         dinit_ai_task();
+        ai_cleanup_resources();
 
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop end");
index 96d7054..f4b8873 100644 (file)
@@ -1854,7 +1854,7 @@ void uapi_stop_tts(void)
     } \
     } ";
 
-     printf("uapi_start_tts : %s\r\n",jsonString);
+     printf("uapi_stop_tts : %s\r\n",jsonString);
 
     if (send_websocket_message(tts_client,( uint8_t *)jsonString,strlen(jsonString),WS_TEXT)==0)
     {
@@ -2645,7 +2645,7 @@ bool dinit_ai_task(void)
         tts_server_deinit();
         
         // 清理AI系统资源
-        ai_cleanup_resources(); 
+        // ai_cleanup_resources(); 
         
        
         WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AI task deinitialized successfully");
@@ -3156,7 +3156,7 @@ errcode_t voice_chat_server_init(void)
 
 // 资源清理函数
 void ai_cleanup_resources(void) {
-    AI_LOCK();
+    // AI_LOCK();
     
     // 首先关闭所有WebSocket连接
     // if (chat_client) {
@@ -3176,10 +3176,10 @@ void ai_cleanup_resources(void) {
     // ws_queues_deinit_all();
     
     // 清理互斥锁
-    if (g_ai_mutex) {
-        osMutexDelete(g_ai_mutex);
-        g_ai_mutex = NULL;
-    }
+    // if (g_ai_mutex) {
+    //     osMutexDelete(g_ai_mutex);
+    //     g_ai_mutex = NULL;
+    // }
     
     // 清理定时器
     // if (g_timer_time_sync) {
@@ -3190,7 +3190,7 @@ void ai_cleanup_resources(void) {
     // 重置内存使用统计
     g_ai_memory_usage = 0;
     
-    AI_UNLOCK();
+    // AI_UNLOCK();
     
     // 最后清理TCP管理器
     // tcp_simple_manager_deinit();
index 972e2d3..160f71e 100644 (file)
@@ -1185,7 +1185,10 @@ static void time_sync_func(void)
 
     if (uapi_get_screen_state() == 0)
     {
-         cat1_getsignal();
+        if(g_skip_cat1_service_udp_transfer !=1)
+        {
+            cat1_getsignal();
+        }
 
         #ifdef SUPPORT_CHINA_MOBILE_AI_REGULATION
         char device_id[128]={0};
index cb69e33..c70ef3e 100644 (file)
@@ -24,6 +24,7 @@ void uapi_UI_stop_start_asr_timeout(void);
 
 bool uapi_get_server_state_is_end(void);
 
+void ai_cleanup_resources(void);
 typedef enum
 {
     AI_TYPE_0=0,
index a3b5695..8790840 100644 (file)
@@ -556,7 +556,7 @@ static void cleanup_connection_unsafe(tcp_connection_info_t* conn)
             
             /* 给一些时间让TCP完成四次挥手 */
             for (int i = 0; i < 50; i++) {  /* 最多等待500ms */
-                sys_msleep(10);
+                msleep(10);
                 
                 /* 检查连接是否已经关闭 */
                 int error = 0;
@@ -780,7 +780,7 @@ static void tcp_manager_io_thread(void* arg)
             select_result = select(max_fd + 1, &read_fds, &write_fds, &except_fds, &timeout);
         } else {
             /* 没有活跃连接,短暂休眠 */
-            sys_msleep(100);
+            msleep(100);
             continue;
         }
         
@@ -790,7 +790,7 @@ static void tcp_manager_io_thread(void* arg)
                 continue;
             } else {
                 printf("select错误: %d, 继续运行\n", errno);
-                sys_msleep(100);
+                msleep(100);
                 continue;
             }
         }
@@ -852,12 +852,42 @@ static void tcp_manager_io_thread(void* arg)
             if (FD_ISSET(conn->sockfd, &write_fds) && conn->send_queue_count > 0) {
                 /* 处理发送队列 */
                 process_send_queue(conn);
+/* 重置写入失败计数和最后写入时间 */
+                conn->write_fail_count = 0;
+                conn->last_write_attempt = sys_now();
             }
             else
             {
                 if( conn->send_queue_count > 0)
                 {
                     printf("process_send_queue tcp_manager_io_thread send_queue_count:%d sockfd:%d\n",conn->send_queue_count,conn->sockfd);
+
+                    /* 检查写入超时 - 长时间无法写入时断开连接 */
+                    uint32_t current_time = sys_now();
+                    if (conn->last_write_attempt > 0) 
+                    {
+                        uint32_t time_since_last_write = current_time - conn->last_write_attempt;
+                        
+                        if (time_since_last_write > TCP_WRITE_TIMEOUT_MS && conn->send_queue_count>10) {
+                            printf("[TCPM_ERR] 写入超时,断开连接: handle=%p, sockfd=%d, 超时时间=%u ms\n", 
+                                   conn->handle, conn->sockfd, time_since_last_write);
+                            
+                            /* 标记连接为错误状态,后续会清理 */
+                            conn->state = TCP_STATE_ERROR;
+                            conn->write_fail_count++;
+                            
+                            /* 如果连续写入失败次数过多,强制断开连接 */
+                        } 
+                        else {
+                            /* 更新写入尝试时间,避免重复检查 */
+                            // conn->last_write_attempt = current_time;
+                        }
+                    } 
+                    else {
+                        /* 首次检测到无法写入,记录时间 */
+                        if(conn->last_write_attempt!=0)
+                        conn->last_write_attempt = current_time;
+                    }
                 }
                 
             }
@@ -1046,7 +1076,7 @@ static void tcp_manager_io_thread(void* arg)
         
         /* 防止CPU占用过高 */
         if (total_connections == 0) {
-            sys_msleep(50);
+            msleep(50);
         }
     }
     
@@ -1073,6 +1103,10 @@ tcp_manager_result_t tcp_simple_manager_init(void)
         g_connections[i].send_queue_count = 0;
         g_connections[i].retry_count = 0;
         g_connections[i].retry_pending = false;
+        g_connections[i].last_write_attempt = 0;
+        g_connections[i].write_fail_count = 0;
+        
+
     }
     
     /* 初始化DNS状态数组 */
@@ -1124,7 +1158,7 @@ tcp_manager_result_t tcp_simple_manager_deinit(void)
     
     /* 等待线程结束 */
     if (g_io_thread != (sys_thread_t)-1) {
-        sys_msleep(1000); /* 等待1秒 */
+        msleep(1000); /* 等待1秒 */
     }
     
     /* 关闭所有连接 */
@@ -1230,6 +1264,8 @@ tcp_handle_t tcp_open_url(const char* host, uint16_t port,
     conn->send_queue_count = 0;
     conn->retry_count = 0;
     conn->retry_pending = false;
+    conn->last_write_attempt = 0;
+    conn->write_fail_count = 0;
     
     /* 复制主机名 */
     strncpy(conn->remote_ip, host, sizeof(conn->remote_ip) - 1);
@@ -1552,7 +1588,7 @@ if (errno == EAGAIN || errno == EWOULDBLOCK) {
         return -1;
     }
 /* 短暂等待后重试 */
-                sys_msleep(5);  // 增加等待时间到5ms
+                msleep(5);  // 增加等待时间到5ms
                 continue;
             } else if (errno == EINPROGRESS) {
                 /* 连接正在进行中,等待连接完成 */
@@ -1562,7 +1598,7 @@ if (errno == EAGAIN || errno == EWOULDBLOCK) {
                     return -1;
                 }
                 /* 等待连接完成 */
-                sys_msleep(10);  // 等待10ms
+                msleep(10);  // 等待10ms
                 continue;
             } else {
                 printf("tcp_send_and_wait_response: send失败, errno=%d (%s)\n", 
@@ -1705,6 +1741,8 @@ tcp_handle_t tcp_add_existing_connection(int sockfd, const char* host, uint16_t
     conn->send_queue_count = 0;
     conn->retry_count = 0;
     conn->retry_pending = false;
+    conn->last_write_attempt = 0;
+    conn->write_fail_count = 0;
     
     /* 复制主机名 */
     strncpy(conn->remote_ip, host, sizeof(conn->remote_ip) - 1);
index 983b47c..98bc752 100644 (file)
@@ -26,7 +26,7 @@ extern "C" {
 #define TCP_MANAGER_RECV_QUEUE_SIZE     16      /* 接收队列大小 */
 #define TCP_MANAGER_CMD_QUEUE_SIZE      32      /* 命令队列大小 */
 #define TCP_MANAGER_RECV_BUFFER_SIZE    1024     /* 接收缓冲区大小 */
-#define TCP_MANAGER_THREAD_STACK_SIZE   4096    /* 线程栈大小 */
+#define TCP_MANAGER_THREAD_STACK_SIZE  (1024*8)    /* 线程栈大小 */
 #define TCP_MANAGER_THREAD_PRIORITY     5       /* 线程优先级 */
 
 /* 调试等级定义 */
@@ -51,8 +51,9 @@ extern int tcp_get_debug_level(void);
 #define TCPM_DBG(fmt, ...)      do { if(tcp_get_debug_level() >= TCP_DEBUG_LEVEL_DEBUG) printf("[TCPM_DBG] " fmt "\n", ##__VA_ARGS__); } while(0)
 
 /* 连接参数定义 */
-#define TCP_CONNECT_TIMEOUT_MS         10000
-#define TCP_DNS_TIMEOUT_MS             8000
+#define TCP_CONNECT_TIMEOUT_MS         10000   /* 连接超时时间 (毫秒) */
+#define TCP_DNS_TIMEOUT_MS             8000    /* DNS解析超时时间 (毫秒) */
+#define TCP_WRITE_TIMEOUT_MS           3000   /* 写入超时时间 (毫秒) - 长时间无法写入时断开连接 */
 #define TCP_SEND_QUEUE_SIZE            32
 #define TCP_SEND_BUFFER_SIZE           2048
 #define TCP_CONNECT_RETRY_COUNT        3
@@ -158,6 +159,10 @@ typedef struct {
     uint8_t retry_count;
     uint32_t last_retry_time;
     bool retry_pending;
+
+    /* 写入超时相关字段 */
+    uint32_t last_write_attempt;  /* 最后一次写入尝试时间 */
+    uint32_t write_fail_count;    /* 连续写入失败次数 */
 } tcp_connection_info_t;
 
 /* 管理器统计信息 */
index 5f3b0ae..d224421 100755 (executable)
@@ -258,9 +258,9 @@ void PointerInputDevice::DispatchDragStartEvent()
     if (!isDragging_) {
         if ((MATH_ABS(dragLen_.x) >= DRAG_LIMIT_X) || (MATH_ABS(dragLen_.y) >= DRAG_LIMIT_Y)) {
             
-            printf("=====PointerInputDevice::DispatchDragStartEvent absx(%d) limitx(%d) absy(%d) limity(%d) \r\n",
-            MATH_ABS(dragLen_.x),DRAG_LIMIT_X,
-            MATH_ABS(dragLen_.y),DRAG_LIMIT_Y);
+            // printf("=====PointerInputDevice::DispatchDragStartEvent absx(%d) limitx(%d) absy(%d) limity(%d) \r\n",
+            // MATH_ABS(dragLen_.x),DRAG_LIMIT_X,
+            // MATH_ABS(dragLen_.y),DRAG_LIMIT_Y);
 
             if ((touchableView_ != nullptr) && !cancelSent_) {
                 DispatchCancelEvent();