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 */
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
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 */
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;
/**
*/
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
[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
#include "bta/bta_av_api.h"
#endif ///BTA_AV_INCLUDED == TRUE
#include "common/bt_defs.h"
+#include "stack/btm_api.h"
/************************************************************************************
** Constants & Macros
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;
+}
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__ */
#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;
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;
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, ¶m,
+ 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;
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;
}
}
}
+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) */
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 */
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);