Skip to content

Commit c026024

Browse files
author
Donatien Garnier
authored
Merge pull request ARMmbed#218 from paul-szczepanek-arm/add-mtu-to-gap
Add data length change to gap and ATT_MTU change to gatt client
2 parents 53917d8 + e4a4b9c commit c026024

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

BLE_GAP/source/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,24 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
568568
}
569569
}
570570

571+
/**
572+
* Implementation of Gap::EventHandler::onDataLengthChange
573+
*/
574+
virtual void onDataLengthChange(
575+
ble::connection_handle_t connectionHandle,
576+
uint16_t txSize,
577+
uint16_t rxSize
578+
) {
579+
printf(
580+
"Data length changed on the connection %d.\r\n"
581+
"Maximum sizes for over the air packets are:\r\n"
582+
"%d octets for transmit and %d octets for receive.\r\n",
583+
connectionHandle,
584+
txSize,
585+
rxSize
586+
);
587+
}
588+
571589
private:
572590

573591
/** Clean up internal state after last run, cycle to the next mode and launch it */

BLE_GattClient/source/main.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
* indications and notification until the connection end.
4444
*/
4545
class GattClientProcess : private mbed::NonCopyable<GattClientProcess>,
46-
public ble::Gap::EventHandler {
46+
public ble::Gap::EventHandler,
47+
public GattClient::EventHandler {
4748

4849
// Internal typedef to this class type.
4950
// It is used as a shorthand to pass member function as callbacks.
@@ -118,6 +119,13 @@ class GattClientProcess : private mbed::NonCopyable<GattClientProcess>,
118119
return;
119120
}
120121

122+
// register as a handler for GattClient events
123+
_client->setEventHandler(this);
124+
125+
// this might not result in a new value but if it does we will be informed through
126+
// an call in the event handler we just registered
127+
_client->negotiateAttMtu(_connection_handle);
128+
121129
printf("Client process started: initiate service discovery.\r\n");
122130
}
123131

@@ -170,6 +178,21 @@ class GattClientProcess : private mbed::NonCopyable<GattClientProcess>,
170178
}
171179
}
172180

181+
/**
182+
* Implementation of GattClient::EventHandler::onAttMtuChange event
183+
*/
184+
virtual void onAttMtuChange(
185+
ble::connection_handle_t connectionHandle,
186+
uint16_t attMtuSize
187+
) {
188+
printf(
189+
"ATT_MTU changed on the connection %d to a new value of %d.\r\n",
190+
connectionHandle,
191+
attMtuSize
192+
/* maximum size of an attribute written in a single operation is one less */
193+
);
194+
}
195+
173196
private:
174197
////////////////////////////////////////////////////////////////////////////////
175198
// Service and characteristic discovery process.

0 commit comments

Comments
 (0)