From 97d69cb5f04cb06b33160586290b435c80d90e33 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 4 Aug 2025 18:02:23 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B34GAi=E9=95=BF=E6=96=87?= =?utf8?q?=E6=9C=AC=E6=92=AD=E6=94=BE=E5=8D=A1=E9=A1=BF=E9=97=AE=E9=A2=98?= =?utf8?q?=EF=BC=8C=E8=BF=98=E9=9C=80=E5=A4=9A=E5=A4=9A=E5=8E=8B=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/src/AiVoiceModel.cpp | 3 +- .../ble_service/bleservice/bleService.c | 37 +++++++++++++++++++ .../ble_service/bleservice/bleService.h | 2 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index afec3424d..3f811e42c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -1635,9 +1635,8 @@ namespace OHOS } if (get_bk_websocket_tts_tick() == 0) // 代表可以发录音文本 { - if (AiVoiceModel::GetInstance().GetInit_4gai_task()) + if (AiVoiceModel::GetInstance().GetInit_4gai_task() && !get_ai_osal_msg_queue_is_full()) { - LOS_Msleep(200); AiVoiceModel::GetInstance().ProcessTextByPunctuation(); } } 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 cae2b1906..2ac1d6a59 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -2571,7 +2571,32 @@ void AI_data_assembly(uint8_t type,uint8_t *buf,uint8_t aitype) static uint8_t g_blesrv_mail_flag=0; +#define OSAL_INVALID_MSG_NUM 0xFFFFFFFF +#define QUEUE_FULL_THRESHOLD 0.8f // 80% 阈值 +// 判断AI消息队列是否接近满(超过阈值) +int get_ai_osal_msg_queue_is_full(void) +{ + // 检查队列有效性 + if (g_ble_Ai_record_queue == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "invalid queue id"); + return -1; // 队列无效 + } + + // 获取当前消息数 + unsigned int current_num = osal_msg_queue_get_msg_num(g_ble_Ai_record_queue); + if (current_num == OSAL_INVALID_MSG_NUM) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get msg num failed"); + return -1; // 获取失败 + } + // 计算占比,超过阈值则视为“即将满” + float ratio = (float)current_num / BLESRV_APP_BOARD_MSG_COUNT; + if (ratio >= QUEUE_FULL_THRESHOLD) { + return 1; // 达到或超过阈值(接近满) + } else { + return 0; // 未达阈值(未满) + } +} int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) { @@ -2603,10 +2628,22 @@ int send_msg_data_into_Ai_msg_queue(void *buff,uint16_t len,uint8_t type) } memcpy_s((void *)(blesrv_mail.msg_data),len,buff,len); + const static int QUEUE_RETRY_DELAY_MS = 50; // 重试间隔(ms) + // 检查队列是否已满(提前判断,减少失败概率) + if (osal_msg_queue_is_full(g_ble_Ai_record_queue)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "queue is full"); + osal_msleep(QUEUE_RETRY_DELAY_MS); // 等待队列消费 + } ret = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0); if (ret != OSAL_SUCCESS) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"len<=singlebuflen Error blesrv Check send failed! err=0x%X %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count); + osal_msleep(QUEUE_RETRY_DELAY_MS); // 等待队列消费 + ret = osal_msg_queue_write_copy(g_ble_Ai_record_queue, (void *)&blesrv_mail, sendlen , 0); + if (ret != OSAL_SUCCESS) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"retry len<=singlebuflen Error blesrv Check send failed! err=0x%X %d! \r\n", ret,send_msg_data_into_Ai_msg_queue_count); + } } return OSAL_SUCCESS; diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h index bf8666ec6..ed17e736c 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h @@ -113,6 +113,8 @@ void AI_data_assembly(uint8_t type,uint8_t *buf,uint8_t aitype); void set_AI_interval(uint8_t data); +int get_ai_osal_msg_queue_is_full(void); + #ifdef __cplusplus } #endif -- 2.17.1