gatt_client: use btstack_packet_handler instead of (*fn)(type,packet,size) for events

This commit is contained in:
Matthias Ringwald 2016-02-04 17:58:00 +01:00
parent d9a7306a10
commit b6e96f1452
8 changed files with 20 additions and 25 deletions

View File

@ -160,7 +160,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
}
}
static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch(state){
case TC_W4_SERVICE_RESULT:

View File

@ -110,7 +110,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
// Handles GATT client query results, sends queries and the
// GAP disconnect command when the querying is done.
void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size);
void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void gatt_client_setup(void){
@ -262,7 +262,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
}
}
void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
le_service_t service;
le_characteristic_t characteristic;
switch(packet[0]){

View File

@ -353,13 +353,10 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
}
// app_run();
}
static void handle_gatt_client_event(uint8_t packet_type, uint8_t * packet, uint16_t size){
handle_hci_event(packet_type, 0, packet, size);
}
void ancs_client_init(void){
hci_event_callback_registration.callback = &handle_hci_event;
hci_add_event_handler(&hci_event_callback_registration);
gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event);
gc_id = gatt_client_register_packet_handler(&handle_hci_event);
}

View File

@ -87,7 +87,7 @@ static uint16_t gatt_client_next_id(void){
return next_gatt_client_id;
}
static gatt_client_callback_t gatt_client_callback_for_id_new(uint16_t id){
static btstack_packet_handler_t gatt_client_callback_for_id_new(uint16_t id){
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_subclients);
while (btstack_linked_list_iterator_has_next(&it)){
@ -98,7 +98,7 @@ static gatt_client_callback_t gatt_client_callback_for_id_new(uint16_t id){
return NULL;
}
uint16_t gatt_client_register_packet_handler(gatt_client_callback_t gatt_callback){
uint16_t gatt_client_register_packet_handler(btstack_packet_handler_t gatt_callback){
if (gatt_callback == NULL){
log_error("gatt_client_register_packet_handler called with NULL callback");
return 0;
@ -500,9 +500,9 @@ static void gatt_client_handle_transaction_complete(gatt_client_t * peripheral){
}
static void emit_event_new(uint16_t gatt_client_id, uint8_t * packet, uint16_t size){
gatt_client_callback_t gatt_client_callback = gatt_client_callback_for_id_new(gatt_client_id);
btstack_packet_handler_t gatt_client_callback = gatt_client_callback_for_id_new(gatt_client_id);
if (!gatt_client_callback) return;
(*gatt_client_callback)(HCI_EVENT_PACKET, packet, size);
(*gatt_client_callback)(HCI_EVENT_PACKET, 0, packet, size);
}
static void emit_event_to_all_subclients_new(uint8_t * packet, uint16_t size){
@ -510,7 +510,7 @@ static void emit_event_to_all_subclients_new(uint8_t * packet, uint16_t size){
btstack_linked_list_iterator_init(&it, &gatt_subclients);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
(*subclient->callback)(HCI_EVENT_PACKET, packet, size);
(*subclient->callback)(HCI_EVENT_PACKET, 0, packet, size);
}
}

View File

@ -50,8 +50,6 @@ typedef struct le_event {
uint16_t handle;
} le_event_t;
typedef void (*gatt_client_callback_t)(uint8_t packet_type, uint8_t *packet, uint16_t size);
typedef enum {
P_READY,
P_W2_SEND_SERVICE_QUERY,
@ -185,9 +183,9 @@ typedef struct gatt_client{
} gatt_client_t;
typedef struct gatt_subclient {
btstack_linked_item_t item;
uint16_t id;
gatt_client_callback_t callback;
btstack_linked_item_t item;
uint16_t id;
btstack_packet_handler_t callback;
} gatt_subclient_t;
/* API_START */
@ -222,7 +220,7 @@ void gatt_client_init(void);
/**
* @brief Register callback (packet handler) for GATT client. Returns GATT client ID.
*/
uint16_t gatt_client_register_packet_handler (gatt_client_callback_t callback);
uint16_t gatt_client_register_packet_handler (btstack_packet_handler_t callback);
/**
* @brief Unregister callback (packet handler) for GATT client.

View File

@ -142,7 +142,7 @@ static void verify_blob(uint16_t value_length, uint16_t value_offset, uint8_t *
result_counter++;
}
static void handle_ble_client_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
static void handle_ble_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
uint8_t status;
le_service_t service;

View File

@ -40,7 +40,7 @@ void CHECK_EQUAL_ARRAY(const uint8_t * expected, uint8_t * actual, int size){
// -----------------------------------------------------
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
bd_addr_t address;

View File

@ -12,7 +12,7 @@
#include "ble/sm.h"
static btstack_packet_handler_t att_packet_handler;
static void (*registered_hci_event_handler) (uint8_t packet_type, uint8_t *packet, uint16_t size) = NULL;
static void (*registered_hci_event_handler) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size) = NULL;
static btstack_linked_list_t connections;
static const uint16_t max_mtu = 23;
@ -25,22 +25,22 @@ uint16_t get_gatt_client_handle(void){
void mock_simulate_command_complete(const hci_cmd_t *cmd){
uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, cmd->opcode & 0xff, cmd->opcode >> 8, 0};
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, sizeof(packet));
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, sizeof(packet));
}
void mock_simulate_hci_state_working(void){
uint8_t packet[3] = {BTSTACK_EVENT_STATE, 0, HCI_STATE_WORKING};
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, 3);
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, 3);
}
void mock_simulate_connected(void){
uint8_t packet[] = {0x3E, 0x13, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x9B, 0x77, 0xD1, 0xF7, 0xB1, 0x34, 0x50, 0x00, 0x00, 0x00, 0xD0, 0x07, 0x05};
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, sizeof(packet));
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, sizeof(packet));
}
void mock_simulate_scan_response(void){
uint8_t packet[] = {0xE2, 0x13, 0xE2, 0x01, 0x34, 0xB1, 0xF7, 0xD1, 0x77, 0x9B, 0xCC, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
registered_hci_event_handler(HCI_EVENT_PACKET, (uint8_t *)&packet, sizeof(packet));
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, sizeof(packet));
}
uint8_t le_central_start_scan(void){