example/gatt_counter: print ATT Writes

This commit is contained in:
Matthias Ringwald 2023-11-16 09:25:19 +01:00
parent ed07a8bd76
commit c0e4ccda0d
2 changed files with 21 additions and 13 deletions

View File

@ -252,20 +252,28 @@ static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t a
/*
* @section ATT Write
*
* @text The only valid ATT write in this example is to the Client Characteristic Configuration, which configures notification
* and indication. If the ATT handle matches the client configuration handle, the new configuration value is stored and used
* in the heartbeat handler to decide if a new value should be sent. See Listing attWrite.
* @text The only valid ATT writes in this example are to the Client Characteristic Configuration, which configures notification
* and indication and to the the Characteristic Value.
* If the ATT handle matches the client configuration handle, the new configuration value is stored and used
* in the heartbeat handler to decide if a new value should be sent.
* If the ATT handle matches the characteristic value handle, we print the write as hexdump
* See Listing attWrite.
*/
/* LISTING_START(attWrite): ATT Write */
static int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
UNUSED(transaction_mode);
UNUSED(offset);
UNUSED(buffer_size);
if (att_handle != ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE) return 0;
le_notification_enabled = little_endian_read_16(buffer, 0) == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION;
con_handle = connection_handle;
switch (att_handle){
case ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE:
le_notification_enabled = little_endian_read_16(buffer, 0) == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION;
con_handle = connection_handle;
break;
case ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE:
printf("Write: transaction mode %u, offset %u, data (%u bytes): ", transaction_mode, offset, buffer_size);
printf_hexdump(buffer, buffer_size);
break;
default:
break;
}
return 0;
}
/* LISTING_END */

View File

@ -1,5 +1,5 @@
PRIMARY_SERVICE, GAP_SERVICE
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "LE Counter"
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "GATT Counter"
// add Battery Service
#import <battery_service.gatt>
@ -9,5 +9,5 @@ CHARACTERISTIC, GATT_DATABASE_HASH, READ,
// Counter Service
PRIMARY_SERVICE, 0000FF10-0000-1000-8000-00805F9B34FB
// Counter Characteristic, with read and notify
CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, READ | NOTIFY | DYNAMIC,
// Counter Characteristic, with read, write and notify
CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, READ | WRITE | NOTIFY | DYNAMIC,