Merge branch 'feature/btdm_read_bredr_rssi' into 'master'

component/bt : add class bt read RSSI delta (golden range)

See merge request idf/esp-idf!2325
This commit is contained in:
Jiang Jiang Jian 2018-05-01 22:55:50 +08:00
commit 95cbdd76dc
8 changed files with 163 additions and 85 deletions

View File

@ -178,4 +178,17 @@ esp_err_t esp_bt_gap_get_cod(esp_bt_cod_t *cod)
return btc_gap_bt_get_cod(cod);
}
esp_err_t esp_bt_gap_read_rssi_delta(esp_bd_addr_t remote_addr)
{
btc_msg_t msg;
btc_gap_bt_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BT;
msg.act = BTC_GAP_BT_ACT_READ_RSSI_DELTA;
memcpy(arg.read_rssi_delta.bda.address, remote_addr, sizeof(esp_bd_addr_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* #if BTC_GAP_BT_INCLUDED == TRUE */

View File

@ -23,13 +23,17 @@
extern "C" {
#endif
/// RSSI threshold
#define ESP_BT_GAP_RSSI_HIGH_THRLD -20 /*!< High RSSI threshold */
#define ESP_BT_GAP_RSSI_LOW_THRLD -45 /*!< Low RSSI threshold */
/// Class of device
typedef struct {
uint32_t reserved_2: 2; /*!< undefined */
uint32_t minor: 6; /*!< minor class */
uint32_t major: 5; /*!< major class */
uint32_t service: 11; /*!< service class */
uint32_t reserved_8: 8; /*!< undefined */
uint32_t reserved_2: 2; /*!< undefined */
uint32_t minor: 6; /*!< minor class */
uint32_t major: 5; /*!< major class */
uint32_t service: 11; /*!< service class */
uint32_t reserved_8: 8; /*!< undefined */
} esp_bt_cod_t;
/// class of device settings
@ -144,6 +148,8 @@ typedef enum {
ESP_BT_GAP_DISC_STATE_CHANGED_EVT, /*!< discovery state changed event */
ESP_BT_GAP_RMT_SRVCS_EVT, /*!< get remote services event */
ESP_BT_GAP_RMT_SRVC_REC_EVT, /*!< get remote service record event */
ESP_BT_GAP_READ_RSSI_DELTA_EVT, /*!< read rssi event */
ESP_BT_GAP_EVT_MAX,
} esp_bt_gap_cb_event_t;
/** Inquiry Mode */
@ -192,6 +198,14 @@ typedef union {
esp_bt_status_t stat; /*!< service search status */
} rmt_srvc_rec; /*!< specific service record from remote device parameter struct */
/**
* @brief ESP_BT_GAP_READ_RSSI_DELTA_EVT *
*/
struct read_rssi_delta_param {
esp_bd_addr_t bda; /*!< remote bluetooth device address*/
esp_bt_status_t stat; /*!< read rssi status */
int8_t rssi_delta; /*!< rssi delta value range -128 ~127, The value zero indicates that the RSSI is inside the Golden Receive Power Range, the Golden Receive Power Range is from ESP_BT_GAP_RSSI_LOW_THRLD to ESP_BT_GAP_RSSI_HIGH_THRLD */
} read_rssi_delta; /*!< read rssi parameter struct */
} esp_bt_gap_cb_param_t;
/**
@ -372,6 +386,18 @@ esp_err_t esp_bt_gap_set_cod(esp_bt_cod_t cod, esp_bt_cod_mode_t mode);
*/
esp_err_t esp_bt_gap_get_cod(esp_bt_cod_t *cod);
/**
* @brief This function is called to read RSSI delta by address after connected. The RSSI value returned by ESP_BT_GAP_READ_RSSI_DELTA_EVT.
*
*
* @param[in] remote_addr - remote device address, corresponding to a certain connection handle.
* @return
* - ESP_OK : Succeed
* - ESP_FAIL: others
*
*/
esp_err_t esp_bt_gap_read_rssi_delta(esp_bd_addr_t remote_addr);
#ifdef __cplusplus
}
#endif

View File

@ -70,7 +70,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_ALARM] = {btc_alarm_handler, NULL },
#if CONFIG_CLASSIC_BT_ENABLED
#if (BTC_GAP_BT_INCLUDED == TRUE)
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, NULL },
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
#endif /* (BTC_GAP_BT_INCLUDED == TRUE) */
[BTC_PID_PRF_QUE] = {btc_profile_queue_handler, NULL },
#if BTC_AV_INCLUDED

