Skip to content

Commit 0027f8b

Browse files
add tracing to scan state (#14225)
1 parent 03abb52 commit 0027f8b

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ ble_error_t Gap::stopScan()
518518
if (err) {
519519
return err;
520520
}
521-
_scan_state = ScanState::pending_stop_scan;
521+
set_scan_state(ScanState::pending_stop_scan);
522522
}
523523

524524
_scan_timeout.detach();
@@ -1209,7 +1209,7 @@ ble_error_t Gap::reset()
12091209

12101210
_event_handler = nullptr;
12111211
_initiating = false;
1212-
_scan_state = ScanState::idle;
1212+
set_scan_state(ScanState::idle);
12131213
_scan_requested = false;
12141214
#if BLE_FEATURE_PRIVACY
12151215
_privacy_initialization_pending = false;
@@ -1295,13 +1295,28 @@ void Gap::on_scan_started(bool success)
12951295
MBED_ASSERT(_scan_state == ScanState::pending_scan);
12961296

12971297
if (success) {
1298-
_scan_state = ScanState::scan;
1298+
set_scan_state(ScanState::scan);
12991299
/* if no longer want the scan */
13001300
if (!_scan_requested) {
13011301
stopScan();
13021302
}
13031303
} else {
1304-
_scan_state = ScanState::idle;
1304+
set_scan_state(ScanState::idle);
1305+
}
1306+
}
1307+
1308+
void Gap::set_scan_state(ScanState state)
1309+
{
1310+
_scan_state = state;
1311+
1312+
if (state == ScanState::idle) {
1313+
tr_info("Scan state: idle");
1314+
} else if (state == ScanState::pending_scan) {
1315+
tr_info("Scan state: pending_scan");
1316+
} else if (state == ScanState::pending_stop_scan) {
1317+
tr_info("Scan state: pending_stop_scan");
1318+
} else if (state == ScanState::scan) {
1319+
tr_info("Scan state: scan");
13051320
}
13061321
}
13071322

@@ -1313,7 +1328,7 @@ void Gap::on_scan_stopped(bool success)
13131328
return;
13141329
}
13151330

1316-
_scan_state = ScanState::idle;
1331+
set_scan_state(ScanState::idle);
13171332

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

1391-
_scan_state = ScanState::idle;
1406+
set_scan_state(ScanState::idle);
13921407
_scan_requested = false;
13931408

13941409
if (_event_handler) {
@@ -3604,6 +3619,8 @@ ble_error_t Gap::startScan(
36043619
if (ret != BLE_ERROR_NONE) {
36053620
return ret;
36063621
}
3622+
} else {
3623+
tr_warning("Cannot start scan immediately as not idle");
36073624
}
36083625

36093626
_scan_requested = true;
@@ -3669,7 +3686,7 @@ ble_error_t Gap::initiate_scan()
36693686
}
36703687
}
36713688

3672-
_scan_state = ScanState::pending_scan;
3689+
set_scan_state(ScanState::pending_scan);
36733690

36743691
return BLE_ERROR_NONE;
36753692
}

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ class Gap :
907907

908908
ScanState _scan_state = ScanState::idle;
909909

910+
void set_scan_state(ScanState state);
911+
910912
scan_duration_t _scan_requested_duration = scan_duration_t::forever();
911913
duplicates_filter_t _scan_requested_filtering = duplicates_filter_t::DISABLE;
912914
scan_period_t _scan_requested_period = scan_period_t(0);

0 commit comments

Comments
 (0)