From bb3dec3120a3769f25f484a019cbe4e6948e3947 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 16 Oct 2024 16:18:12 +0800 Subject: [PATCH] =?utf8?q?1.AI=E8=B6=85=E6=97=B6=E7=95=8C=E9=9D=A2UI?= =?utf8?q?=E4=BC=98=E5=8C=96=202.=E6=B7=BB=E5=8A=A0AI=E5=9B=9E=E5=BA=94?= =?utf8?q?=E7=9B=B4=E6=8E=A5=E7=BB=93=E6=9D=9F=EF=BC=8C=E8=BF=94=E5=9B=9E?= =?utf8?q?=E7=BB=93=E6=9E=9C=E4=B8=BA=E7=A9=BA=E5=BC=B9=E7=AA=97=203.?= =?utf8?q?=E8=BF=9B=E5=85=A5AI=E7=95=8C=E9=9D=A2=E5=8A=A8=E6=80=81?= =?utf8?q?=E6=9B=B4=E6=94=B9=E8=BF=9E=E6=8E=A5=E5=8F=82=E6=95=B0=EF=BC=8C?= =?utf8?q?=E5=87=8F=E5=B0=91=E5=8F=91=E9=80=81=E8=AF=AD=E9=9F=B3=E6=95=B0?= =?utf8?q?=E6=8D=AE=E9=94=99=E8=AF=AF=E7=8E=87=204.=E5=8F=91=E9=80=81AI?= =?utf8?q?=E5=87=86=E5=A4=87=E5=92=8C=E5=8F=96=E6=B6=88=E5=BD=93=E5=89=8DA?= =?utf8?q?I=E5=AF=B9=E8=AF=9D=E6=8C=87=E4=BB=A4=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?utf8?q?=E8=93=9D=E7=89=99=E7=9A=84=E7=BA=BF=E7=A8=8B=EF=BC=8C=E4=B8=8EU?= =?utf8?q?I=E7=BA=BF=E7=A8=8B=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/src/AiVoiceModel.cpp | 15 ++- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 12 +- .../aivoice/src/AivoiceConnectTimeoutView.cpp | 5 +- .../service/ble_service/bleservice/bleEvent.c | 120 +++++++++++------- .../ble_service/bleservice/bleService.c | 33 ++--- .../peripheral/utils/custom_utils_at_cmd.c | 3 + 6 files changed, 115 insertions(+), 73 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 3f7f04716..1ef125cff 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:50 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-15 19:02:09 + * @LastEditTime: 2024-10-16 10:46:11 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -515,7 +515,7 @@ namespace OHOS { AIResponseType = type; errnote = str; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIResponseType = %d,errnote = %s\n", AIResponseType, errnote.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AIResponseType = %d,errnote = %s\n", AIResponseType, errnote.c_str()); //如果是:AI录音解析错误或AI 回应错误 ,或者重传多次录音数据->跳转AI回应错误界面 if (AIResponseType == AiVoiceModel::AI_RECORDING_PARSING_ERROR || AIResponseType == AiVoiceModel::AI_RESPONSE_ERROR || AIResponseType == AiVoiceModel::AI_BLE_ERROR) @@ -523,6 +523,17 @@ namespace OHOS SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)errnote.c_str(), errnote.length()); return; } + else if(AiVoiceModel::AI_RESPONSE_END) //如果是AI 回应结束 + { + if(errnote.empty()) //如果没有回应数据 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::GetErrnote is empty!!"); + AiVoiceModel::GetInstance().SetErrnote("response data is empty"); + std::string str = AiVoiceModel::GetInstance().GetErrnote(); + SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length()); + return; + } + } aiAnswerStr += str; SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 4fd9b9162..f9428d09e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-26 16:16:49 + * @LastEditTime: 2024-10-16 15:13:54 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -22,6 +22,7 @@ #include #include "gfx_utils/mem_check.h" +#include "bleService.h" namespace OHOS { @@ -58,6 +59,8 @@ namespace OHOS ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 开启一个60s取消长亮屏timer model->ai_start_screen60s_timer(); + + uapi_ble_connect_param_update(10); } // 页面已经展示后的调用逻辑 @@ -87,6 +90,8 @@ namespace OHOS model->StatusResume(); model->ai_stop_screen60s_timer(); model->stop_listening_timer(); + + uapi_ble_connect_param_update(50); } /*调转到返回结果界面*/ @@ -351,6 +356,11 @@ namespace OHOS auto it = viewIdMap.find(viewId); if (it != viewIdMap.end()) { + if(it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) //点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat"); + AiVoiceModel::GetInstance().CancelCurAIChat(); + } ChangeViewAndLogicOperator(it->second.first, it->second.second); return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp index 35557fc7a..00962b635 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-05 10:20:37 + * @LastEditTime: 2024-10-16 11:37:43 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceConnectTimeoutView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -275,10 +275,11 @@ namespace OHOS { if (NoteLabel) { - NoteLabel->SetText(""); + // NoteLabel->SetText(""); std::string text = AiVoiceModel::GetInstance().GetErrnote(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "text = %s", text.c_str()); NoteLabel->SetText(text.c_str()); + NoteLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); NoteLabel->Invalidate(); } } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 3f3b68717..9abf63730 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -473,35 +473,7 @@ void sendtraningdata(msg_get_train_data_info_t *data) } static uint8_t AI_is_end_state=0; -//发送AI录音准备就绪国内/ -/*使用模型: -0:文心一言 -1:ChatGPT -2:KIMI -3:豆包*/ -bool send_AI_is_ready(uint8_t type) -{ - - if(AI_is_end_state==0) - { - printf("发送AI准备就绪\r\n"); - ble_data_type type_={0x05,0x05,1,1,1}; - send_big_data(type_,(char *)&type,1); - AI_is_end_state=1; - return true; - } - else - { - printf("发送AI准备就绪失败,没有正确回复结束\r\n"); - return false; - } - - - - - //send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x05, 5); -} //查询AI 模型是否可用,结果通过2AE4返回 /*使用模型: 0:文心一言 @@ -517,25 +489,7 @@ void inquire_AI_is_ready(uint8_t type) //send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x06, 5); } -void cancel_AI_cur_chat(void) -{ - if(AI_is_end_state) - { - printf("取消当前AI对话\r\n"); - uint8_t data=1; - ble_data_type type_={0x05,0x07,data_len,1,1}; - send_big_data(type_,(char *)&data,data_len); - AI_is_end_state=0; - - } - else - { - printf("已经取消当前AI对话无需再次取消\r\n"); - } - - //send_big_data(0, (char *)&data, 1, 1, 1, 1, 0x07, 5); -} //发送ble数据 @@ -8276,6 +8230,13 @@ void free_ble_data(void)//以防断开蓝牙没有释放数据类型 } +void cancel_AI_cur_chat(void) +{ + blesrv_service_recv_msg_handler(0xff,(uint8_t*)"AI_cancel_AI",13); + return; + //send_big_data(0, (char *)&data, 1, 1, 1, 1, 0x07, 5); +} + void free_ble_data_Event(void)//以防断开蓝牙没有释放数据类型 { @@ -8303,6 +8264,59 @@ void free_ble_data_Event(void)//以防断开蓝牙没有释放数据类型 } +//发送AI录音准备就绪国内/ +/*使用模型: +0:文心一言 +1:ChatGPT +2:KIMI +3:豆包*/ +bool send_AI_is_ready_(uint8_t type) +{ + + if(AI_is_end_state==0) + { + printf("发送AI准备就绪\r\n"); + ble_data_type type_={0x05,0x05,1,1,1}; + send_big_data(type_,(char *)&type,1); + AI_is_end_state=1; + return true; + } + else + { + printf("发送AI准备就绪失败,没有正确回复结束\r\n"); + return false; + } + //send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x05, 5); +} + +static uint8_t AI_is_ready_type=0; + +bool send_AI_is_ready(uint8_t type) +{ + AI_is_ready_type=type; + blesrv_service_recv_msg_handler(0xff,(uint8_t*)"AI_is_ready",12); + return true; +} + +void cancel_AI_cur_chat_(void) +{ + if(AI_is_end_state) + { + printf("取消当前AI对话\r\n"); + uint8_t data=1; + ble_data_type type_={0x05,0x07,data_len,1,1}; + send_big_data(type_,(char *)&data,data_len); + AI_is_end_state=0; + + } + else + { + printf("已经取消当前AI对话无需再次取消\r\n"); + } + + + //send_big_data(0, (char *)&data, 1, 1, 1, 1, 0x07, 5); +} //接收app下发的原始数据 void revBleOldData(uint8_t *buf, uint16_t event_size,uint16_t handle)//每包的数据大小 @@ -8310,7 +8324,19 @@ void revBleOldData(uint8_t *buf, uint16_t event_size,uint16_t handle)//每包的 printf("handle :%d %s event_size %d\r\n",handle,getHandlname(handle),event_size); if(handle==0xff) { - free_ble_data_Event(); + if(strcmp("AI_cancel_AI",(char *)buf)==0) + { + cancel_AI_cur_chat_(); + } + else if(strcmp("AI_is_ready",(char *)buf)==0) + { + send_AI_is_ready_(AI_is_ready_type); + } + else + { + free_ble_data_Event(); + } + return; } 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 032c645da..d03456542 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -492,16 +492,7 @@ void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, gap_bl Bleconnect = GAP_BLE_STATE_CONNECTED;//蓝牙已连接 - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_CONNECTED!!! 0x%x\r\n",pair_state); - - // gap_conn_param_update_t conn_param = { 0 }; - // conn_param.conn_handle = conn_id; /* param 0: conn_handle */ - // conn_param.interval_min =50; /* param 1: interval_min */ - // conn_param.interval_max = 50; /* param 2: interval_max */ - // conn_param.slave_latency = 6; /* param 3: slave_latency */ - // conn_param.timeout_multiplier = 700; /* param 4: timeout_multiplier */ - // ret = gap_ble_connect_param_update(&conn_param); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"gap ble update connection parameters ret: %X\n", ret); + } @@ -512,7 +503,7 @@ void uapi_ble_connect_param_update(uint16_t data) { gap_conn_param_update_t conn_param = { 0 }; conn_param.conn_handle = g_ble_conn_id; /* param 0: conn_handle */ - conn_param.interval_min =data; /* param 1: interval_min */ + conn_param.interval_min =data; /* param 1: interval_min 10ms */ conn_param.interval_max = data; /* param 2: interval_max */ conn_param.slave_latency = 6; /* param 3: slave_latency */ conn_param.timeout_multiplier = 700; /* param 4: timeout_multiplier */ @@ -565,14 +556,6 @@ void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t s hand_watch_first_time_Paired(); svr_ble_adv_stop(); - gap_conn_param_update_t conn_param = { 0 }; - conn_param.conn_handle = conn_id; /* param 0: conn_handle */ - conn_param.interval_min =150; /* param 1: interval_min */ - conn_param.interval_max = 150; /* param 2: interval_max */ - conn_param.slave_latency = 20; /* param 3: slave_latency */ - conn_param.timeout_multiplier = 160*32; /* param 4: timeout_multiplier */ - errcode_t ret = gap_ble_connect_param_update(&conn_param); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"gap ble update connection parameters ret: %u\n", ret); } } // uint16_t interval; /*!< @if Eng interval @@ -1240,8 +1223,16 @@ errcode_t svr_ble_bt_gatts_noyify(uint8_t *data, uint16_t data_len)//这里是 ret=gatts_notify_indicate(g_ble_server_id, g_ble_conn_id, &data_info); if(ret!=ERRCODE_SUCC) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gatts_notify_indicate ret:0x%x. serverid:%u,conn_id:%u,handle:%u.data_len:%d", ret, g_ble_server_id, - g_ble_conn_id, g_ble_server_handle,data_len); + { + msleep(200); + ret=gatts_notify_indicate(g_ble_server_id, g_ble_conn_id, &data_info); + if(ret!=ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gatts_notify_indicate ret:0x%x. serverid:%u,conn_id:%u,handle:%u.data_len:%d", ret, g_ble_server_id, + g_ble_conn_id, g_ble_server_handle,data_len); + ble_set_ai_Answer_str("BLE NOTIF ERROR",5); + } + } } } return ret; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 1b2b38d83..1e62501e4 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -1122,6 +1122,9 @@ static uint32_t BLE_TEST(uint8_t *para, uint32_t paraLen, char *strCommonCmd) case 18: test_paly(type_2); break; + case 19: + uapi_ble_connect_param_update(type_2); + break; default: break; -- 2.17.1