View File

@ -31,6 +31,7 @@
#include "bta/bta_av_api.h"
#endif ///BTA_AV_INCLUDED == TRUE
#include "common/bt_defs.h"
#include "stack/btm_api.h"
/************************************************************************************
** Constants & Macros
@ -179,3 +180,69 @@ void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str)
ntohl(uuid4), ntohs(uuid5));
return;
}
esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status)
{
esp_bt_status_t esp_status = ESP_BT_STATUS_FAIL;
switch(hci_status) {
case HCI_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case HCI_ERR_HOST_TIMEOUT:
esp_status = ESP_BT_STATUS_TIMEOUT;
break;
case HCI_ERR_ILLEGAL_COMMAND:
esp_status = ESP_BT_STATUS_PENDING;
break;
case HCI_ERR_UNACCEPT_CONN_INTERVAL:
esp_status = ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL;
break;
case HCI_ERR_PARAM_OUT_OF_RANGE:
esp_status = ESP_BT_STATUS_PARAM_OUT_OF_RANGE;
break;
case HCI_ERR_ILLEGAL_PARAMETER_FMT:
esp_status = ESP_BT_STATUS_ERR_ILLEGAL_PARAMETER_FMT;
break;
default:
esp_status = ESP_BT_STATUS_FAIL;
break;
}
return esp_status;
}
esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status)
{
esp_bt_status_t esp_status = ESP_BT_STATUS_FAIL;
switch(btm_status){
case BTM_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case BTM_BUSY:
esp_status = ESP_BT_STATUS_BUSY;
break;
case BTM_NO_RESOURCES:
esp_status = ESP_BT_STATUS_NOMEM;
break;
case BTM_ERR_PROCESSING:
esp_status = ESP_BT_STATUS_PENDING;
break;
case BTM_PEER_LE_DATA_LEN_UNSUPPORTED:
esp_status = ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED;
break;
case BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED:
esp_status = ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED;
break;
case BTM_SET_PRIVACY_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case BTM_SET_PRIVACY_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
default:
esp_status = ESP_BT_STATUS_FAIL;
break;
}
return esp_status;
}

View File

@ -44,4 +44,7 @@ void uuid128_be_to_esp_uuid(esp_bt_uuid_t *u, uint8_t* uuid128);
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status);
esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status);
#endif /* __BTC_UTIL_H__ */

View File

