修改ws 的stop调用
authorhcj <1224667075@qq.com>
Fri, 19 Sep 2025 12:31:56 +0000 (20:31 +0800)
committerhcj <1224667075@qq.com>
Fri, 19 Sep 2025 12:31:56 +0000 (20:31 +0800)
code/sdk/zhihui/leiniao/imsl_ln/leiniao_api_at.c
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index aaed755..f00f1c1 100644 (file)
@@ -650,7 +650,7 @@ static uint32_t ln_ws_stop_at(uint8_t *para, uint32_t paraLen, char *strCommonCm
 {
     VAD_UNUSED(para); VAD_UNUSED(paraLen); VAD_UNUSED(strCommonCmd);
     printf("[LN][WS_STOP]\n");
-    int ret = ln_ws_stop();
+    int ret = ln_ws_stop_async();
     if (ret != 0)
     {
         printf("[LN][WS_STOP] failed: %d\n", ret);
index 555a111..cb1c3e8 100644 (file)
@@ -124,7 +124,7 @@ static void ln_ws_on_error(int client, struct WebSocketErrorResult error)
 static void ln_ws_on_close(int client)
 {
     (void)client;
-    printf("WebSocketClientConstructor [LN][WS] ln_ws_on_close");
+    printf("WebSocketClientConstructor [LN][WS] ln_ws_on_close %d\r\n",client);
     g_ws_connected = WS_STATE_DISCONNECTED;
     printf("[LN][WS] 连接状态: 未连接\n");
     if(g_ws_client_fd>=0)
@@ -274,6 +274,27 @@ static void ln_ws_main_thread(void *arg)
         /* 1秒间隔 */
         usleep(1000 * 1000);
     }
+
+    if (g_ws_client_fd >= 0) {
+        WebSocketClientClose(g_ws_client_fd);
+        g_ws_client_fd = -1;
+    }
+    g_ws_connected = WS_STATE_DISCONNECTED;
+    
+    // 删除消息队列
+    if (g_ws_msg_queue != NULL) {
+
+         ws_msg_info_t msg;
+        while (osMessageQueueGet(g_ws_msg_queue, &msg, NULL, 0) == osOK) {
+            if(msg.data.raw_json)
+            {
+                free(msg.data.raw_json);
+            }
+            
+        }
+        osMessageQueueDelete(g_ws_msg_queue);
+        g_ws_msg_queue = NULL;
+    }
 }
 
 /*
@@ -411,7 +432,7 @@ int ln_ws_force_reconnect(void)
     ws_msg_info_t msg;
     msg.msg_type = WS_MSG_TYPE_FORCE_RECONNECT;
     msg.data_len = 0;
-    // msg.data = NULL;
+    msg.data.raw_json = NULL;
     
     osStatus_t ret = osMessageQueuePut(g_ws_msg_queue, &msg, 0, 0);
     return (ret == osOK) ? 0 : -1;
@@ -425,6 +446,7 @@ int ln_ws_stop_async(void)
     ws_msg_info_t msg;
     msg.msg_type = WS_MSG_TYPE_STOP;
     msg.data_len = 0;
+    msg.data.raw_json = NULL;
     // msg.data = NULL;
     
     osStatus_t ret = osMessageQueuePut(g_ws_msg_queue, &msg, 0, 0);