From 77043c43b8afb83c6683758c4c21bfba99b3a253 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 20 Dec 2024 10:44:05 +0100 Subject: [PATCH] gatt-service/ancs-client: use event getters for notification & indication --- src/ble/gatt-service/ancs_client.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/ble/gatt-service/ancs_client.c b/src/ble/gatt-service/ancs_client.c index a0abc9cd6..23c2e3d19 100644 --- a/src/ble/gatt-service/ancs_client.c +++ b/src/ble/gatt-service/ancs_client.c @@ -192,12 +192,7 @@ static void ancs_chunk_parser_handle_byte(uint8_t data){ } } -static void ancs_client_handle_notification(uint8_t * packet, uint16_t size){ - UNUSED(size); - - uint16_t value_handle = little_endian_read_16(packet, 4); - uint16_t value_length = little_endian_read_16(packet, 6); - uint8_t * value = &packet[8]; +static void ancs_client_handle_notification(uint16_t value_handle, const uint8_t * value, uint16_t value_length){ log_info("ANCS Notification, value handle %u", value_handle); @@ -280,6 +275,7 @@ static void ancs_client_handle_gatt_client_event(uint8_t packet_type, uint16_t c UNUSED(packet_type); UNUSED(channel); + UNUSED(size); static const uint8_t ancs_notification_source_uuid[] = {0x9F,0xBF,0x12,0x0D,0x63,0x01,0x42,0xD9,0x8C,0x58,0x25,0xE6,0x99,0xA2,0x1D,0xBD}; static const uint8_t ancs_control_point_uuid[] = {0x69,0xD1,0xD8,0xF3,0x45,0xE1,0x49,0xA8,0x98,0x21,0x9B,0xBD,0xFD,0xAA,0xD9,0xD9}; @@ -351,9 +347,19 @@ static void ancs_client_handle_gatt_client_event(uint8_t packet_type, uint16_t c case TC_SUBSCRIBED: switch(hci_event_packet_get_type(packet)){ case GATT_EVENT_NOTIFICATION: - case GATT_EVENT_INDICATION: - ancs_client_handle_notification(packet, size); + ancs_client_handle_notification( + gatt_event_notification_get_value_handle(packet), + gatt_event_notification_get_value(packet), + gatt_event_notification_get_value_length(packet) + ); break; + case GATT_EVENT_INDICATION: + ancs_client_handle_notification( + gatt_event_indication_get_value_handle(packet), + gatt_event_indication_get_value(packet), + gatt_event_indication_get_value_length(packet) + ); + break; default: break; }