Skip to content

add tracing to scan state #14225

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
Show file tree
Hide file tree
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
31 changes: 24 additions & 7 deletions connectivity/FEATURE_BLE/source/generic/GapImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ ble_error_t Gap::stopScan()
if (err) {
return err;
}
_scan_state = ScanState::pending_stop_scan;
set_scan_state(ScanState::pending_stop_scan);
}

_scan_timeout.detach();
Expand Down Expand Up @@ -1209,7 +1209,7 @@ ble_error_t Gap::reset()

_event_handler = nullptr;
_initiating = false;
_scan_state = ScanState::idle;
set_scan_state(ScanState::idle);
_scan_requested = false;
#if BLE_FEATURE_PRIVACY
_privacy_initialization_pending = false;
Expand Down Expand Up @@ -1295,13 +1295,28 @@ void Gap::on_scan_started(bool success)
MBED_ASSERT(_scan_state == ScanState::pending_scan);

if (success) {
_scan_state = ScanState::scan;
set_scan_state(ScanState::scan);
/* if no longer want the scan */
if (!_scan_requested) {
stopScan();
}
} else {
_scan_state = ScanState::idle;
set_scan_state(ScanState::idle);
}
}

void Gap::set_scan_state(ScanState state)
{
_scan_state = state;

if (state == ScanState::idle) {
tr_info("Scan state: idle");
} else if (state == ScanState::pending_scan) {
tr_info("Scan state: pending_scan");
} else if (state == ScanState::pending_stop_scan) {
tr_info("Scan state: pending_stop_scan");
} else if (state == ScanState::scan) {
tr_info("Scan state: scan");
}
}

Expand All @@ -1313,7 +1328,7 @@ void Gap::on_scan_stopped(bool success)
return;
}

_scan_state = ScanState::idle;
set_scan_state(ScanState::idle);

#if BLE_ROLE_BROADCASTER
/* with legacy advertising we might need to wait for scanning and advertising to both stop */
Expand Down Expand Up @@ -1388,7 +1403,7 @@ void Gap::on_scan_timeout()
return;
}

_scan_state = ScanState::idle;
set_scan_state(ScanState::idle);
_scan_requested = false;

if (_event_handler) {
Expand Down Expand Up @@ -3604,6 +3619,8 @@ ble_error_t Gap::startScan(
if (ret != BLE_ERROR_NONE) {
return ret;
}
} else {
tr_warning("Cannot start scan immediately as not idle");
}

_scan_requested = true;
Expand Down Expand Up @@ -3669,7 +3686,7 @@ ble_error_t Gap::initiate_scan()
}
}

_scan_state = ScanState::pending_scan;
set_scan_state(ScanState::pending_scan);

return BLE_ERROR_NONE;
}
Expand Down
2 changes: 2 additions & 0 deletions connectivity/FEATURE_BLE/source/generic/GapImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ class Gap :

ScanState _scan_state = ScanState::idle;

void set_scan_state(ScanState state);

scan_duration_t _scan_requested_duration = scan_duration_t::forever();
duplicates_filter_t _scan_requested_filtering = duplicates_filter_t::DISABLE;
scan_period_t _scan_requested_period = scan_period_t(0);
Expand Down