From 86dc0ae80858e1658626f3ad7a25693239cf3060 Mon Sep 17 00:00:00 2001 From: yulong Date: Tue, 25 Oct 2016 09:12:10 -0400 Subject: [PATCH] component bt: Added the param len & connect API to the bt project --- .../bluedroid_demos/app_core/bt_app_api.c | 95 +++++++++++++++++++ .../bluedroid_demos/include/bt_app_api.h | 3 + .../bluedroid_demos/include/bt_app_defs.h | 9 ++ 3 files changed, 107 insertions(+) diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c index 3ecf3012e4..71dce9f558 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_api.c @@ -14,6 +14,8 @@ #include "bt_app_api.h" #include "btm_ble_api.h" +//#include "btm_ble_int.h" + void API_Ble_AppConfigAdvData(tESP_BLE_ADV_DATA *adv_data, tAPI_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) @@ -69,6 +71,99 @@ void API_Ble_AppStartAdvertising(tESP_API_BLE_ADV_PARAMS_ALL *ble_adv_params) } +void API_Ble_SetScanParams (tESP_BLE_SCAN_PARAMS *scan_params, tGATT_IF client_if, + tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) +{ + if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && + API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && + (scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) + { + BTA_DmSetBleScanFilterParams(client_if, + scan_params->scan_intv, + scan_params->scan_win, + scan_params->scan_type, + scan_params->scan_fil_policy, + scan_params->addr_type_own, + scan_param_setup_cback); + } +} + + +void API_Ble_StartScanning (UINT8 duration, tBTA_DM_SEARCH_CBACK *p_results_cb) +{ + if((duration != 0) && (p_results_cb != NULL)) + { + ///Start scan the device + BTA_DmBleObserve(true, duration, p_results_cb); + }else{ + LOG_ERROR("The scan duration or p_results_cb invalid\n"); + } +} + +void API_Ble_AppStopAdvertising(void) +{ + bool stop_adv = true; + + BTA_DmBleBroadcast(stop_adv); +} + +void API_Ble_AppUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, + UINT16 max_int, UINT16 latency, UINT16 timeout) +{ + if (min_int > max_int){ + min_int = max_int; + } + + if (min_int < BTM_BLE_CONN_INT_MIN || max_int > BTM_BLE_CONN_INT_MAX){ + LOG_ERROR("Invalid interval value.\n"); + } + + BTA_DmBleUpdateConnectionParams(bd_addr, min_int, max_int, + latency, timeout); + +} + +void API_Ble_SetPacketDataLength(BD_ADDR remote_device, UINT16 tx_data_length) +{ + if (tx_data_length > BTM_BLE_DATA_SIZE_MAX){ + tx_data_length = BTM_BLE_DATA_SIZE_MAX; + }else if (tx_data_length < BTM_BLE_DATA_SIZE_MIN){ + tx_data_length = BTM_BLE_DATA_SIZE_MIN; + } + + BTA_DmBleSetDataLength(remote_device, tx_data_length); +} + + +void API_Ble_SetRandAddress(BD_ADDR rand_addr) +{ + if (rand_addr != NULL){ + BTA_DmSetRandAddress(rand_addr); + }else{ + LOG_ERROR("Invalid randrom address.\n"); + } +} + +void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable) +{ + BTA_DmBleConfigLocalPrivacy(privacy_enable); +} + + + + +void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb) +{ + if (p_app_uuid != NULL) + { + BTA_GATTC_AppRegister(p_app_uuid, *p_client_cb); + }else{ + LOG_ERROR("The app uuid invalid.\n"); + } +} + + + diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h index e26bd398bc..3cb14974ab 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_api.h @@ -14,6 +14,7 @@ #include "bt_types.h" #include "bt_app_defs.h" +#include "bta_gatt_api.h" typedef tBTA_SET_ADV_DATA_CMPL_CBACK tAPI_SET_ADV_DATA_CMPL_CBACK ; typedef tBTA_STATUS tAPI_STATUS; @@ -42,5 +43,7 @@ extern void API_Ble_SetRandAddress(BD_ADDR rand_addr); extern void API_Ble_ConfigLocalPrivacy(BOOLEAN privacy_enable); +extern void API_Ble_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb); + void API_Ble_PrfEnable(); diff --git a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h index eeb036d32a..d2aa9c2f4a 100644 --- a/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h +++ b/examples/06_bluedroid_demos/components/bluedroid_demos/include/bt_app_defs.h @@ -64,6 +64,15 @@ typedef struct tBLE_BD_ADDR *p_dir_bda; }tESP_API_BLE_ADV_PARAMS_ALL; +typedef struct +{ + UINT8 scan_type; + UINT16 scan_intv; + UINT16 scan_win; + UINT8 addr_type_own; + UINT8 scan_fil_policy; +}tESP_BLE_SCAN_PARAMS; + extern void ESP_AppBleConfigadvData(tESP_BLE_ADV_DATA *adv_data, tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);