Skip to content

Fix extended advertising guards #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BLE_GAP/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
advertising_params.getMaxPrimaryInterval().valueInMs()
);

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

_demo_duration.reset();
_demo_duration.start();
Expand Down Expand Up @@ -350,6 +352,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
_is_connecting = false;
_demo_duration.stop();

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

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

_gap.stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE);

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

_extended_adv_handle = ble::INVALID_ADVERTISING_HANDLE;
}
#endif // BLE_FEATURE_EXTENDED_ADVERTISING

_is_in_scanning_phase = true;

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

#if BLE_FEATURE_EXTENDED_ADVERTISING
if (_extended_adv_handle != ble::INVALID_ADVERTISING_HANDLE) {
duration_ts = ble::adv_interval_t(ble::millisecond_t(duration_ms)).value();
interval_ts = extended_advertising_params.getMaxPrimaryInterval().value();
/* this is how many times we advertised */
extended_events = (duration_ts / interval_ts);
}
#endif // BLE_FEATURE_EXTENDED_ADVERTISING

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

Expand All @@ -562,13 +570,17 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
} else {
printf("We created at least %d tx and rx events\r\n", events);
}

#if BLE_FEATURE_EXTENDED_ADVERTISING
if (extended_events) {
if (extended_advertising_params.getType() == ble::advertising_type_t::NON_CONNECTABLE_UNDIRECTED) {
printf("We created at least %d tx events with extended advertising\r\n", extended_events);
} else {
printf("We created at least %d tx and rx events with extended advertising\r\n", extended_events);
}
}

#endif // BLE_FEATURE_EXTENDED_ADVERTISING
}

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

#if BLE_FEATURE_EXTENDED_ADVERTISING
ble::advertising_handle_t _extended_adv_handle = ble::INVALID_ADVERTISING_HANDLE;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
};

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