From: SnickerSun Date: Fri, 10 May 2024 04:07:00 +0000 (+0800) Subject: 经典蓝牙状态同步,修复a2dp snk 不能工作等问题。 X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~8^2~1 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=d5e85eac5702604d5ed66d974766e2a5a8034bc0;p=mirrors%2FFD230.git 经典蓝牙状态同步,修复a2dp snk 不能工作等问题。 --- 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 4a456775d..6e0539d05 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h @@ -127,6 +127,7 @@ void BtRemoteNameChangedCallback(const bd_addr_t *bdAddr, const unsigned char *d void BtIsAcceptConnOnSafeModeCallback(const bd_addr_t *bd_addr, bool *res); void BtInitCallBacks(void); void BtInitCallBacksEx(void); +void BtA2dpInit(void); void BtInitGatts(void); void BtInitSpp(void); void BleAdvStart(void); 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 1af445392..c415098f6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -1173,8 +1173,17 @@ static a2dp_snk_callbacks_t g_a2dp_snk_callbacks = { BtA2dpSnkPlayingStateChangedCb, BtA2dpSnkConfigChangedCb }; - -void BtInitCallBacks() +void BtA2dpInit(void) +{ + /* a2dp source */ + g_a2dpSrcCallbacks.connectstate_changed_cb = A2dpSrcConnectstateChanged; + g_a2dpSrcCallbacks.configuration_changed_cb = A2dpSrcConfigureChanged; + g_a2dpSrcCallbacks.playing_state_changed_cb = A2dpSrcPlayingStateChanged; + a2dp_src_register_callbacks(&g_a2dpSrcCallbacks); + /* a2dp sink */ + a2dp_snk_register_callbacks(&g_a2dp_snk_callbacks); +} +void BtInitCallBacks(void) { g_btGapCallBacks.discovery_result_callback = BtGapDiscoveryResultCallback; g_btGapCallBacks.discovery_state_changed_callback = BtGapDiscoveryStateChangedCallback; @@ -1187,12 +1196,7 @@ void BtInitCallBacks() g_btGapCallBacks.pair_confiremed_callback = BtGapPairConfirmedCallback; gap_register_callbacks(&g_btGapCallBacks); - g_a2dpSrcCallbacks.connectstate_changed_cb = A2dpSrcConnectstateChanged; - g_a2dpSrcCallbacks.configuration_changed_cb = A2dpSrcConfigureChanged; - g_a2dpSrcCallbacks.playing_state_changed_cb = A2dpSrcPlayingStateChanged; - a2dp_src_register_callbacks(&g_a2dpSrcCallbacks); - /* a2dp sink */ - a2dp_snk_register_callbacks(&g_a2dp_snk_callbacks); + } void BtInitCallBacksEx() diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp index 19adeb548..e7012e0dc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp @@ -82,10 +82,12 @@ namespace OHOS if (it->second == "HFP") { ConfigModel::GetInstance()->SetHFPState(true); + enable_hfp_service(true); } else if (it->second == "A2DP") { ConfigModel::GetInstance()->SetA2DPState(true); + enable_a2dp_service(true); } } else @@ -94,10 +96,12 @@ namespace OHOS if (it->second == "HFP") { ConfigModel::GetInstance()->SetHFPState(false); + enable_hfp_service(false); } else if (it->second == "A2DP") { ConfigModel::GetInstance()->SetA2DPState(false); + enable_a2dp_service(false); } } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h index b0d9c404a..c6e2d3f2d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -68,6 +68,7 @@ namespace OHOS CONFIGMODEL_ITEM_MOTIONRECOGNITION,//运动识别 CONFIGMODEL_ITEM_HFP, //通话蓝牙开关 CONFIGMODEL_ITEM_A2DP,//媒体蓝牙开关 + CONFIGMODEL_ITEM_SPP,//SPP蓝牙开关 CONFIGMODEL_ITEM_TRANING_FREQ,//训练实时数据上传频率 CONFIGMODEL_ITEM_TRANING_AUTO,//开启关闭自动获取实时数据 CONFIGMODEL_ITEM_TRAINING_HEART_MAX,//训练最高心率 @@ -230,6 +231,7 @@ namespace OHOS {ConfigDataType::DATATYPE_BOOL, "MotionRecognition", "false" },// CONFIGMODEL_ITEM_MOTIONRECOGNITION {ConfigDataType::DATATYPE_BOOL, "HFP", "false" },// CONFIGMODEL_ITEM_HFP {ConfigDataType::DATATYPE_BOOL, "A2DP", "false" },// CONFIGMODEL_ITEM_A2DP + {ConfigDataType::DATATYPE_BOOL, "SPP", "true" },// CONFIGMODEL_ITEM_SPP,//SPP蓝牙开关 {ConfigDataType::DATATYPE_INT, "traningfreq", "10" },// CONFIGMODEL_ITEM_TRANING_FREQ //训练实时数据上传频率//单位秒 {ConfigDataType::DATATYPE_BOOL, "traningauto", "0" },//CONFIGMODEL_ITEM_TRANING_AUTO,//开启关闭自动获取实时数据 {ConfigDataType::DATATYPE_INT, "traningheart", "190" },//CONFIGMODEL_ITEM_TRAINING_HEART_MAX//训练最高心率 diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h index 4041c76d1..caa10bdd2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h @@ -73,6 +73,14 @@ void initialize4GCapability(void); * @brief 初始化运动识别开关 */ void initializeMotionRecognition(void); + + +bool get_SPP_switch(void); + +bool get_HFP_switch(void); + +bool get_A2DP_switch(void); + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp index 57cf3e384..293af737f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp @@ -919,6 +919,28 @@ void initializeMotionRecognition(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "initializeMotionRecognition"); bool isopen = OHOS::ConfigModel::GetInstance()->GetMotionRecognition(); } + + +bool get_SPP_switch(void) +{ + bool isopen = OHOS::ConfigModel::GetInstance()->get_configData_bool(OHOS::ConfigModel::CONFIGMODEL_ITEM_SPP); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getSPPSwitch %d",isopen); + return isopen; +} + +bool get_HFP_switch(void) +{ + bool isopen = OHOS::ConfigModel::GetInstance()->GetHFPState(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getHFPSwitch %d",isopen); + return isopen; +} + +bool get_A2DP_switch(void) +{ + bool isopen = OHOS::ConfigModel::GetInstance()->GetA2DPState(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getA2DPSwitch %d",isopen); + return isopen; +} #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index e73549899..ef167b77a 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -76,7 +76,7 @@ static uint8_t exit_alipay_gui = 0; static gap_ble_callbacks_t g_ble_gapble_cbs; static gatts_callbacks_t g_ble_gatts_cbs; static gap_call_backs_t g_btGapCallBacks; -static a2dp_src_callbacks_t g_a2dpSrcCallbacks; + static bool g_ble_adv_start_state = false; uint16_t g_ble_server_id = 1; @@ -100,8 +100,6 @@ uint8_t Bleconnect = 0;//蓝牙默认是断开 0 1 为连接 uint8_t devpair_state = 0;//设备配对状态 0 未配对 1已配对成功 uint8_t bond_flag = 0;//绑定标识 uint16_t ble_nus_max_data_len = SDK_BLE_MTU_MIN - 3; -#define A2DP_STREAM_ACCEPT_TIMER_PERIOD 500 -static osal_timer g_a2dp_stream_accept_timer = {NULL, NULL, 0, 0}; uint16_t data2ae3Cmd = 0;//2ae3短指令特征值 uint16_t data2ae4Cmd = 0; @@ -1020,287 +1018,6 @@ static void svr_gap_ble_auth_complete_callback(uint16_t conn_id, const bd_addr_t sendParieSuccess(1,&phone_addr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "svr_gap_ble_auth_complete_callback %x %x %x %x %x %x\r\n",addr->addr[0],addr->addr[1],addr->addr[2],addr->addr[3],addr->addr[4],addr->addr[5]); } -// 回调: gap_read_remote_rssi_value 接口的数据上报 -static void svr_gap_ble_ReadRemoteRssiEventCallback(const bd_addr_t *bdAddr, int rssi, int status) -{ - UNUSED(status); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapReadRemoteRssiEventCallback 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 */ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt BtGapReadRemoteRssiEventCallback SetSortCaseRssi: %d status: %d", rssi, status); -} - -// 回调:发现状态变化上报/扫描结束 -static void svr_gap_ble_DiscoveryStateChangedCallback(int status) -{ - UNUSED(status); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt BtGapDiscoveryStateChangedCallback %d", status); -} - - -static void svr_gap_ble_PairStatusChangedCallback(const bd_addr_t *bdAddr, int status) -{ - WEARABLE_LOGD(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 */ - if (status == GAP_PAIR_PAIRED) { - - } -} - -static void svr_gap_ble_RequestedCallback(const bd_addr_t *bdAddr) -{ - WEARABLE_LOGD(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 */ -} - -static void svr_gap_ble_ConfirmedCallback(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", - bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], /* addr下标 0 1 2 3 */ - req_type, number); -} - -// 回调:扫描结果处理/发现结果上报 -static void svr_gap_ble_DiscoveryResultCallback(const bd_addr_t *bdAddr) -{ - if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapDiscoveryResultCallback: Mobile Phone Device"); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapDiscoveryResultCallback"); - if (bdAddr == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr nullptr"); - return; - } -} - -// 回调:ACL连接状态上报 -static void svr_gap_br_AclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); - 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 */ - if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); - return; - } - if(state == GAP_ACL_STATE_DISCONNECTED || state == GAP_ACL_STATE_LE_DISCONNECTED) - { - // gap_remove_all_pairs(); - } - -} -// 回调:远端设备名称变化 -static void svr_gap_ble_RemoteNameChangedCallback(const bd_addr_t *bdAddr, const unsigned char *deviceName, unsigned char length) -{ - if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtRemoteNameChangedCallback: Mobile Phone Device"); - return; - } - if (bdAddr == NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtRemoteNameChangedCallback addr nullptr"); - return; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtRemoteNameChangedCallback 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 */ - -} - -static void svr_gap_ble_IsAcceptConnOnSafeModeCallback(const bd_addr_t *bdAddr, bool *res) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtIsAcceptConnOnSafeModeCallback addr: %02x%02x%02x%02x%02x%02x set *res true", - bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* addr下标 3 4 5 */ - bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* addr下标 0 1 2 */ - *res = true; -} - -static void A2dp_SrcConnectstateChanged(bd_addr_t *bdAddr, int connState) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connectStateChangedCallback addr: %02x%02x%02x%02x%02x%02x connState: %x", - bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ - bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], connState); /* 2 1 0 idx */ - if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connectstateChangedCb: Mobile Phone Device"); - return; - } - if (connState == PROFILE_STATE_CONNECTED) { - avrcp_ct_connect(bdAddr); - // PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_CONNECTED); - } - - if (connState == PROFILE_STATE_DISCONNECTED) { - // PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_DISCONNECTED); - } -} - - -static void A2dp_SrcPlayingStateChanged(bd_addr_t *bdAddr, int playState) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "A2dpSrcPlayingStateChangedCallback addr: %02x%02x%02x%02x%02x%02x playState: %x", - bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ - bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], playState); /* 2 1 0 idx */ -} - -static void A2dp_SrcConfigureChanged(bd_addr_t *bdAddr, a2dp_codec_info_t *info) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "A2dpSrcConfigurationChangedCallback addr: %02x%02x%02x%02x%02x%02x ", - bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ - bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* 2 1 0 idx */ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "codec_priority: %04x codec_type: %04x sample_rate: %02x bits_per_sample: %02x channel_mode: %02x ", - info->codec_priority, info->codec_type, info->sample_rate, info->bits_per_sample, info->channel_mode); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "codec_specific1: %04x codec_specific2: %04x codec_specific3: %04x codec_specific4: %04x", - info->codec_specific1, info->codec_specific2, info->codec_specific3, info->codec_specific4); -} -static void BtA2dpSnkAcceptTimerStop(void) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "stop timer\n"); - if (g_a2dp_stream_accept_timer.timer != NULL) { - (void)osal_timer_stop(&g_a2dp_stream_accept_timer); - (void)osal_timer_destroy(&g_a2dp_stream_accept_timer); - g_a2dp_stream_accept_timer.timer = NULL; - } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "stop timer success!\n"); -} - -static void BtA2dpSnStartAcceptHandler(unsigned long data) -{ - UNUSED(data); - bd_addr_t active_bd_addr = a2dp_snk_get_active_device(); - a2dp_snk_start_accept(&active_bd_addr); - BtA2dpSnkAcceptTimerStop(); -} - -static errcode_t BtA2dpSnkStartAcceptTimer(void) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "start timer\n"); - if (g_a2dp_stream_accept_timer.timer != NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timer is running"); - return ERRCODE_SUCC; - } - - g_a2dp_stream_accept_timer.handler = BtA2dpSnStartAcceptHandler; - g_a2dp_stream_accept_timer.interval = A2DP_STREAM_ACCEPT_TIMER_PERIOD; - - int32_t timer_ret = osal_timer_init(&g_a2dp_stream_accept_timer); - if (timer_ret != EOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "create timer error! ret: %x\n", timer_ret); - BtA2dpSnkAcceptTimerStop(); - return ERRCODE_FAIL; - } - timer_ret = osal_timer_start(&g_a2dp_stream_accept_timer); - if (timer_ret != EOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "start timer error! ret: %x\n", timer_ret); - BtA2dpSnkAcceptTimerStop(); - return ERRCODE_FAIL; - } - return ERRCODE_SUCC; -} - -static int32_t BtA2dpSnkAudioCreate() -{ -#if MEDIA_A2DP_SNK_INTERFACE - WEARABLE_LOGI(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); - ret = AudioManagerA2dpSinkCreate(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkCreate ret %x\n", ret); -#endif - /* 起定时器接受音乐开始请求 */ - (void)BtA2dpSnkStartAcceptTimer(); - return 0; -} - -static int32_t BtA2dpSnkAudioDestroy() -{ -#if MEDIA_A2DP_SNK_INTERFACE - int32_t ret = AudioManagerA2dpSinkDestroy(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkDestroy ret %x\n", ret); -#endif - return 0; -} - - - -static void BtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) -{ - if(conn_state == 4)//取消配对 - { - - }else if(conn_state == 2)//配对成功 发送配对成功的指令 手机mac地址 - { - // sendParieSuccess(); - } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtA2dpSnkConnectStateChangedCb addr: ****%02x%02x%02x%02x%02x%02x conn_state: %x\n", - bd_addr->addr[5],bd_addr->addr[4],bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ -} - -static void BtA2dpSnkStartStreamReqCb(bd_addr_t *bd_addr) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x \n", - bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* 3 2 1 0 idx */ - BtA2dpSnkAudioCreate(); -} - -static void BtA2dpSnkPlayingStateChangedCb(bd_addr_t *bd_addr, int playing_state) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x playing_state: %x\n", - bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], playing_state); /* 3 2 1 0 idx */ - if (playing_state == A2DP_NOT_PLAYING) { - BtA2dpSnkAudioDestroy(); - } -} - -static void BtA2dpSnkConfigChangedCb(bd_addr_t *bd_addr, a2dp_snk_codec_info_t *info) -{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x ", - bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* 3 2 1 0 idx */ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, - "codec_priority: %04x codec_type: %04x sample_rate: %02x bits_per_sample: %02x channel_mode: %02x", - info->codec_priority, info->codec_type, info->sample_rate, info->bits_per_sample, info->channel_mode); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, - "codec_specific1: %04x codec_specific2: %04x codec_specific3: %04x codec_specific4: %04x\n", - (unsigned int)info->codec_specific1, - (unsigned int)info->codec_specific2, - (unsigned int)info->codec_specific3, - (unsigned int)info->codec_specific4); -#if MEDIA_A2DP_SNK_INTERFACE - if (info->codec_type == A2DP_SNK_CODEC_TYPE_AAC) { - g_audio_format_config.audioFormat = AAC_LC; - } else { - g_audio_format_config.audioFormat = SBC; - } - /* channel count 1 or 2 */ - g_audio_format_config.channelCount = (info->channel_mode == A2DP_SNK_CODEC_CHANNEL_MODE_NONE ? 1 : 2); - - switch (info->sample_rate) { - case A2DP_SNK_CODEC_SAMPLE_RATE_48000: - g_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE48000; - break; - case A2DP_SNK_CODEC_SAMPLE_RATE_88200: - g_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE88200; - break; - case A2DP_SNK_CODEC_SAMPLE_RATE_96000: - g_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE96000; - break; - default: - g_audio_format_config.sampleRate = BT_AUDIO_A2DP_SMAPLE_RATE44100; - break; - } - WEARABLE_LOGI(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); -#endif -} - -static a2dp_snk_callbacks_t g_a2dp_snk_callbacks = { - BtA2dpSnkConnectStateChangedCb, - BtA2dpSnkStartStreamReqCb, - BtA2dpSnkPlayingStateChangedCb, - BtA2dpSnkConfigChangedCb -}; void svr_ble_btcallback_reg(void)//ble基础通讯服务注册回调函数 { @@ -1311,24 +1028,7 @@ void svr_ble_btcallback_reg(void)//ble基础通讯服务注册回调函数 sec_params.sc_mode = GAP_BLE_GAP_SECURITY_MODE1_LEVEL2; errcode_t ret = gap_ble_set_sec_param(&sec_params);//设置配对参数 发起配对弹窗 - g_btGapCallBacks.discovery_result_callback = svr_gap_ble_DiscoveryResultCallback; - g_btGapCallBacks.discovery_state_changed_callback = svr_gap_ble_DiscoveryStateChangedCallback; - g_btGapCallBacks.acl_state_changed_callbak = svr_gap_br_AclStateChangedCallback; - g_btGapCallBacks.read_remote_rssi_event_callback = svr_gap_ble_ReadRemoteRssiEventCallback; - g_btGapCallBacks.remote_name_changed_callback = svr_gap_ble_RemoteNameChangedCallback; - g_btGapCallBacks.is_accept_conn_on_safe_mode_callback = svr_gap_ble_IsAcceptConnOnSafeModeCallback; - g_btGapCallBacks.pair_status_changed_callback = svr_gap_ble_PairStatusChangedCallback; - g_btGapCallBacks.pair_requested_callback = svr_gap_ble_RequestedCallback; - g_btGapCallBacks.pair_confiremed_callback = svr_gap_ble_ConfirmedCallback; - - gap_register_callbacks(&g_btGapCallBacks); - - g_a2dpSrcCallbacks.connectstate_changed_cb = A2dp_SrcConnectstateChanged; - g_a2dpSrcCallbacks.configuration_changed_cb = A2dp_SrcConfigureChanged; - g_a2dpSrcCallbacks.playing_state_changed_cb = A2dp_SrcPlayingStateChanged; - a2dp_src_register_callbacks(&g_a2dpSrcCallbacks); - a2dp_snk_register_callbacks(&g_a2dp_snk_callbacks); g_ble_gapble_cbs.conn_state_change_cb = svr_ble_connstate_change_cb; g_ble_gapble_cbs.start_adv_cb = svr_ble_adv_start_cb; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 4162387e7..9f60e3217 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -193,6 +193,49 @@ bool is_doing_shutdown_or_reboot(void) return doing_shutdown_or_reboot; } + +bool enable_hfp_service(bool _enable) +{ + uint8_t stat=uapi_dev_runtime_get_br_connect_stat(); + if (_enable == true) + { + stat |= 0x01; + }else{ + stat &= ~0x01; + } + uapi_dev_runtime_set_br_connect_stat(stat); + return true; +} + +bool enable_a2dp_service(bool _enable) +{ + uint8_t stat=uapi_dev_runtime_get_br_connect_stat(); + if (_enable == true) + { + stat |= 0x02; + }else{ + stat &= ~0x02; + } + uapi_dev_runtime_set_br_connect_stat(stat); + return true; +} + +bool enable_spp_service(bool _enable) +{ + uint8_t stat=uapi_dev_runtime_get_br_connect_stat(); + if (_enable == true) + { + stat |= 0x04; + }else{ + stat &= ~0x04; + } + uapi_dev_runtime_set_br_connect_stat(stat); + return true; +} + +extern void BtInitSpp(void); +extern void BtA2dpInit(void); +extern void BtInitCallBacks(void); bool start_custom_ble_service(void) { #ifdef SUPPORT_BLE_SERVICE @@ -200,9 +243,23 @@ bool start_custom_ble_service(void) PRINT("start custom protocol classic bt ble service !\r\n"); // bool ret = enable_bt_stack(); #endif + // if(uapi_dev_runtime_get_bt_powerstat()==true) + { + + PRINT("register custom protocol classic bt service !\r\n"); + + BtInitCallBacks(); + BtA2dpInit(); + enable_a2dp_service(true); + BtInitSpp(); + enable_spp_service(true); + + } + uapi_dev_runtime_set_bt_powerstat(1); return true; } + bool stop_custom_ble_service(void) { #ifdef SUPPORT_BLE_SERVICE diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index c8090381b..68d01b79d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -139,6 +139,9 @@ bool stop_custom_ble_service(void); bool start_alipay_ble_service(void); bool stop_alipay_ble_service(void); +bool enable_hfp_service(bool _enable); +bool enable_a2dp_service(bool _enable); +bool enable_spp_service(bool _enable); uint32_t uapi_calendar_recover_date(void); uint32_t uapi_calendar_store_date(void);