Conversation
64bae68 to
f47363e
Compare
96d0ef0 to
b8438ac
Compare
This ensures that the callback will be called within the configured time (in ms) when devices fail to respond to a scan response request within that time.
b8438ac to
bdb4021
Compare
There was a problem hiding this comment.
Pull request overview
Adds an optional (and default-enabled) scan-response timeout to ensure active scanning still produces onResult callbacks even when a peripheral never sends a scan response.
Changes:
- Introduces
CONFIG_NIMBLE_CPP_SCAN_RSP_TIMEOUTconfiguration (default 30ms, 0 to disable). - Adds a host-queue callout timer to trigger a “dummy scan response” path when the timeout elapses.
- Extends scan state tracking by storing a per-device timestamp used by the timeout logic.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/nimconfig.h |
Adds user-facing config and default for scan response timeout. |
src/NimBLEScan.h |
Adds scan-response timeout timer callback declaration and callout member. |
src/NimBLEScan.cpp |
Implements timer logic and enqueues a dummy scan response event to complete results. |
src/NimBLEAdvertisedDevice.h |
Adds per-device timestamp storage used for timeout scheduling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+41
to
+42
| static ble_gap_disc_desc dummyDesc{ | ||
| .event_type = BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP, .length_data = 0, .addr{}, .rssi = 127, .data = nullptr, .direct_addr{}}; |
Comment on lines
+41
to
+54
| static ble_gap_disc_desc dummyDesc{ | ||
| .event_type = BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP, .length_data = 0, .addr{}, .rssi = 127, .data = nullptr, .direct_addr{}}; | ||
|
|
||
| extern "C" void ble_gap_rx_adv_report(ble_gap_disc_desc* desc); | ||
|
|
||
| /** | ||
| * @brief Sends dummy (null) scan response data to the scan event handler in order to | ||
| * provide the scan result to the callbacks when a device hasn't responded to the | ||
| * scan request in time. This is called by the host task from the default event queue. | ||
| */ | ||
| static void sendDummyScanResponse(ble_npl_event* ev) { | ||
| (void)ev; | ||
| ble_gap_rx_adv_report(&dummyDesc); | ||
| } |
| # if SR_TIMEOUT | ||
| static ble_npl_event dummySrTimerEvent; | ||
| static ble_gap_disc_desc dummyDesc{ | ||
| .event_type = BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP, .length_data = 0, .addr{}, .rssi = 127, .data = nullptr, .direct_addr{}}; |
Comment on lines
+65
to
+76
| ble_npl_time_t now = ble_npl_time_get(); | ||
|
|
||
| for (auto& dev : pScan->m_scanResults.m_deviceVec) { | ||
| if (dev->m_callbackSent < 2 && dev->isScannable()) { | ||
| if (!curDev || (now - dev->m_time > now - curDev->m_time)) { | ||
| nextDev = curDev; | ||
| curDev = dev; | ||
| continue; | ||
| } | ||
|
|
||
| if (!nextDev || now - dev->m_time > now - nextDev->m_time) { | ||
| nextDev = dev; |
Comment on lines
+90
to
+99
| auto nextTime = now - nextDev->m_time; | ||
| if (nextTime >= SR_TIMEOUT) { | ||
| nextTime = 1; | ||
| } else { | ||
| nextTime = SR_TIMEOUT - nextTime; | ||
| } | ||
|
|
||
| ble_npl_time_t ticks; | ||
| ble_npl_time_ms_to_ticks(nextTime, &ticks); | ||
| ble_npl_callout_reset(&pScan->m_srTimer, ticks); |
| advertisedDevice->m_time = ble_npl_time_get(); | ||
| # endif | ||
| } else { | ||
| advertisedDevice->update(event, event_type); |
Comment on lines
216
to
+231
| // If not active scanning or scan response is not available | ||
| // or extended advertisement scanning, report the result to the callback now. | ||
| if (pScan->m_scanParams.passive || !isLegacyAdv || !advertisedDevice->isScannable()) { | ||
| advertisedDevice->m_callbackSent++; | ||
| pScan->m_pScanCallbacks->onResult(advertisedDevice); | ||
| } else if (isLegacyAdv && event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) { | ||
| advertisedDevice->m_callbackSent++; | ||
| // got the scan response report the full data. | ||
| pScan->m_pScanCallbacks->onResult(advertisedDevice); | ||
| # if SR_TIMEOUT | ||
| } else if (isLegacyAdv && !ble_npl_callout_is_active(&pScan->m_srTimer)) { | ||
| // Start the timer to wait for the scan response. | ||
| ble_npl_time_t ticks; | ||
| ble_npl_time_ms_to_ticks(SR_TIMEOUT, &ticks); | ||
| ble_npl_callout_reset(&pScan->m_srTimer, ticks); | ||
| # endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ensures that the callback will be called within the configured time (in ms) when devices fail to respond to a scan response request within that time.
Closes #591