Skip to content
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
49 changes: 38 additions & 11 deletions BLE_GAP/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,40 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle

void onAdvertisingEnd(const ble::AdvertisingEndEvent &event) override
{
if (event.isConnected()) {
printf("Stopped advertising early due to connection\r\n");
ble::advertising_handle_t adv_handle = event.getAdvHandle();
if (event.getStatus() == BLE_ERROR_UNSPECIFIED) {
printf("Error: Failed to stop advertising set %d\r\n", adv_handle);
} else {
printf("Stopped advertising set %d\r\n", adv_handle);

if (event.getStatus() == BLE_ERROR_TIMEOUT) {
printf("Stopped due to timeout\r\n");
} else if (event.getStatus() == BLE_ERROR_LIMIT_REACHED) {
printf("Stopped due to max number of adv events reached\r\n");
} else if (event.getStatus() == BLE_ERROR_NONE) {
if (event.isConnected()) {
printf("Stopped early due to connection\r\n");
} else {
printf("Stopped due to user request\r\n");
}
}
}

#if BLE_FEATURE_EXTENDED_ADVERTISING
if (event.getAdvHandle() == _extended_adv_handle) {
/* we were waiting for it to stop before destroying it and starting scanning */
ble_error_t error = _gap.destroyAdvertisingSet(_extended_adv_handle);
if (error) {
print_error(error, "Error caused by Gap::destroyAdvertisingSet");
}

_extended_adv_handle = ble::INVALID_ADVERTISING_HANDLE;

_is_in_scanning_phase = true;

_event_queue.call_in(delay, [this]{ scan(); });
}
#endif //BLE_FEATURE_EXTENDED_ADVERTISING
}

void onAdvertisingStart(const ble::AdvertisingStartEvent &event) override
Expand Down Expand Up @@ -488,6 +519,8 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
{
print_advertising_performance();

printf("Requesting stop advertising.\r\n");

_gap.stopAdvertising(ble::LEGACY_ADVERTISING_HANDLE);

#if BLE_FEATURE_EXTENDED_ADVERTISING
Expand All @@ -499,19 +532,13 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
print_error(error, "Error caused by Gap::stopAdvertising");
}
}

ble_error_t error = _gap.destroyAdvertisingSet(_extended_adv_handle);
if (error) {
print_error(error, "Error caused by Gap::destroyAdvertisingSet");
}

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

/* we have to wait before we destroy it until it's stopped */
#else
_is_in_scanning_phase = true;

_event_queue.call_in(delay, [this]{ scan(); });
#endif // BLE_FEATURE_EXTENDED_ADVERTISING
}

/** print some information about our radio activity */
Expand Down