mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Notify application when advertising start or stop
Applicable for legacy and extended advertising.pull/13759/head
parent
6ee5740941
commit
f32141a051
|
|
@ -314,6 +314,17 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when advertising starts.
|
||||||
|
*
|
||||||
|
* @param event Advertising start event.
|
||||||
|
*
|
||||||
|
* @see startAdvertising()
|
||||||
|
*/
|
||||||
|
virtual void onAdvertisingStart(const AdvertisingStartEvent &event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when advertising ends.
|
* Called when advertising ends.
|
||||||
*
|
*
|
||||||
|
|
@ -732,6 +743,7 @@ public:
|
||||||
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
|
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
|
||||||
* @return BLE_ERROR_NONE on success.
|
* @return BLE_ERROR_NONE on success.
|
||||||
*
|
*
|
||||||
|
* @see EventHandler::onAdvertisingStart when the advertising starts.
|
||||||
* @see EventHandler::onScanRequestReceived when a scan request is received.
|
* @see EventHandler::onScanRequestReceived when a scan request is received.
|
||||||
* @see EventHandler::onAdvertisingEnd when the advertising ends.
|
* @see EventHandler::onAdvertisingEnd when the advertising ends.
|
||||||
* @see EventHandler::onConnectionComplete when the device gets connected
|
* @see EventHandler::onConnectionComplete when the device gets connected
|
||||||
|
|
|
||||||
|
|
@ -575,15 +575,47 @@ private:
|
||||||
*/
|
*/
|
||||||
struct ScanTimeoutEvent { };
|
struct ScanTimeoutEvent { };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event produced when advertising start.
|
||||||
|
*
|
||||||
|
* @see ble::Gap::EventHandler::onAdvertisingStart().
|
||||||
|
*/
|
||||||
|
struct AdvertisingStartEvent {
|
||||||
|
#if !defined(DOXYGEN_ONLY)
|
||||||
|
|
||||||
|
/** Create an advertising start event.
|
||||||
|
*
|
||||||
|
* @param advHandle Advertising set handle.
|
||||||
|
*/
|
||||||
|
AdvertisingStartEvent(advertising_handle_t advHandle) :
|
||||||
|
advHandle(advHandle)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Get advertising handle. */
|
||||||
|
advertising_handle_t getAdvHandle() const
|
||||||
|
{
|
||||||
|
return advHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
advertising_handle_t advHandle;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event produced when advertising ends.
|
* Event produced when advertising ends.
|
||||||
*
|
*
|
||||||
* @see ble::Gap::EventHandler::onAdvertisingEnd().
|
* @see ble::Gap::EventHandler::onAdvertisingEnd().
|
||||||
|
*
|
||||||
|
* @note The connection handle, connected flag and completed_event fields are
|
||||||
|
* valid if the flag legacy is not set to true.
|
||||||
*/
|
*/
|
||||||
struct AdvertisingEndEvent {
|
struct AdvertisingEndEvent {
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
|
|
||||||
/** Create advertising end event.
|
/** Create an extended advertising end event.
|
||||||
*
|
*
|
||||||
* @param advHandle Advertising set handle.
|
* @param advHandle Advertising set handle.
|
||||||
* @param connection Connection handle.
|
* @param connection Connection handle.
|
||||||
|
|
@ -599,7 +631,19 @@ struct AdvertisingEndEvent {
|
||||||
advHandle(advHandle),
|
advHandle(advHandle),
|
||||||
connection(connection),
|
connection(connection),
|
||||||
completed_events(completed_events),
|
completed_events(completed_events),
|
||||||
connected(connected)
|
connected(connected),
|
||||||
|
legacy(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create a legacy advertising end event.
|
||||||
|
*/
|
||||||
|
AdvertisingEndEvent() :
|
||||||
|
advHandle(LEGACY_ADVERTISING_HANDLE),
|
||||||
|
connection(),
|
||||||
|
completed_events(0),
|
||||||
|
connected(false),
|
||||||
|
legacy(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -629,11 +673,22 @@ struct AdvertisingEndEvent {
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Is the end of legacy advertising.
|
||||||
|
*
|
||||||
|
* If it is the return of getConnection() getCompleted_events() and isConnected()
|
||||||
|
* must be discarded
|
||||||
|
*/
|
||||||
|
bool isLegacy() const
|
||||||
|
{
|
||||||
|
return legacy;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
advertising_handle_t advHandle;
|
advertising_handle_t advHandle;
|
||||||
connection_handle_t connection;
|
connection_handle_t connection;
|
||||||
uint8_t completed_events;
|
uint8_t completed_events;
|
||||||
bool connected;
|
bool connected;
|
||||||
|
bool legacy;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1199,6 +1199,7 @@ void Gap::on_scan_stopped(bool success)
|
||||||
if (restart_advertising) {
|
if (restart_advertising) {
|
||||||
_address_refresh_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
_address_refresh_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
||||||
startAdvertising(LEGACY_ADVERTISING_HANDLE);
|
startAdvertising(LEGACY_ADVERTISING_HANDLE);
|
||||||
|
_adv_started_from_refresh.set(LEGACY_ADVERTISING_HANDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
_scan_address_refresh = false;
|
_scan_address_refresh = false;
|
||||||
|
|
@ -2804,11 +2805,18 @@ void Gap::on_legacy_advertising_started()
|
||||||
{
|
{
|
||||||
_active_sets.set(LEGACY_ADVERTISING_HANDLE);
|
_active_sets.set(LEGACY_ADVERTISING_HANDLE);
|
||||||
_pending_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
_pending_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
||||||
|
|
||||||
|
if (_adv_started_from_refresh.get(LEGACY_ADVERTISING_HANDLE)) {
|
||||||
|
_adv_started_from_refresh.clear(LEGACY_ADVERTISING_HANDLE);
|
||||||
|
} else if(_event_handler) {
|
||||||
|
_event_handler->onAdvertisingStart(
|
||||||
|
AdvertisingStartEvent(LEGACY_ADVERTISING_HANDLE)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gap::on_legacy_advertising_stopped()
|
void Gap::on_legacy_advertising_stopped()
|
||||||
{
|
{
|
||||||
|
|
||||||
_active_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
_active_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
||||||
_pending_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
_pending_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
||||||
|
|
||||||
|
|
@ -2819,10 +2827,13 @@ void Gap::on_legacy_advertising_stopped()
|
||||||
if (_address_refresh_sets.get(LEGACY_ADVERTISING_HANDLE) && !wait_for_scan_stop) {
|
if (_address_refresh_sets.get(LEGACY_ADVERTISING_HANDLE) && !wait_for_scan_stop) {
|
||||||
_address_refresh_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
_address_refresh_sets.clear(LEGACY_ADVERTISING_HANDLE);
|
||||||
startAdvertising(LEGACY_ADVERTISING_HANDLE);
|
startAdvertising(LEGACY_ADVERTISING_HANDLE);
|
||||||
|
_adv_started_from_refresh.set(LEGACY_ADVERTISING_HANDLE);
|
||||||
if (restart_scan) {
|
if (restart_scan) {
|
||||||
_scan_address_refresh = false;
|
_scan_address_refresh = false;
|
||||||
startScan();
|
startScan();
|
||||||
}
|
}
|
||||||
|
} else if (_event_handler) {
|
||||||
|
_event_handler->onAdvertisingEnd(AdvertisingEndEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2831,6 +2842,13 @@ void Gap::on_advertising_set_started(const mbed::Span<const uint8_t>& handles)
|
||||||
for (const auto &handle : handles) {
|
for (const auto &handle : handles) {
|
||||||
_active_sets.set(handle);
|
_active_sets.set(handle);
|
||||||
_pending_sets.clear(handle);
|
_pending_sets.clear(handle);
|
||||||
|
if (_adv_started_from_refresh.get(handle)) {
|
||||||
|
_adv_started_from_refresh.clear(handle);
|
||||||
|
} else if (_event_handler) {
|
||||||
|
_event_handler->onAdvertisingStart(
|
||||||
|
AdvertisingStartEvent(LEGACY_ADVERTISING_HANDLE)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2848,6 +2866,7 @@ void Gap::on_advertising_set_terminated(
|
||||||
if (_address_refresh_sets.get(advertising_handle) && !connection_handle) {
|
if (_address_refresh_sets.get(advertising_handle) && !connection_handle) {
|
||||||
_address_refresh_sets.clear(advertising_handle);
|
_address_refresh_sets.clear(advertising_handle);
|
||||||
startAdvertising(advertising_handle);
|
startAdvertising(advertising_handle);
|
||||||
|
_adv_started_from_refresh.set(advertising_handle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -923,6 +923,7 @@ private:
|
||||||
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _pending_sets;
|
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _pending_sets;
|
||||||
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _address_refresh_sets;
|
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _address_refresh_sets;
|
||||||
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _interruptible_sets;
|
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _interruptible_sets;
|
||||||
|
BitArray<BLE_GAP_MAX_ADVERTISING_SETS> _adv_started_from_refresh;
|
||||||
|
|
||||||
|
|
||||||
bool _user_manage_connection_parameter_requests : 1;
|
bool _user_manage_connection_parameter_requests : 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue