mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Update state when scan started/stopped callback received.
parent
d8c6820cbd
commit
924f8b1dc9
|
@ -459,12 +459,10 @@ ble_error_t Gap::stopScan()
|
|||
{
|
||||
ble_error_t err;
|
||||
|
||||
if (!_scan_enabled) {
|
||||
if ((!_scan_enabled && !_scan_pending) || _scan_pending) {
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
_scan_enabled = false;
|
||||
|
||||
if (is_extended_advertising_available()) {
|
||||
err = _pal_gap.extended_scan_enable(false, duplicates_filter_t::DISABLE, 0, 0);
|
||||
} else {
|
||||
|
@ -472,10 +470,10 @@ ble_error_t Gap::stopScan()
|
|||
}
|
||||
|
||||
if (err) {
|
||||
_scan_enabled = true;
|
||||
return err;
|
||||
}
|
||||
|
||||
_scan_pending = true;
|
||||
_scan_timeout.detach();
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
|
@ -1053,10 +1051,19 @@ Gap::GapShutdownCallbackChain_t &Gap::onShutdown()
|
|||
|
||||
void Gap::on_scan_started(bool success)
|
||||
{
|
||||
if (success) {
|
||||
_scan_pending = false;
|
||||
_scan_enabled = true;
|
||||
} else {
|
||||
_scan_pending = false;
|
||||
_scan_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Gap::on_scan_stopped(bool success)
|
||||
{
|
||||
_scan_pending = false;
|
||||
_scan_enabled = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1067,29 +1074,21 @@ void Gap::on_scan_timeout()
|
|||
}
|
||||
|
||||
_scan_enabled = false;
|
||||
_scan_pending = false;
|
||||
|
||||
if (!is_extended_advertising_available()) {
|
||||
/* if timeout happened on a 4.2 chip this means legacy scanning and a timer timeout
|
||||
* but we need to handle the event from user context - use the event queue to handle it */
|
||||
_event_queue.post(
|
||||
mbed::callback(
|
||||
this,
|
||||
&Gap::process_legacy_scan_timeout
|
||||
)
|
||||
);
|
||||
} else {
|
||||
if (_event_handler) {
|
||||
_event_handler->onScanTimeout(ScanTimeoutEvent());
|
||||
}
|
||||
if (_event_handler) {
|
||||
_event_handler->onScanTimeout(ScanTimeoutEvent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Gap::process_legacy_scan_timeout()
|
||||
{
|
||||
if (!_scan_enabled) {
|
||||
return;
|
||||
}
|
||||
/* legacy scanning timed out is based on timer so we need to stop the scan manually */
|
||||
_pal_gap.scan_enable(false, false);
|
||||
_scan_enabled = false;
|
||||
|
||||
if (_event_handler) {
|
||||
_event_handler->onScanTimeout(ScanTimeoutEvent());
|
||||
|
@ -2666,14 +2665,17 @@ ble_error_t Gap::startScan(
|
|||
|
||||
_scan_timeout.detach();
|
||||
if (duration.value()) {
|
||||
_scan_timeout.attach(
|
||||
mbed::callback(this, &Gap::on_scan_timeout),
|
||||
_scan_timeout.attach([this]() {
|
||||
_event_queue.post([this] { process_legacy_scan_timeout(); });
|
||||
},
|
||||
duration.valueChrono()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_scan_enabled = true;
|
||||
if (!_scan_enabled) {
|
||||
_scan_pending = true;
|
||||
}
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
@ -2957,7 +2959,7 @@ bool Gap::is_advertising() const
|
|||
}
|
||||
|
||||
bool Gap::is_radio_active() const {
|
||||
return _initiating || _scan_enabled || is_advertising();
|
||||
return _initiating || _scan_enabled || _scan_pending || is_advertising();
|
||||
}
|
||||
|
||||
void Gap::update_advertising_set_connectable_attribute(
|
||||
|
|
|
@ -585,7 +585,8 @@ private:
|
|||
peripheral_privacy_configuration_t _peripheral_privacy_configuration;
|
||||
central_privacy_configuration_t _central_privacy_configuration;
|
||||
|
||||
bool _scan_enabled;
|
||||
bool _scan_enabled = false;
|
||||
bool _scan_pending = false;
|
||||
mbed::LowPowerTimeout _advertising_timeout;
|
||||
mbed::LowPowerTimeout _scan_timeout;
|
||||
mbed::LowPowerTicker _address_rotation_ticker;
|
||||
|
|
Loading…
Reference in New Issue