1
0
mirror of https://github.com/bluekitchen/btstack.git synced 2025-03-27 14:37:12 +00:00

gatt_client: store notification callback, fix characteristic serialization. ancs_client: also listen for notification source notifications

This commit is contained in:
Matthias Ringwald 2016-04-08 22:51:52 +02:00
parent 77a5a3586d
commit 86c3855949
3 changed files with 18 additions and 19 deletions

@ -89,7 +89,8 @@ static const uint8_t ancs_data_source_uuid[] = {0x22,0xEA,0xC6,0xE9,0x24
static uint32_t ancs_notification_uid;
static uint16_t gc_handle;
static gatt_client_notification_t client_notification;
static gatt_client_notification_t ancs_notification_source_notification;
static gatt_client_notification_t ancs_data_source_notification;
static int ancs_service_found;
static gatt_client_service_t ancs_service;
static gatt_client_characteristic_t ancs_notification_source_characteristic;
@ -252,19 +253,19 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT:
gatt_event_characteristic_query_result_get_characteristic(packet, &characteristic);
if (memcmp(characteristic.uuid128, ancs_notification_source_uuid, 16) == 0){
log_info("ANCS Notification Source Characterisic found");
log_info("ANCS Notification Source found, attribute handle %u", characteristic.value_handle);
ancs_notification_source_characteristic = characteristic;
ancs_characteristcs++;
break;
}
if (memcmp(characteristic.uuid128, ancs_control_point_uuid, 16) == 0){
log_info("ANCS Control Point found");
log_info("ANCS Control Point found, attribute handle %u", characteristic.value_handle);
ancs_control_point_characteristic = characteristic;
ancs_characteristcs++;
break;
}
if (memcmp(characteristic.uuid128, ancs_data_source_uuid, 16) == 0){
log_info("ANCS Data Source Characterisic found");
log_info("ANCS Data Source found, attribute handle %u", characteristic.value_handle);
ancs_data_source_characteristic = characteristic;
ancs_characteristcs++;
break;
@ -273,6 +274,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
case GATT_EVENT_QUERY_COMPLETE:
log_info("ANCS Characteristcs count %u", ancs_characteristcs);
tc_state = TC_W4_NOTIFICATION_SOURCE_SUBSCRIBED;
gatt_client_listen_for_characteristic_value_updates(&ancs_notification_source_notification, &handle_hci_event, gc_handle, &ancs_notification_source_characteristic);
gatt_client_write_client_characteristic_configuration(handle_hci_event, gc_handle, &ancs_notification_source_characteristic,
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
break;
@ -285,7 +287,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
case GATT_EVENT_QUERY_COMPLETE:
log_info("ANCS Notification Source subscribed");
tc_state = TC_W4_DATA_SOURCE_SUBSCRIBED;
gatt_client_listen_for_characteristic_value_updates(&client_notification, gc_handle, &ancs_data_source_characteristic);
gatt_client_listen_for_characteristic_value_updates(&ancs_data_source_notification, &handle_hci_event, gc_handle, &ancs_data_source_characteristic);
gatt_client_write_client_characteristic_configuration(handle_hci_event, gc_handle, &ancs_data_source_characteristic,
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
break;
@ -311,6 +313,8 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
value_length = little_endian_read_16(packet, 6);
value = &packet[8];
log_info("ANCS Ntoficiation, value handle %u", value_handle);
if (value_handle == ancs_data_source_characteristic.value_handle){
int i;
for (i=0;i<value_length;i++) {

@ -453,13 +453,8 @@ static void emit_event_new(btstack_packet_handler_t callback, uint8_t * packet,
(*callback)(HCI_EVENT_PACKET, 0, packet, size);
}
/**
* @brief Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration
* @param notification struct used to store registration
* @param con_handle
* @param characteristic
*/
void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){
void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t packet_handler, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){
notification->callback = packet_handler;
notification->con_handle = con_handle;
notification->attribute_handle = characteristic->value_handle;
btstack_linked_list_add(&gatt_client_value_listeners, (btstack_linked_item_t*) notification);
@ -469,10 +464,10 @@ static void emit_event_to_registered_listeners(hci_con_handle_t con_handle, uint
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &gatt_client_value_listeners);
while (btstack_linked_list_iterator_has_next(&it)){
gatt_client_notification_t * registration = (gatt_client_notification_t*) btstack_linked_list_iterator_next(&it);
if (registration->con_handle != con_handle) continue;
if (registration->attribute_handle != attribute_handle) continue;
(*registration->callback)(HCI_EVENT_PACKET, 0, packet, size);
gatt_client_notification_t * notification = (gatt_client_notification_t*) btstack_linked_list_iterator_next(&it);
if (notification->con_handle != con_handle) continue;
if (notification->attribute_handle != attribute_handle) continue;
(*notification->callback)(HCI_EVENT_PACKET, 0, packet, size);
}
}
@ -1854,8 +1849,7 @@ void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset,
characteristic->value_handle = little_endian_read_16(packet, offset + 2);
characteristic->end_handle = little_endian_read_16(packet, offset + 4);
characteristic->properties = little_endian_read_16(packet, offset + 6);
characteristic->uuid16 = little_endian_read_16(packet, offset + 8);
reverse_128(&packet[offset+10], characteristic->uuid128);
reverse_128(&packet[offset+8], characteristic->uuid128);
if (uuid_has_bluetooth_prefix(characteristic->uuid128)){
characteristic->uuid16 = big_endian_read_32(characteristic->uuid128, 0);
}

@ -335,10 +335,11 @@ uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_han
/**
* @brief Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration
* @param notification struct used to store registration
* @param packet_handler
* @param con_handle
* @param characteristic
*/
void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t packet_handler, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
/**
* @brief -> gatt complete event