@@ -507,6 +507,7 @@ class BleGap {
507
507
advParams_{},
508
508
advTimeoutTimer_ (nullptr ),
509
509
isScanning_ (false ),
510
+ notifyScanResult_ (false ),
510
511
scanParams_{},
511
512
scanSemaphore_ (nullptr ),
512
513
scanResultCallback_ (nullptr ),
@@ -640,6 +641,7 @@ class BleGap {
640
641
hal_ble_adv_params_t advParams_;
641
642
os_timer_t advTimeoutTimer_; /* *< Timer for advertising timeout. */
642
643
volatile bool isScanning_; /* *< If it is scanning or not. */
644
+ volatile bool notifyScanResult_;
643
645
hal_ble_scan_params_t scanParams_; /* *< BLE scanning parameters. */
644
646
os_semaphore_t scanSemaphore_; /* *< Semaphore to wait until the scan procedure completed. */
645
647
hal_ble_on_scan_result_cb_t scanResultCallback_; /* *< Callback function on scan result. */
@@ -1672,6 +1674,7 @@ int BleGap::startScanning(hal_ble_on_scan_result_cb_t callback, void* context) {
1672
1674
1673
1675
CHECK_RTL (WRAP_BLE_EVT_LOCK (le_scan_start ()));
1674
1676
isScanning_ = true ;
1677
+ notifyScanResult_ = true ;
1675
1678
// GAP_SCAN_STATE_SCANNING may be propagated immediately following the GAP_SCAN_STATE_START
1676
1679
// IMPORTANT: have to poll here, for some reason we may not get notified
1677
1680
if (waitState (BleGapDevState ().scan (GAP_SCAN_STATE_SCANNING), BLE_STATE_DEFAULT_TIMEOUT, true /* forcePoll */ )) {
@@ -1694,7 +1697,7 @@ int BleGap::startScanning(hal_ble_on_scan_result_cb_t callback, void* context) {
1694
1697
1695
1698
int BleGap::stopScanning (bool resetStack) {
1696
1699
BleLock lk;
1697
-
1700
+ notifyScanResult_ = false ;
1698
1701
if (!isScanning_) {
1699
1702
return SYSTEM_ERROR_NONE;
1700
1703
}
@@ -1754,7 +1757,7 @@ int BleGap::stopScanning(bool resetStack) {
1754
1757
1755
1758
// This function is called from thread
1756
1759
void BleGap::notifyScanResult (T_LE_SCAN_INFO* advReport) {
1757
- if (!isScanning_ || !scanResultCallback_) {
1760
+ if (!isScanning_ || !scanResultCallback_ || !notifyScanResult_ ) {
1758
1761
return ;
1759
1762
}
1760
1763
0 commit comments