mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-29 21:32:38 +00:00
example/gatt_counter: print ATT Writes
This commit is contained in:
parent
ed07a8bd76
commit
c0e4ccda0d
@ -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 */
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user