Skip to content

Commit ea20e43

Browse files
add extended advertising guards (#350)
1 parent d9c437c commit ea20e43

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

BLE_GAP/source/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
188188
advertising_params.getMaxPrimaryInterval().valueInMs()
189189
);
190190

191+
#if BLE_FEATURE_EXTENDED_ADVERTISING
191192
/* if we support extended advertising we'll also additionally advertise another set at the same time */
192193
if (_gap.isFeatureSupported(ble::controller_supported_features_t::LE_EXTENDED_ADVERTISING)) {
193194
/* With Bluetooth 5; it is possible to advertise concurrently multiple
@@ -229,6 +230,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
229230
extended_advertising_params.getMaxPrimaryInterval().valueInMs()
230231
);
231232
}
233+
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
232234

233235
_demo_duration.reset();
234236
_demo_duration.start();
@@ -350,6 +352,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
350352
_is_connecting = false;
351353
_demo_duration.stop();
352354

355+
#if BLE_FEATURE_EXTENDED_ADVERTISING
353356
if (!_is_in_scanning_phase) {
354357
/* if we have more than one advertising sets one of them might still be active */
355358
if (_extended_adv_handle != ble::INVALID_ADVERTISING_HANDLE) {
@@ -361,6 +364,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
361364
}
362365
}
363366
}
367+
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
364368

365369
if (event.getStatus() != BLE_ERROR_NONE) {
366370
print_error(event.getStatus(), "Connection failed");
@@ -485,6 +489,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
485489

486490
_gap.stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE);
487491

492+
#if BLE_FEATURE_EXTENDED_ADVERTISING
488493
if (_extended_adv_handle != ble::INVALID_ADVERTISING_HANDLE) {
489494
/* if it's still active, stop it */
490495
if (_gap.isAdvertisingActive(_extended_adv_handle)) {
@@ -501,6 +506,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
501506

502507
_extended_adv_handle = ble::INVALID_ADVERTISING_HANDLE;
503508
}
509+
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
504510

505511
_is_in_scanning_phase = true;
506512

@@ -546,12 +552,14 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
546552
uint16_t events = (duration_ts / interval_ts);
547553
uint16_t extended_events = 0;
548554

555+
#if BLE_FEATURE_EXTENDED_ADVERTISING
549556
if (_extended_adv_handle != ble::INVALID_ADVERTISING_HANDLE) {
550557
duration_ts = ble::adv_interval_t(ble::millisecond_t(duration_ms)).value();
551558
interval_ts = extended_advertising_params.getMaxPrimaryInterval().value();
552559
/* this is how many times we advertised */
553560
extended_events = (duration_ts / interval_ts);
554561
}
562+
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
555563

556564
printf("We have advertised for %dms\r\n", duration_ms);
557565

@@ -562,13 +570,17 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
562570
} else {
563571
printf("We created at least %d tx and rx events\r\n", events);
564572
}
573+
574+
#if BLE_FEATURE_EXTENDED_ADVERTISING
565575
if (extended_events) {
566576
if (extended_advertising_params.getType() == ble::advertising_type_t::NON_CONNECTABLE_UNDIRECTED) {
567577
printf("We created at least %d tx events with extended advertising\r\n", extended_events);
568578
} else {
569579
printf("We created at least %d tx and rx events with extended advertising\r\n", extended_events);
570580
}
571581
}
582+
583+
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
572584
}
573585

574586
private:
@@ -588,7 +600,9 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
588600
Timer _demo_duration;
589601
size_t _scan_count = 0;
590602

603+
#if BLE_FEATURE_EXTENDED_ADVERTISING
591604
ble::advertising_handle_t _extended_adv_handle = ble::INVALID_ADVERTISING_HANDLE;
605+
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
592606
};
593607

594608
/** Schedule processing of events from the BLE middleware in the event queue. */

0 commit comments

Comments
 (0)