Skip to content

Commit 3d90f93

Browse files
check event error codes for adv stop
1 parent c37f46a commit 3d90f93

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

BLE_GAP/source/main.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,23 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
330330

331331
void onAdvertisingEnd(const ble::AdvertisingEndEvent &event) override
332332
{
333-
if (event.isConnected()) {
334-
printf("Stopped advertising early due to connection\r\n");
333+
ble::advertising_handle_t adv_handle = event.getAdvHandle();
334+
if (event.getStatus() == BLE_ERROR_UNSPECIFIED) {
335+
printf("Error: Failed to stop advertising set %d\r\n", adv_handle);
336+
} else {
337+
printf("Stopped advertising set %d\r\n", adv_handle);
338+
339+
if (event.getStatus() == BLE_ERROR_TIMEOUT) {
340+
printf("Stopped due to timeout\r\n");
341+
} else if (event.getStatus() == BLE_ERROR_LIMIT_REACHED) {
342+
printf("Stopped due to max number of adv events reached\r\n");
343+
} else if (event.getStatus() == BLE_ERROR_NONE) {
344+
if (event.isConnected()) {
345+
printf("Stopped early due to connection\r\n");
346+
} else {
347+
printf("Stopped due to user request\r\n");
348+
}
349+
}
335350
}
336351

337352
#if BLE_FEATURE_EXTENDED_ADVERTISING
@@ -504,6 +519,8 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
504519
{
505520
print_advertising_performance();
506521

522+
printf("Requesting stop advertising.\r\n");
523+
507524
_gap.stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE);
508525

509526
#if BLE_FEATURE_EXTENDED_ADVERTISING

0 commit comments

Comments
 (0)