component bt:Change the battery client profile to the new API
This commit is contained in:
parent
cdd65095e3
commit
57f8128718
2 changed files with 20 additions and 18 deletions
|
@ -17,14 +17,15 @@
|
||||||
#include "btm_api.h"
|
#include "btm_api.h"
|
||||||
#include "bt_types.h"
|
#include "bt_types.h"
|
||||||
#include "gattc_profile.h"
|
#include "gattc_profile.h"
|
||||||
|
#include "bt_app_api.h"
|
||||||
|
|
||||||
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
#define BT_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||||
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
#define BT_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
|
||||||
tBTA_GATTC_IF client_if;
|
esp_gattc_if_t client_if;
|
||||||
|
|
||||||
tBT_UUID bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}};
|
esp_bt_uuid_t bas_uuid = {LEN_UUID_16, {UUID_SERVCLASS_BATTERY}};
|
||||||
|
|
||||||
uint16_t get_uuid16(tBT_UUID* p_uuid)
|
uint16_t get_uuid16(esp_bt_uuid_t* p_uuid)
|
||||||
{
|
{
|
||||||
if(p_uuid->len == LEN_UUID_16)
|
if(p_uuid->len == LEN_UUID_16)
|
||||||
{
|
{
|
||||||
|
@ -52,17 +53,17 @@ void bta_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID* p_outp
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fill a service ID structure with a 16 bits service UUID*/
|
/*fill a service ID structure with a 16 bits service UUID*/
|
||||||
void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, tBTA_GATT_SRVC_ID* p_output)
|
void bta_le_fill_16bits_srvc_id(bool is_pri, UINT8 inst_id, UINT16 srvc_uuid, esp_gatt_srvc_id_t* p_output)
|
||||||
{
|
{
|
||||||
memset((void *)p_output, 0, sizeof(tBTA_GATT_SRVC_ID));
|
memset((void *)p_output, 0, sizeof(esp_gatt_srvc_id_t));
|
||||||
p_output->is_primary = is_pri;
|
p_output->is_primary = is_pri;
|
||||||
bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id);
|
bta_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*fill a char ID structure with a 16 bits char UUID*/
|
/*fill a char ID structure with a 16 bits char UUID*/
|
||||||
void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p_output)
|
void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, esp_gatt_id_t* p_output)
|
||||||
{
|
{
|
||||||
memset((void *)p_output, 0, sizeof(tBTA_GATT_ID));
|
memset((void *)p_output, 0, sizeof(esp_gatt_id_t));
|
||||||
bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output);
|
bta_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,13 +72,13 @@ void bta_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, tBTA_GATT_ID* p
|
||||||
**
|
**
|
||||||
** Description battery service register callback function
|
** Description battery service register callback function
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
static void bas_gattc_callback(esp_gattc_evt_t event, esp_gattc_t* p_data)
|
||||||
{
|
{
|
||||||
switch (event)
|
switch (event)
|
||||||
{
|
{
|
||||||
case BTA_GATTC_REG_EVT:
|
case ESP_GATTC_REG_EVT:
|
||||||
{
|
{
|
||||||
tBTA_GATT_STATUS status = p_data->reg_oper.status;
|
esp_gatt_status_t status = p_data->reg_oper.status;
|
||||||
client_if = p_data->reg_oper.client_if;
|
client_if = p_data->reg_oper.client_if;
|
||||||
LOG_ERROR("BAS register completed: event=%d, status=%d, client_if=%d\n",
|
LOG_ERROR("BAS register completed: event=%d, status=%d, client_if=%d\n",
|
||||||
event, status, client_if);
|
event, status, client_if);
|
||||||
|
@ -86,7 +87,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*connect callback*/
|
/*connect callback*/
|
||||||
case BTA_GATTC_OPEN_EVT:
|
case ESP_GATTC_OPEN_EVT:
|
||||||
{
|
{
|
||||||
|
|
||||||
LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n",
|
LOG_ERROR("\n%s:device is connected "BT_BD_ADDR_STR", client_if=%d, status=%d, connect_id=%d\n",
|
||||||
|
@ -101,12 +102,12 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
||||||
int conn_id = p_data->open.conn_id;
|
int conn_id = p_data->open.conn_id;
|
||||||
|
|
||||||
/*discover service*/
|
/*discover service*/
|
||||||
BTA_GATTC_ServiceSearchRequest(conn_id, NULL);
|
esp_ble_gattc_svc_search_req(conn_id, NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTA_GATTC_SEARCH_RES_EVT:
|
case ESP_GATTC_SEARCH_RES_EVT:
|
||||||
{
|
{
|
||||||
// tBTA_GATTC_SRVC_RES service_result;
|
// tBTA_GATTC_SRVC_RES service_result;
|
||||||
LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n",
|
LOG_ERROR("find the service,uuid=0x%x, is_primary=%d\n",
|
||||||
|
@ -115,7 +116,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTA_GATTC_SEARCH_CMPL_EVT:
|
case ESP_GATTC_SEARCH_CMPL_EVT:
|
||||||
{
|
{
|
||||||
LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id,
|
LOG_ERROR("search service complete, conn_id=%d,status=%d\n", p_data->search_cmpl.conn_id,
|
||||||
p_data->search_cmpl.status);
|
p_data->search_cmpl.status);
|
||||||
|
@ -127,7 +128,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
||||||
tBTA_GATTC_CHAR_ID out_char_id;
|
tBTA_GATTC_CHAR_ID out_char_id;
|
||||||
tGATT_CHAR_PROP out_char_prop;
|
tGATT_CHAR_PROP out_char_prop;
|
||||||
bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id);
|
bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_srvc_id);
|
||||||
status = BTA_GATTC_GetFirstChar(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL,
|
status = esp_ble_gattc_get_first_char(p_data->search_cmpl.conn_id, &battery_srvc_id, NULL,
|
||||||
&out_char_id, &out_char_prop);
|
&out_char_id, &out_char_prop);
|
||||||
if(status == 0)
|
if(status == 0)
|
||||||
{
|
{
|
||||||
|
@ -139,13 +140,13 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
||||||
bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id);
|
bta_le_fill_16bits_srvc_id(TRUE, 0, UUID_SERVCLASS_BATTERY, &battery_char_id.srvc_id);
|
||||||
bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id);
|
bta_le_fill_16bits_char_id(0, GATT_UUID_BATTERY_LEVEL, &battery_char_id.char_id);
|
||||||
|
|
||||||
BTA_GATTC_ReadCharacteristic(p_data->search_cmpl.conn_id, &battery_char_id,
|
esp_ble_gattc_read_char(p_data->search_cmpl.conn_id, &battery_char_id,
|
||||||
BTA_GATT_AUTH_REQ_NONE);
|
BTA_GATT_AUTH_REQ_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BTA_GATTC_READ_CHAR_EVT:
|
case ESP_GATTC_READ_CHAR_EVT:
|
||||||
{
|
{
|
||||||
|
|
||||||
LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n",
|
LOG_ERROR("\nread characteristic:connect_id=%d, status=%d\n",
|
||||||
|
@ -179,7 +180,7 @@ static void bas_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data)
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
void bac_register(void)
|
void bac_register(void)
|
||||||
{
|
{
|
||||||
BTA_GATTC_AppRegister(&bas_uuid, bas_gattc_callback);
|
esp_ble_gattc_app_register(&bas_uuid, bas_gattc_callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ typedef tBTA_GATT_STATUS esp_gatt_status_t;
|
||||||
|
|
||||||
typedef UINT16 gatt_size_t;
|
typedef UINT16 gatt_size_t;
|
||||||
typedef tBT_UUID esp_bt_uuid_t;
|
typedef tBT_UUID esp_bt_uuid_t;
|
||||||
|
typedef tBTA_GATT_ID esp_gatt_id_t;
|
||||||
|
|
||||||
typedef tBTA_BLE_AD_MASK esp_ble_ad_mask_t;
|
typedef tBTA_BLE_AD_MASK esp_ble_ad_mask_t;
|
||||||
typedef tGATT_IF esp_gatt_if_t;
|
typedef tGATT_IF esp_gatt_if_t;
|
||||||
|
|
Loading…
Reference in a new issue