From: hcj <1224667075@qq.com> Date: Sat, 20 Jul 2024 01:47:22 +0000 (+0800) Subject: 增加 连接状态改变 X-Git-Tag: release_V1.2.70_20241020_135402~745^2~30 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=946ffa9288e7924430fd47025cf4f32474eaba65;p=mirrors%2FFD230.git 增加 连接状态改变 --- 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 83b267ba7..f7935fd6d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -36,7 +36,8 @@ #include "custom_runtime.h" #include "bleService.h" //#include "hfp_hf_service.h" - +#include "ui_service.h" +#include "PhoneService.h" #ifdef SUPPORT_AT_OHOSFWK #include "BluetoothWrapper.h" #endif @@ -197,11 +198,12 @@ void bluetooth_enable_all(void) errcode_t ret; // 设置自动回连,ios一键双连依赖此配置 - bts_feature_t bts_feature = { 0 }; - 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 }; + // bts_feature_t bts_feature = { 0 }; + // bts_feature.bt_auto_reconnect_closed = 1; + // 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 }; ret = gap_ble_set_sec_param(&sec_param); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt gap_ble_set_sec_param ret = %u", ret); @@ -1276,13 +1278,13 @@ static errcode_t BtA2dpSnkStartAcceptTimer(void) static int32_t BtA2dpSnkAudioCreate() { #if MEDIA_A2DP_SNK_INTERFACE - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audioFormat %d channelCount %d sampleRate %d \n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "audioFormat %d channelCount %d sampleRate %d \n", g_audio_format_config.audioFormat, g_audio_format_config.channelCount, g_audio_format_config.sampleRate); int32_t ret = AudioManagerA2dpSinkSetParam(g_audio_format_config); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkSetParam ret %x\n", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkSetParam ret %x\n", ret); ret = AudioManagerA2dpSinkCreate(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkCreate ret %x\n", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkCreate ret %x\n", ret); #endif /* 起定时器接受音乐开始请求 */ (void)BtA2dpSnkStartAcceptTimer(); @@ -1304,6 +1306,22 @@ static void BtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x conn_state: %x\n", bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ (void)memcpy_s(&g_bd_addr, sizeof(bd_addr_t), bd_addr, sizeof(bd_addr_t)); + if(conn_state==PROFILE_STATE_DISCONNECTING || conn_state==PROFILE_STATE_DISCONNECTED) + { + if(0==uapi_a2dp_snk_get_device_connect_state() && 0==uapi_hfp_connect_state()) + { + SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + } + } + else if (conn_state==PROFILE_STATE_CONNECTING || conn_state==PROFILE_STATE_CONNECTED) + { + SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); + } + + + } 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 9c1b0f1e0..f7e132cdf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phoneservice/src/PhoneService.cpp @@ -26,11 +26,11 @@ #include "ui_service.h" #include "msg_center_msg.h" #include "cat1_server_hal.h" - +#include "BluetoothModel.h" #ifdef __cplusplus extern "C" { #endif - +#include "bleService.h" #define CALL_LOG_PATH "/user/userdata/calllog.bin" #define CALL_TMP_LOG_PATH "/user/userdata/calltmplog.bin" #define CALL_LOG_DIR "/user/userdata" @@ -608,8 +608,12 @@ static void ConnStateChanged(const bd_addr_t *bdAddr, profile_connect_state_t st case PROFILE_STATE_DISCONNECTED: // 蓝牙断开连接 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnStateChanged] BT disconnected"); BtDisconnectedPro(); - SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); - SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + if(0==OHOS::uapi_a2dp_snk_get_device_connect_state() && 0==uapi_hfp_connect_state()) + { + SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + } + break; default: break; @@ -1868,9 +1872,11 @@ int uapi_hfp_disconnect(void) int uapi_hfp_connect(void) { int ret; - if(false==bt_is_acl_connected(&g_bdAddr)) + bd_addr_t bdaddr={0}; + get_phone_addr(&bdaddr); + if(false==bt_is_acl_connected(&bdaddr)) { - ret= gap_connect_remote_device(&g_bdAddr); + ret= gap_connect_remote_device(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[bt_is_acl_connected] ret:%X", ret); } @@ -1878,9 +1884,9 @@ int uapi_hfp_connect(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[bt_is_acl_connected is true"); } - + - ret = hfp_hf_connect(&g_bdAddr); + 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 */ diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 1494c0c70..7dbea4432 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -74,6 +74,16 @@ extern "C" { #include #include +void ble_connect_ok(void) +{ + SendMsgToUIService(PHONE_CONNECTED_TO_UI, 0, nullptr, 0); +} + +void ble_disconnect_ok(void) +{ + SendMsgToUIService(PHONE_DISCONNECTED_TO_UI, 0, nullptr, 0); +} + @@ -1484,7 +1494,7 @@ void Set_heart_cmd(msg_get_heart_set_param_info_t *data) { printf("set_condigData_Int data->max_min %d\r\n",data->max_min); - p_ConfigModel->set_condigData_Bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN,data->max_min); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN,data->max_min); p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE,data->heart); } @@ -1497,7 +1507,7 @@ void Get_heart_cmd(msg_get_heart_set_param_info_t *data) data->frequence = p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED); data->remind_on = p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_REMIND); - data->max_min= p_ConfigModel->get_configData_bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN); + data->max_min= p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_MAX_MIN); printf("Get_heart_cmd data->max_min %d\r\n",data->max_min); data->heart = p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_THRESHOLD_VALUE); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index 7394c78f5..6a75ac26d 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -322,6 +322,11 @@ void ble_add_message_index(uint32_t old_index); uint32_t ble_get_message_index(void); +///////////////////////服务状态//////////////////////////// +void ble_connect_ok(void); + +void ble_disconnect_ok(void); + #ifdef __cplusplus #if __cplusplus }