From 36332fb0b1fa1f42bb3695b2c5d0940c253b1803 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Thu, 14 Aug 2025 07:26:15 +0800 Subject: [PATCH] =?utf8?q?=E5=8F=AF=E5=AF=B9=E8=AF=9D=EF=BC=8C=E4=BD=86tts?= =?utf8?q?=E4=BB=8D=E7=84=B6=E4=B8=8D=E8=83=BD=E5=AE=8C=E6=95=B4=E6=92=AD?= =?utf8?q?=E6=94=BE=E3=80=82asr=E4=B9=9F=E4=B8=A2=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../slip/cat1Service/bk_websocket.h | 4 +-- .../slip/cat1Service/cat1_ai_server.cpp | 29 ++++++++++++++----- .../slip/cat1Service/websocket_parser.cpp | 2 +- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/bk_websocket.h b/code/sdk/drivers/peripheral/slip/cat1Service/bk_websocket.h index 33156f03c..bbfa75d39 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/bk_websocket.h +++ b/code/sdk/drivers/peripheral/slip/cat1Service/bk_websocket.h @@ -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; 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 e1aeb4c24..4ba5118cc 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp @@ -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 diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/websocket_parser.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/websocket_parser.cpp index 0dda0d562..aa259147a 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/websocket_parser.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/websocket_parser.cpp @@ -4,7 +4,7 @@ #include // 控制日志输出的宏 -#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__) -- 2.17.1