@ -27,6 +27,7 @@
#include "esp_gap_ble_api.h"
#include "btc/btc_ble_storage.h"
#include "btc/btc_dm.h"
#include "btc/btc_util.h"
static tBTA_BLE_ADV_DATA gl_bta_adv_data;
static tBTA_BLE_ADV_DATA gl_bta_scan_rsp_data;
@ -107,85 +108,6 @@ static void btc_cleanup_adv_data(tBTA_BLE_ADV_DATA *bta_adv_data)
btc_gap_adv_point_cleanup((void **) &bta_adv_data->p_sol_service_128b);
}
static esp_bt_status_t btc_hci_to_esp_status(uint8_t hci_status)
{
esp_bt_status_t esp_status = ESP_BT_STATUS_FAIL;
switch(hci_status) {
case HCI_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case HCI_ERR_ESP_VENDOR_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
case HCI_ERR_HOST_TIMEOUT:
esp_status = ESP_BT_STATUS_TIMEOUT;
break;
case HCI_ERR_ILLEGAL_COMMAND:
esp_status = ESP_BT_STATUS_PENDING;
break;
case HCI_ERR_UNACCEPT_CONN_INTERVAL:
esp_status = ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL;
break;
case HCI_ERR_PARAM_OUT_OF_RANGE:
esp_status = ESP_BT_STATUS_PARAM_OUT_OF_RANGE;
break;
case HCI_ERR_ILLEGAL_PARAMETER_FMT:
esp_status = ESP_BT_STATUS_ERR_ILLEGAL_PARAMETER_FMT;
break;
case HCI_ERR_MEMORY_FULL:
esp_status = ESP_BT_STATUS_MEMORY_FULL;
break;
default:
esp_status = ESP_BT_STATUS_FAIL;
break;
}
return esp_status;
}
static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status)
{
esp_bt_status_t esp_status = ESP_BT_STATUS_FAIL;
switch(btm_status){
case BTM_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case BTM_BUSY:
esp_status = ESP_BT_STATUS_BUSY;
break;
case BTM_NO_RESOURCES:
esp_status = ESP_BT_STATUS_NOMEM;
break;
case BTM_ERR_PROCESSING:
esp_status = ESP_BT_STATUS_PENDING;
break;
case BTM_PEER_LE_DATA_LEN_UNSUPPORTED:
esp_status = ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED;
break;
case BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED:
esp_status = ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED;
break;
case BTM_SET_PRIVACY_SUCCESS:
esp_status = ESP_BT_STATUS_SUCCESS;
break;
case BTM_SET_PRIVACY_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
case BTM_INVALID_STATIC_RAND_ADDR:
esp_status = ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR;
break;
case BTM_SET_STATIC_RAND_ADDR_FAIL:
esp_status = ESP_BT_STATUS_FAIL;
break;
default:
esp_status = ESP_BT_STATUS_FAIL;
break;
}
return esp_status;
}
static void btc_to_bta_adv_data(esp_ble_adv_data_t *p_adv_data, tBTA_BLE_ADV_DATA *bta_adv_data, uint32_t *data_mask)
{
uint32_t mask;

View File

@ -594,6 +594,32 @@ esp_err_t btc_gap_bt_get_cod(esp_bt_cod_t *cod)
return ESP_BT_STATUS_SUCCESS;
}
static void btc_gap_bt_read_rssi_delta_cmpl_callback(void *p_data)
{
tBTA_RSSI_RESULTS *result = (tBTA_RSSI_RESULTS *)p_data;
esp_bt_gap_cb_param_t param;
bt_status_t ret;
btc_msg_t msg;
msg.sig = BTC_SIG_API_CB;
msg.pid = BTC_PID_GAP_BT;
msg.act = ESP_BT_GAP_READ_RSSI_DELTA_EVT;
memcpy(param.read_rssi_delta.bda, result->rem_bda, sizeof(BD_ADDR));
param.read_rssi_delta.stat = btc_btm_status_to_esp_status(result->status);
param.read_rssi_delta.rssi_delta = result->rssi;
ret = btc_transfer_context(&msg, &param,
sizeof(esp_bt_gap_cb_param_t), NULL);
if (ret != BT_STATUS_SUCCESS) {
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
}
}
static void btc_gap_bt_read_rssi_delta(btc_gap_bt_args_t *arg)
{
BTA_DmBleReadRSSI(arg->read_rssi_delta.bda.address, btc_gap_bt_read_rssi_delta_cmpl_callback);
}
void btc_gap_bt_call_handler(btc_msg_t *msg)
{
btc_gap_bt_args_t *arg = (btc_gap_bt_args_t *)msg->arg;
@ -635,6 +661,10 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
btc_gap_bt_set_cod(msg->arg);
break;
}
case BTC_GAP_BT_ACT_READ_RSSI_DELTA: {
btc_gap_bt_read_rssi_delta(msg->arg);
break;
}
default:
break;
}
@ -658,4 +688,15 @@ void btc_gap_bt_busy_level_updated(uint8_t bl_flags)
}
}
void btc_gap_bt_cb_handler(btc_msg_t *msg)
{
esp_bt_gap_cb_param_t *param = (esp_bt_gap_cb_param_t *)msg->arg;
if (msg->act < ESP_BT_GAP_EVT_MAX) {
btc_gap_bt_cb_to_app(msg->act, param);
} else {
LOG_ERROR("%s, unknow msg->act = %d", __func__, msg->act);
}
}
#endif /* (BTC_GAP_BT_INCLUDED == TRUE) */

View File

@ -34,6 +34,7 @@ typedef enum {
BTC_GAP_BT_ACT_GET_REMOTE_SERVICE_RECORD,
BTC_GAP_BT_ACT_SEARCH_SERVICE_RECORD,
BTC_GAP_BT_ACT_SET_COD,
BTC_GAP_BT_ACT_READ_RSSI_DELTA,
} btc_gap_bt_act_t;
/* btc_bt_gap_args_t */
@ -65,9 +66,14 @@ typedef union {
esp_bt_cod_mode_t mode;
} set_cod;
//BTC_GAP_BT_ACT_READ_RSSI_DELTA,
struct bt_read_rssi_delta_args {
bt_bdaddr_t bda;
} read_rssi_delta;
} btc_gap_bt_args_t;
void btc_gap_bt_call_handler(btc_msg_t *msg);
void btc_gap_bt_cb_handler(btc_msg_t *msg);
void btc_gap_bt_busy_level_updated(uint8_t bl_flags);