From: hcj <1224667075@qq.com> Date: Sat, 27 Jul 2024 02:13:56 +0000 (+0800) Subject: 将ACL断连时使用接口改为回连接口,确报可以连接上HFP(有BUG会同时连上A2DP) X-Git-Tag: release_V1.2.70_20241020_135402~741^2~5 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=12d50a5f878d1b58656a91896de124de05f4271e;p=mirrors%2FFD230.git 将ACL断连时使用接口改为回连接口,确报可以连接上HFP(有BUG会同时连上A2DP) --- 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 679b45112..a38074ac4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h @@ -138,6 +138,8 @@ int uapi_a2dp_snk_get_device_connect_state(void); int uapi_a2dp_snk_connect(void); int uapi_a2dp_snk_disconnect(void); int uapi_disconnect_remote_device(void); +int uapi_get_acl_connect_state(void); +int uapi_set_acl_connect_hfp(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 7ea5b313e..b6c0d5902 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -968,7 +968,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; // 回调:ACL连接状态上报 void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) { @@ -976,6 +978,16 @@ void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + ALC_State_flag=state; + + if(ALC_connect_hfp_flag && state==GAP_ACL_STATE_CONNECTED) + { + int ret= hfp_hf_connect(bdAddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt hfp_hf_connect ret %X", ret); + ALC_connect_hfp_flag=0; + } + + if ((gap_get_device_class(bdAddr) & 0x200) != 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); return; @@ -1629,12 +1641,27 @@ int uapi_disconnect_remote_device() get_phone_addr(&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); } return 0; } - + + +int uapi_get_acl_connect_state() +{ + if( ALC_State_flag==GAP_ACL_STATE_DISCONNECTED )//|| ALC_State_flag ==GAP_ACL_STATE_LE_DISCONNECTED) + return 0; + else + return 1; +} + +int uapi_set_acl_connect_hfp() +{ + ALC_connect_hfp_flag=1; + return 0; +} // /////////////////////////////////////////HFP hf端 代码/////////////////////////////////////////////////// // int uapi_HFP_hf_connect() diff --git a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp index 90bfbd696..0f65679e0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp @@ -1874,24 +1874,26 @@ int uapi_hfp_connect(void) int ret; bd_addr_t bdaddr={0}; get_phone_addr(&bdaddr); - // if(false==bt_is_acl_connected(&bdaddr)) - // { - // ret= gap_connect_remote_device(&bdaddr); - - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[bt_is_acl_connected] ret:%X", ret); - // } - // else - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[bt_is_acl_connected is true"); - // } - // ret= hfp_hf_send_dtmf_tone(&bdaddr,'1'); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[hfp_hf_send_dtmf_tone] ret:%X", ret); + if(false==OHOS::uapi_get_acl_connect_state()) + { + // ret= gap_connect_remote_device(&bdaddr); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[gap_connect_remote_device] ret:%X", ret); + // ret=OHOS::uapi_set_acl_connect_hfp(); + ret=gap_reconnect_media_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[gap_connect_remote_device] ret:%X", ret); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[bt_is_acl_connected is true"); + ret = hfp_hf_connect(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[uapi_hfp_connect] ret:%X", ret); + } + + - ret = hfp_hf_connect(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x %02x %02x %02x g_bdAddr.type: %x\n", g_bdAddr.addr[3], g_bdAddr.addr[2], g_bdAddr.addr[1], g_bdAddr.addr[0], g_bdAddr.type); /* 3 2 1 0 idx */ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[uapi_hfp_connect] ret:%X", ret); return ret; }