From edb3b0a384f59a8a23a17c5bbae7ce2c9c763a80 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Mon, 12 Aug 2024 16:24:04 +0800 Subject: [PATCH] =?utf8?q?A2DP=20=E5=92=8CHFP=20uapi=E6=8E=A5=E5=8F=A3BUG?= =?utf8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../bluetooth/include/BluetoothModel.h | 3 +- .../nativeui/bluetooth/src/BluetoothModel.cpp | 58 +++++++++++++++---- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h index 64fe97568..c7917c1c2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h @@ -141,7 +141,8 @@ int uapi_disconnect_remote_device(void); int uapi_get_acl_connect_state(void); int uapi_set_acl_connect_hfp(void); void uapi_connect_pbap_pce(void); - +int uapi_reconnect(void); +int uapi_set_acl_connect_A2DP(void); #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index 9b8f13a3a..06b5a88be 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -205,8 +205,8 @@ void bluetooth_enable_all(void) // bts_feature.bt_auto_reconnect_closed = 0; // ret = bts_set_features(&bts_feature); // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt bts_set_features ret = %u", ret); - // gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 1, GAP_BLE_GAP_SECURITY_MODE1_LEVEL3 }; - gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 0, GAP_BLE_GAP_SECURITY_MODE1_LEVEL2 }; + gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 1, GAP_BLE_GAP_SECURITY_MODE1_LEVEL3 }; + //gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 0, GAP_BLE_GAP_SECURITY_MODE1_LEVEL2 }; ret = gap_ble_set_sec_param(&sec_param); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt gap_ble_set_sec_param ret = %u", ret); /**开始ble广播*/ @@ -974,6 +974,9 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned static uint8_t ALC_State_flag=0; static uint8_t ALC_connect_hfp_flag=0; + +static uint8_t ALC_connect_A2DP_flag=0; + // 回调:ACL连接状态上报 void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) { @@ -989,7 +992,14 @@ void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt hfp_hf_connect ret %X", ret); ALC_connect_hfp_flag=0; } - + + if(ALC_connect_A2DP_flag && state==1) + { + // int ret= hfp_hf_connect(bdAddr); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt hfp_hf_connect ret %X", ret); + uapi_a2dp_snk_connect(); + ALC_connect_A2DP_flag=0; + } if ((gap_get_device_class(bdAddr) & 0x200) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); @@ -1634,9 +1644,12 @@ int uapi_a2dp_snk_get_device_connect_state() int uapi_a2dp_snk_connect() { - int ret = a2dp_snk_connect(&g_bd_addr); + bd_addr_t bdaddr={0}; + get_phone_addr(&bdaddr); + + int ret = a2dp_snk_connect(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x g_bd_addr.type: %x\n", - g_bd_addr.addr[3], g_bd_addr.addr[2], g_bd_addr.addr[1], g_bd_addr.addr[0], g_bd_addr.type); /* 3 2 1 0 idx */ + bdaddr.addr[3], bdaddr.addr[2], bdaddr.addr[1], bdaddr.addr[0], bdaddr.type); /* 3 2 1 0 idx */ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %x\n", ret); return ret; @@ -1644,7 +1657,11 @@ int uapi_a2dp_snk_connect() int uapi_a2dp_snk_disconnect() { - int ret = a2dp_snk_disconnect(&g_bd_addr); + + bd_addr_t bdaddr={0}; + get_phone_addr(&bdaddr); + + int ret = a2dp_snk_disconnect(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %d\n", ret); return ret; } @@ -1653,12 +1670,13 @@ int uapi_disconnect_remote_device() { bd_addr_t bdaddr={0}; get_phone_addr(&bdaddr); - if (bt_is_acl_connected(&bdaddr)) - { + + // if (bt_is_acl_connected(&bdaddr)) + // { - int ret = gap_disconnect_remote_device(&bdaddr); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_close_all gap_disconnect_remote_device ret = %u", ret); - } + int ret = gap_disconnect_remote_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth_close_all gap_disconnect_remote_device ret = %u", ret); + //} return 0; } @@ -1676,6 +1694,24 @@ int uapi_set_acl_connect_hfp() ALC_connect_hfp_flag=1; return 0; } + +int uapi_set_acl_connect_A2DP() +{ + ALC_connect_A2DP_flag=1; + return 0; +} + + +int uapi_reconnect(void) +{ + bd_addr_t bdaddr={0}; + get_phone_addr(&bdaddr); + int ret=gap_reconnect_media_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ret(int): %X\n", ret); + + return 0; +} + // /////////////////////////////////////////HFP hf端 代码/////////////////////////////////////////////////// // int uapi_HFP_hf_connect() -- 2.17.1