修改蓝牙AI对话的功能逻辑
authordxy <1731678236qq.com>
Tue, 9 Sep 2025 06:03:13 +0000 (14:03 +0800)
committerdxy <1731678236qq.com>
Tue, 9 Sep 2025 06:03:13 +0000 (14:03 +0800)
2.code/1.sdk/apps/BK_app/BK_drive/bk_audio.c
2.code/1.sdk/apps/BK_app/bk_app.c

index 91cab3d..0d8ea0b 100644 (file)
@@ -503,9 +503,10 @@ int read_iis_play_data(char *data, int len)
 }
 
 
-
+extern u8 check_bt_active;
 void open_bt_audio(void)//打开蓝牙通话
 {
+    check_bt_active=0;
     BT_state = 1;
     __set_bt_esco_by_watch(1);
     user_emitter_cmd_prepare(USER_CTRL_CONN_SCO,0,NULL);
@@ -514,8 +515,11 @@ void open_bt_audio(void)//打开蓝牙通话
 }
 void close_bt_audio(void)
 {
-    printf("close_bt_audio");
-    user_emitter_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP,0,NULL);
+    printf("close_bt_audio get_call_status:%d",get_call_status());
+    if(get_call_status() != BT_CALL_HANGUP){ //如果是主动挂断的不需要再重复挂断
+        user_emitter_cmd_prepare(USER_CTRL_HFP_CALL_HANGUP,0,NULL);
+    }
+        
 }
 #if EN_AEC
 //extern void uart_demo();
index b8d9a0b..238563a 100644 (file)
@@ -10,6 +10,7 @@
 #define LOG_CLI_ENABLE
 #include "debug.h"
 #include "key_event_deal.h"
+#include "btstack/avctp_user.h"
 static char AI_start_flag = 0;
 #if(USR_KWS_ALG == KWS_BK)
 #include "imsl_vad.h"
@@ -76,16 +77,22 @@ void AI_VC_1S_cb(void *p)
 {
     bk_app_send_smg(AI_VC_1S_EVENT,NULL,0);
 }
+u8 check_bt_active = 5;
+extern u8 bt_connect;
 void AI_VC_1S_event(void)
 {
     int cat1_io = gpio_read(IO_PORTA_10) ;
-    printf("AI_VC_1S_cb:%d %d %d",cat1_io,BT_state,esco_flag);
-    if(BT_state)
+    int call_state = get_call_status();
+    
+    printf("AI_VC_1S_cb:%d %d %d call_state:%d",cat1_io,BT_state,esco_flag,call_state);
+    if(BT_state && bt_connect == 2) // 打开了蓝牙麦并且蓝牙耳机已经连上了
     {
-        if(esco_flag ==0 ){
+        check_bt_active--; //通话建立连接没有连上的情况等待5s重新连接
+        if(esco_flag ==0 && check_bt_active==0){
+            printf("check_bt_active:%d",check_bt_active);
+            check_bt_active=5;
             bk_app_send_smg(OPEN_CALL,NULL,0);//会关闭定时器 open_bt_audio(0)
         }
-        
     }
    
     
@@ -189,7 +196,22 @@ void bk_app_send_smg(bk_app_msg_event event,char *data,int data_len)
             }
         }
         
-        os_taskq_post_msg("bk_app_task", 3, event,(int)data_tmp, data_len);
+        int ret = os_taskq_post_msg("bk_app_task", 3, event,(int)data_tmp, data_len);
+        printf("event:%d ret:%d--------------------1",event,ret);
+        if(ret)
+        {
+            u8 count=20;
+            while (count--)
+            {
+                int ret = os_taskq_post_msg("bk_app_task", 3, event,(int)data_tmp, data_len);
+                if(!ret){
+                    printf("event:%d ret:%d--------------------2",event,ret);
+                    break;
+                }
+                printf("event:%d ret:%d--------------------3",event,ret);
+                os_time_dly(1);
+            }
+        }
 }
 void bk_app_task(void *p)
 {
@@ -198,6 +220,7 @@ void bk_app_task(void *p)
     log_info("%s:RUN BK_VERSIONS:%s!!!!!!\n",__FUNCTION__,BK_VERSIONS);
     log_info("%s:RUN BK_VERSIONS:%s!!!!!!\n",__FUNCTION__,BK_VERSIONS);
     get_ble_switch_imei_timer_init();
+    os_time_dly(10);
     // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
     // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
     // log_info("%s:这是ota升级测试程序 !!!!!!\n",__FUNCTION__);
@@ -297,11 +320,13 @@ void bk_ALG_send_smg(bk_ALG_msg_event event,char *data,int data_len)
 //蓝牙耳机切换事件回调
 void BT_State_Change_cb(void)
 {
+
     os_time_dly(100);
-    if(esco_flag == 1){
+    printf("BT_State_Change_cb:%d",get_call_status());
+    if(get_call_status() == BT_CALL_ACTIVE)
+    {   
         bk_app_send_smg(CLOSE_BT_AUDIO_EVENT,NULL,0);
     }
-    
     bk_app_send_smg(AI_CLOSE,NULL,0);
     bk_app_send_smg(AI_OPEN,NULL,0);
     // bk_app_send_smg(AI_KEY_PRESS,NULL,0);
@@ -313,18 +338,26 @@ void key_bt_hangup(void){
 }
 void key_bt_hangup_CB(void){
     os_time_dly(30);   
-    printf("esco_flag end:%d %d",esco_flag,bt_connect);
+    printf("esco_flag end:%d %d get_call_status:%d",esco_flag,bt_connect,get_call_status());
     if(bt_connect ==0) //蓝牙耳机已断开
         return; 
+    bk_app_send_smg(AI_CLOSE,NULL,0);
+    bk_app_send_smg(AI_OPEN,NULL,0);
     bk_app_send_smg(AI_KEY_PRESS,NULL,0);
 }
 //蓝牙耳机所有按键触发AI对话
 void all_key_bt_ai(void) //蓝牙耳机已连接不在通话中
 {
-    printf("all_key_bt_ai end:%d %d",esco_flag,AI_start_flag);
-    if(esco_flag){
-        return;
+    printf("all_key_bt_ai end:%d %d get_call_status:%d",esco_flag,AI_start_flag,get_call_status());
+    // if(esco_flag){
+    //     return;
+    // }
+    if(get_call_status() != BT_CALL_ACTIVE)
+    {
+        bk_app_send_smg(AI_CLOSE,NULL,0);
     }
+    
+    bk_app_send_smg(AI_OPEN,NULL,0);
     bk_app_send_smg(AI_KEY_PRESS,NULL,0);
 }
 //#include "rtc.h"
@@ -478,7 +511,7 @@ void bk_app_init(void)
     #if(USR_KWS_ALG != 0)
         err = task_create(bk_ALG_task, NULL, "bk_ALG_task");
     #endif
-    err = os_task_create(bk_app_task, NULL, 31, 512, 255, "bk_app_task");
+    err = os_task_create(bk_app_task, NULL, 3, 512, 512, "bk_app_task");
     //int err = task_create(bk_app_task, NULL, "bk_app_task");
     if (err != OS_ERR_NONE) {
         r_printf("creat fail %x\n", err);