From 05080abad4a93404863f7ee243d78d0c884ff1b4 Mon Sep 17 00:00:00 2001 From: h2zero Date: Wed, 31 Mar 2021 20:24:57 -0600 Subject: [PATCH] Add clear scan duplicate filter cache method + clear on start. This allows for clearing the duplicate filter cache when required and will also clear it automatically when starting a scan. This is useful when unexpectedly disconnected from a device and attempting to reconnect. Previously the scan filter would not report advertisements from a device if it was multi-connectable and advertising while connected. The result was long delays until the device would be scanned again. This resolves it by clearing the filter cache on each scan start/clearResults call and adding a method to NimBLEScan for manually clearing the cache on demand. --- src/NimBLEScan.cpp | 11 +++++++++++ src/NimBLEScan.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/NimBLEScan.cpp b/src/NimBLEScan.cpp index 00aeab0..bc08896 100644 --- a/src/NimBLEScan.cpp +++ b/src/NimBLEScan.cpp @@ -316,6 +316,8 @@ bool NimBLEScan::start(uint32_t duration, void (*scanCompleteCB)(NimBLEScanResul break; case BLE_HS_EALREADY: + // Clear the cache if already scanning in case an advertiser was missed. + clearDuplicateCache(); break; case BLE_HS_EBUSY: @@ -398,6 +400,14 @@ bool NimBLEScan::stop() { } // stop +/** + * @brief Clears the duplicate scan filter cache. + */ +void NimBLEScan::clearDuplicateCache() { + esp_ble_scan_dupilcate_list_flush(); +} + + /** * @brief Delete peer device from the scan results vector. * @param [in] address The address of the device to delete from the results. @@ -453,6 +463,7 @@ void NimBLEScan::clearResults() { delete it; } m_scanResults.m_advertisedDevicesVector.clear(); + clearDuplicateCache(); } diff --git a/src/NimBLEScan.h b/src/NimBLEScan.h index 57e7430..49d67c8 100644 --- a/src/NimBLEScan.h +++ b/src/NimBLEScan.h @@ -70,6 +70,7 @@ public: void setDuplicateFilter(bool enabled); void setLimitedOnly(bool enabled); void setFilterPolicy(uint8_t filter); + void clearDuplicateCache(); bool stop(); void clearResults(); NimBLEScanResults getResults();