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:
Tian Hao
2016-12-11 16:36:47 +08:00
parent 1ed584f896
commit c01dedcb06
23 changed files with 573 additions and 382 deletions

View File

@@ -17,8 +17,9 @@
#include "esp_gattc_api.h"
#include "btc_manage.h"
#include "btc_gattc.h"
#include "btc_gatt_util.h"
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
esp_err_t esp_ble_gattc_register_callback(esp_gattc_cb_t callback)
{
if (callback == NULL) {
return ESP_FAIL;
@@ -33,7 +34,6 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
btc_msg_t msg;
btc_ble_gattc_args_t arg;
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
if (app_id > ESP_APP_ID_MAX) {
return ESP_ERR_INVALID_ARG;
}
@@ -46,7 +46,7 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -54,12 +54,12 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_APP_UNREGISTER;
arg.app_unreg.gatt_if = gatt_if;
arg.app_unreg.gattc_if = gattc_if;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -67,14 +67,14 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_OPEN;
arg.open.gatt_if = gatt_if;
arg.open.gattc_if = gattc_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.is_direct = is_direct;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
esp_err_t esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -82,12 +82,12 @@ esp_err_t esp_ble_gattc_close (uint16_t conn_id)
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CLOSE;
arg.close.conn_id = conn_id;
arg.close.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
esp_err_t esp_ble_gattc_config_mtu (esp_gatt_if_t gattc_if, uint16_t conn_id, uint16_t mtu)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -99,13 +99,13 @@ esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CFG_MTU;
arg.cfg_mtu.conn_id = conn_id;
arg.cfg_mtu.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
arg.cfg_mtu.mtu = mtu;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
esp_err_t esp_ble_gattc_search_service(esp_gatt_if_t gattc_if, uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -113,7 +113,8 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_SEARCH_SERVICE;
arg.search_srvc.conn_id = conn_id;
arg.search_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
if (filter_uuid) {
arg.search_srvc.filter_uuid_enable = true;
memcpy(&arg.search_srvc.filter_uuid, filter_uuid, sizeof(esp_bt_uuid_t));
@@ -124,9 +125,10 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *start_char_id)
esp_err_t esp_ble_gattc_get_characteristic(esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *start_char_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -134,12 +136,12 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_char_id) {
arg.get_next_char.conn_id = conn_id;
arg.get_next_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_next_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_char.char_id, start_char_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_CHAR;
} else {
arg.get_first_char.conn_id = conn_id;
arg.get_first_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_first_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_CHAR;
}
@@ -147,7 +149,8 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
esp_err_t esp_ble_gattc_get_descriptor(esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *start_descr_id)
@@ -159,13 +162,13 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
msg.pid = BTC_PID_GATTC;
if (start_descr_id) {
arg.get_next_descr.conn_id = conn_id;
arg.get_next_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_next_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.get_next_descr.descr_id, start_descr_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_DESCR;
} else {
arg.get_first_descr.conn_id = conn_id;
arg.get_first_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_first_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_first_descr.char_id, char_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_DESCR;
@@ -174,9 +177,10 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_srvc_id_t *start_incl_srvc_id)
esp_err_t esp_ble_gattc_get_included_service(esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_srvc_id_t *start_incl_srvc_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -185,12 +189,12 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
msg.pid = BTC_PID_GATTC;
if (start_incl_srvc_id) {
arg.get_next_incl_srvc.conn_id = conn_id;
arg.get_next_incl_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_next_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_incl_srvc.start_service_id, start_incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE;
} else {
arg.get_first_incl_srvc.conn_id = conn_id;
arg.get_first_incl_srvc.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.get_first_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE;
}
@@ -198,8 +202,11 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
esp_err_t esp_ble_gattc_read_char (esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -207,7 +214,7 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_CHAR;
arg.read_char.conn_id = conn_id;
arg.read_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.read_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.read_char.char_id, char_id, sizeof(esp_gatt_id_t));
arg.read_char.auth_req = auth_req;
@@ -215,11 +222,12 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
esp_gatt_auth_req_t auth_req)
esp_err_t esp_ble_gattc_read_char_descr (esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -227,7 +235,7 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_CHAR_DESCR;
arg.read_descr.conn_id = conn_id;
arg.read_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.read_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.read_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.read_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
@@ -236,7 +244,8 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
esp_err_t esp_ble_gattc_write_char( esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t value_len,
@@ -250,7 +259,7 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_WRITE_CHAR;
arg.write_char.conn_id = (uint16_t) conn_id;
arg.write_char.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.write_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.write_char.char_id, char_id, sizeof(esp_gatt_id_t));
arg.write_char.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
@@ -261,14 +270,15 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
uint16_t value_len,
uint8_t *value,
esp_gatt_write_type_t write_type,
esp_gatt_auth_req_t auth_req)
esp_err_t esp_ble_gattc_write_char_descr (esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
uint16_t value_len,
uint8_t *value,
esp_gatt_write_type_t write_type,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -276,7 +286,7 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_WRITE_CHAR_DESCR;
arg.write_descr.conn_id = (uint16_t) conn_id;
arg.write_descr.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.write_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.write_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.write_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
@@ -288,7 +298,8 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
esp_err_t esp_ble_gattc_prepare_write(esp_gatt_if_t gattc_if,
uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t offset,
@@ -303,7 +314,7 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_PREPARE_WRITE;
arg.prep_write.conn_id = conn_id;
arg.prep_write.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
memcpy(&arg.prep_write.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.prep_write.char_id, char_id, sizeof(esp_gatt_id_t));
arg.prep_write.offset = offset;
@@ -314,7 +325,7 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id, bool is_execute)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
@@ -322,13 +333,13 @@ esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_EXECUTE_WRITE;
arg.exec_write.conn_id = conn_id;
arg.exec_write.conn_id = BTC_GATT_CREATE_CONN_ID(gattc_if, conn_id);
arg.exec_write.is_execute = is_execute;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id)
@@ -339,7 +350,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
arg.reg_for_notify.gatt_if = gatt_if;
arg.reg_for_notify.gattc_if = gattc_if;
memcpy(arg.reg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.reg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.reg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));
@@ -347,7 +358,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id)
@@ -358,7 +369,7 @@ esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_UNREG_FOR_NOTIFY;
arg.unreg_for_notify.gatt_if = gatt_if;
arg.unreg_for_notify.gattc_if = gattc_if;
memcpy(arg.unreg_for_notify.remote_bda, server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.unreg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.unreg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));