可对话,但tts仍然不能完整播放。asr也丢数据 2074/1
author孙春阳 <snickersun@163.com>
Wed, 13 Aug 2025 23:26:15 +0000 (07:26 +0800)
committer孙春阳 <snickersun@163.com>
Wed, 13 Aug 2025 23:26:15 +0000 (07:26 +0800)
code/sdk/drivers/peripheral/slip/cat1Service/bk_websocket.h
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp
code/sdk/drivers/peripheral/slip/cat1Service/websocket_parser.cpp

index 33156f0..bbfa75d 100644 (file)
@@ -20,11 +20,11 @@ typedef ws_opcode_t WebSocketMessageType;
 typedef void (*on_ws_packet_callback)(uint8_t* data, size_t datalen, WebSocketMessageType type);
 
 /* WebSocket消息队列系统 */
-#define WS_QUEUE_SIZE 4
+#define WS_QUEUE_SIZE 48
 #define WS_MESSAGE_MAX_SIZE 1024
 
 typedef struct {
-    uint8_t data[WS_MESSAGE_MAX_SIZE];
+    uint8_t *data;//data[WS_MESSAGE_MAX_SIZE];
     uint16_t length;
     WebSocketMessageType type;
     uint32_t timestamp;
index e1aeb4c..4ba5118 100644 (file)
@@ -434,6 +434,16 @@ static int ws_queue_put(ws_message_queue_t* queue, const uint8_t* data, uint16_t
     
     /* 添加消息到队列 */
     ws_message_item_t* item = &queue->messages[queue->tail];
+    if (item->data==NULL)
+    {
+        item->data=(uint8_t*)malloc(WS_MESSAGE_MAX_SIZE);
+        if (item->data==NULL)
+        {
+            osMutexRelease(queue->mutex);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to malloc ws_message_item_t");
+            return -1;
+        }
+    }
     memset(item->data,0,WS_MESSAGE_MAX_SIZE);
     memcpy(item->data, data, length);
     item->length = length;
@@ -490,12 +500,16 @@ static int ws_queue_get(ws_message_queue_t* queue, uint8_t* data, uint16_t max_l
     uint16_t copy_len = (item->length > max_length) ? max_length : item->length;
     memcpy(data, item->data, copy_len);
     *type = item->type;
+    if (item->data)  
+    {
+        free(item->data);
+        item->data=NULL;
+    }
     
     /* 标记为已使用 */
     item->in_use = false;
     queue->head = (queue->head + 1) % WS_QUEUE_SIZE;
     queue->count--;
-    
     osMutexRelease(queue->mutex);
     
     return copy_len;
@@ -1088,6 +1102,7 @@ void bk_websocket_demo(void *data) {
             {
                 recv_buf[len] = '\0';
             }
+            WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bk_websocket_demo len %d\n",len);
             if (len == -1 || type == WS_CLOSE) {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WebSocket connection closed");
                 break;
@@ -1369,13 +1384,13 @@ bool aer_result_analysis(char *buf)
         #ifdef ASR_HODE
         memcpy_s(&result_str_asr[strlen(result_str_asr)],AI_RESULT_STR_LEN/2,result_str,strlen(result_str));
 
-        if(asr_is_stop==1 && strlen(result_str_asr))
-        {
-            send_ai_txt(0,result_str_asr);
-            ble_set_ai_Question_str(result_str_asr);
+        // if(asr_is_stop==1 && strlen(result_str_asr))
+        // {
+        //     send_ai_txt(0,result_str_asr);
+        //     ble_set_ai_Question_str(result_str_asr);
 
-            memset_s(result_str_asr,AI_RESULT_STR_LEN,0,AI_RESULT_STR_LEN);
-        }
+        //     memset_s(result_str_asr,AI_RESULT_STR_LEN,0,AI_RESULT_STR_LEN);
+        // }
 
         
         #else
index 0dda0d5..aa25914 100644 (file)
@@ -4,7 +4,7 @@
 #include <string.h>
 
 // 控制日志输出的宏
-#define ENABLE_DEBUG_LOG 1  // 设置为0可以关闭所有调试输出
+#define ENABLE_DEBUG_LOG 0  // 设置为0可以关闭所有调试输出
 
 #if ENABLE_DEBUG_LOG
 #define WS_LOG(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)