mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-26 12:50:30 +00:00
component/bt : change api for V2.0
1. change all gatt cb function to 3 args and function type. add gattc_if/gatts_if as second argument 2. delete gatt_if of "gatt cb param" 3. separate conn_id and gatt_if from conn_id 4. change the demo code as the gatt changed
This commit is contained in:
@@ -17,10 +17,11 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "btc_manage.h"
|
||||
#include "btc_gatts.h"
|
||||
#include "btc_gatt_util.h"
|
||||
|
||||
#define COPY_TO_GATTS_ARGS(_gatt_args, _arg, _arg_type) memcpy(_gatt_args, _arg, sizeof(_arg_type))
|
||||
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback)
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_gatts_cb_t callback)
|
||||
{
|
||||
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@@ -44,7 +45,7 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatts_if)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
@@ -52,12 +53,12 @@ esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
|
||||
arg.app_unreg.gatt_if = gatt_if;
|
||||
arg.app_unreg.gatts_if = gatts_if;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatts_if,
|
||||
esp_gatt_srvc_id_t *service_id, uint16_t num_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@@ -66,7 +67,7 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_CREATE_SERVICE;
|
||||
arg.create_srvc.gatt_if = gatt_if;
|
||||
arg.create_srvc.gatts_if = gatts_if;
|
||||
arg.create_srvc.num_handle = num_handle;
|
||||
memcpy(&arg.create_srvc.service_id, service_id, sizeof(esp_gatt_srvc_id_t));
|
||||
|
||||
@@ -164,7 +165,7 @@ esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
esp_err_t esp_ble_gatts_send_indicate(esp_gatt_if_t gatts_if, uint16_t conn_id, uint16_t attr_handle,
|
||||
uint16_t value_len, uint8_t *value, bool need_confirm)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@@ -173,7 +174,7 @@ esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
|
||||
arg.send_ind.conn_id = conn_id;
|
||||
arg.send_ind.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
||||
arg.send_ind.attr_handle = attr_handle;
|
||||
arg.send_ind.need_confirm = need_confirm;
|
||||
arg.send_ind.value_len = value_len;
|
||||
@@ -182,7 +183,7 @@ esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
esp_err_t esp_ble_gatts_send_response(esp_gatt_if_t gatts_if, uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatt_rsp_t *rsp)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
@@ -191,7 +192,7 @@ esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_SEND_RESPONSE;
|
||||
arg.send_rsp.conn_id = conn_id;
|
||||
arg.send_rsp.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
||||
arg.send_rsp.trans_id = trans_id;
|
||||
arg.send_rsp.status = status;
|
||||
arg.send_rsp.rsp = rsp;
|
||||
@@ -199,7 +200,7 @@ esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatts_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
@@ -207,14 +208,14 @@ esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_OPEN;
|
||||
arg.open.gatt_if = gatt_if;
|
||||
arg.open.gatts_if = gatts_if;
|
||||
arg.open.is_direct = is_direct;
|
||||
memcpy(&arg.open.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gatts_close(uint16_t conn_id)
|
||||
esp_err_t esp_ble_gatts_close(esp_gatt_if_t gatts_if, uint16_t conn_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
@@ -222,7 +223,7 @@ esp_err_t esp_ble_gatts_close(uint16_t conn_id)
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTS;
|
||||
msg.act = BTC_GATTS_ACT_CLOSE;
|
||||
arg.close.conn_id = conn_id;
|
||||
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gatts_if, conn_id);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user