From: hcj <1224667075@qq.com> Date: Wed, 14 Aug 2024 03:40:08 +0000 (+0800) Subject: br连接地址纠正 X-Git-Tag: release_V1.2.70_20241020_135402~670 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=8b9e83032010b0713aed12975a9b9aa9ac56d497;p=mirrors%2FFD230.git br连接地址纠正 --- 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 c7917c1c2..1857e0547 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h @@ -143,6 +143,7 @@ int uapi_set_acl_connect_hfp(void); void uapi_connect_pbap_pce(void); int uapi_reconnect(void); int uapi_set_acl_connect_A2DP(void); +void uapi_get_br_address(bd_addr_t *bdaddr); #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 54a52dd44..9981e57cf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -154,7 +154,7 @@ static int bluetooth_init_all(void) // ret = gap_ble_set_sec_param(&sec_params);//设置配对参数 发起配对弹窗 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, 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); @@ -174,7 +174,7 @@ static int bluetooth_init_all(void) // BtInitCallBacksEx(); //BLE // BtInitGatts(); //BLE - uapi_pbap_pce_reg_callback(); + //uapi_pbap_pce_reg_callback(); // BtInitSpp(); BtA2dpInit(); @@ -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广播*/ @@ -743,11 +743,16 @@ void BluetoothModel::BtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr) } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt BtGapDiscoveryResultCallback end"); } - +bd_addr_t BtGapPair_bdAddr={0}; void BtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapPairStatusChangedCallback addr: ****%02x%02x%02x%02x status: %d\n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairStatusChangedCallback addr: ****%02x%02x%02x%02x status: %d\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], status); /* addr下标 0 1 2 3 */ + memcpy(&BtGapPair_bdAddr,bdAddr,sizeof(bd_addr_t)); + uapi_a2dp_snk_connect(); + //uapi_a2dp_snk_connect(); + //a2dp_snk_connect(bdAddr); + if (status == GAP_PAIR_PAIRED) { if (ConnectPhonePresenter::GetInstance() != nullptr) { NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); @@ -757,13 +762,13 @@ void BtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) void BtGapPairRequestedCallback(const bd_addr_t *bdAddr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapPairRequestedCallback addr: ****%02x%02x%02x%02x\n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairRequestedCallback addr: ****%02x%02x%02x%02x\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* addr下标 0 1 2 3 */ } void BtGapPairConfirmedCallback(const bd_addr_t *bdAddr, int req_type, int number) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapPairConfirmedCallback addr: ****%02x%02x%02x%02x req_type: %d number: %d\n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairConfirmedCallback addr: ****%02x%02x%02x%02x req_type: %d number: %d\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], /* addr下标 0 1 2 3 */ req_type, number); } @@ -984,22 +989,23 @@ 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; - } + //ALC_State_flag=state; - 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(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(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"); @@ -1654,11 +1660,21 @@ int uapi_a2dp_snk_get_device_connect_state() return 0; } + +void uapi_get_br_address(bd_addr_t *bdaddr) +{ + if(BtGapPair_bdAddr.addr[0]==0 && BtGapPair_bdAddr.addr[1]==0 && + BtGapPair_bdAddr.addr[2]==0 && BtGapPair_bdAddr.addr[3]==0 ) + get_phone_addr(bdaddr); + else + memcpy(bdaddr,&BtGapPair_bdAddr,sizeof(bd_addr_t)); + +} int uapi_a2dp_snk_connect() { bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + uapi_get_br_address(&bdaddr); int ret = a2dp_snk_connect(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x g_bd_addr.type: %x\n", @@ -1672,7 +1688,7 @@ int uapi_a2dp_snk_disconnect() { bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + uapi_get_br_address(&bdaddr); int ret = a2dp_snk_disconnect(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %d\n", ret); @@ -1682,14 +1698,18 @@ int uapi_a2dp_snk_disconnect() int uapi_disconnect_remote_device() { bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + uapi_get_br_address(&bdaddr); - // if (bt_is_acl_connected(&bdaddr)) - // { + if (bt_is_acl_connected(&bdaddr)) + { int ret = gap_disconnect_remote_device(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth_close_all gap_disconnect_remote_device ret = %u", ret); - //} + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt_is_acl_connected bt_acl_is True"); + } return 0; } @@ -1718,7 +1738,7 @@ int uapi_set_acl_connect_A2DP() int uapi_reconnect(void) { bd_addr_t bdaddr={0}; - get_phone_addr(&bdaddr); + uapi_get_br_address(&bdaddr); int ret=gap_reconnect_media_device(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ret(int): %X\n", ret);