Skip to content

Commit 6da3019

Browse files
committed
Jira 896, BLE scan withDuplicates logic inversion, git 476
Bug fixed: This feature was implemented in PR arduino#457, merged, and released in Deneb.RC1. However, it was discovered that the logic was inverted and was report as Git issue arduino#476. BLE scan() and input parameter withDuplicates is true means reporting all Peripherals detected regardless how many times it was reported. Code mods: 1. libraries/CurieBLE/src/BLEDevice.cpp: - In startScan, calls the correct routine to scan for all Peripherals if withDuplicates is true. Otherwise, just scan for new ones. 2. libraries/CurieBLE/src/BLEDevice.h: - Prototyping. 3. libraries/CurieBLE/src/internal/BLEDeviceManager.h, libraries/CurieBLE/src/internal/BLEDeviceManager.cpp - Modified header comment to reflect the input parameter withDuplictes correct meaning. - Default the input parameter, withDupilcates, as true. - And, consequently, eliminated some redundant methods.
1 parent 6f4f579 commit 6da3019

File tree

4 files changed

+43
-72
lines changed

4 files changed

+43
-72
lines changed

Diff for: libraries/CurieBLE/src/BLEDevice.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -247,38 +247,22 @@ bool BLEDevice::startScan(bool withDuplicates)
247247
}
248248
else
249249
{
250-
return BLEDeviceManager::instance()->startScanning();
250+
return BLEDeviceManager::instance()->startScanningNewPeripherals();
251251
}
252252
}
253253

254-
255-
void BLEDevice::scan()
256-
{
257-
scan(false);
258-
}
259-
260254
void BLEDevice::scan(bool withDuplicates)
261255
{
262256
BLEDeviceManager::instance()->clearAdvertiseCritical();
263257
startScan(withDuplicates);
264258
}
265259

266-
void BLEDevice::scanForName(String name)
267-
{
268-
scanForName(name, false);
269-
}
270-
271260
void BLEDevice::scanForName(String name, bool withDuplicates)
272261
{
273262
BLEDeviceManager::instance()->setAdvertiseCritical(name);
274263
startScan(withDuplicates);
275264
}
276265

277-
void BLEDevice::scanForUuid(String uuid)
278-
{
279-
scanForUuid(uuid, false);
280-
}
281-
282266
void BLEDevice::scanForUuid(String uuid, bool withDuplicates)
283267
{
284268
BLEService service_temp(uuid.c_str());

Diff for: libraries/CurieBLE/src/BLEDevice.h

+37-50
Original file line numberDiff line numberDiff line change
@@ -361,83 +361,70 @@ class BLEDevice
361361
//void scanForAddress(String address); // Not include in baseline. Add here as feature for feature release.
362362

363363
/**
364-
* @brief Start scanning for peripherals without filter
364+
* @brief Start scanning for peripherals with the option of accepting all detectable
365+
* Peripherals or just the newly detected.
365366
*
366-
* @param none
367-
*
368-
* @return none
369-
*
370-
* @note none
371-
*/
372-
void scan();
373-
374-
/**
375-
* @brief Start scanning for peripherals with filter
376-
*
377-
* @param[in] withDuplicates true - with duplicate filter
378-
* false- without duplicate filter
379-
*
380-
* @return none
381-
*
382-
* @note option to filter out duplicate addresses for Arduino.
383-
* The current only support fileter duplicate mode.
384-
*/
385-
void scan(bool withDuplicates);
386-
387-
/**
388-
* @brief Start scanning for peripherals and filter by device name in ADV
389-
*
390-
* @param name The device's local name.
367+
* @param[in] withDuplicates true - return all detectable Peripherals.
368+
* false- return only new Peripherals.
391369
*
392370
* @return none
393371
*
394-
* @note option to filter out duplicate addresses for Arduino.
395-
* The current only support fileter duplicate mode.
372+
* @note When, withDuplicates = true (default), accept all detectable Peripherals.
373+
* No Peripheral filtering process applied to the scan result.
396374
*/
397-
void scanForName(String name);
375+
void scan(bool withDuplicates = true);
398376

399377
/**
400-
* @brief Start scanning for peripherals and filter by device name in ADV
378+
* @brief Start scanning for peripherals and filter by device name in ADV and
379+
* the option of accepting all detectable Peripherals or just the
380+
* newly detected.
401381
*
402382
* @param[in] name The device's local name.
403383
*
404-
* @param[in] withDuplicates true - with duplicate filter
405-
* false- without duplicate filter
384+
* @param[in] withDuplicates true - return all detectable Peripherals.
385+
* false- return only new Peripherals.
406386
*
407387
* @return none
408388
*
409-
* @note option to filter out duplicate addresses for Arduino.
410-
* The current only support fileter duplicate mode.
389+
* @note When, withDuplicates = true (default), accept all detectable Peripherals.
390+
* No Peripheral filtering process applied to the scan result.
411391
*/
412-
void scanForName(String name, bool withDuplicates);
392+
void scanForName(String name, bool withDuplicates = true);
413393

414394
/**
415-
* @brief Start scanning for peripherals and filter by service in ADV
395+
* @brief Start scanning for peripherals and filter by service in ADV and
396+
* the option of accepting all detectable Peripherals or just the
397+
* newly detected.
416398
*
417-
* @param service The service
399+
* @param[in] service The service
400+
*
401+
* @param[in] withDuplicates true - return all detectable Peripherals.
402+
* false- return only new Peripherals.
418403
*
419404
* @return none
420405
*
421-
* @note none
406+
* @note When, withDuplicates = true (default), accept all detectable Peripherals.
407+
* No Peripheral filtering process applied to the scan result.
422408
*/
423-
void scanForUuid(String uuid);
409+
void scanForUuid(String uuid, bool withDuplicates = true);
424410

425411
/**
426-
* @brief Start scanning for peripherals and filter by service in ADV
412+
* @brief Start scanning for peripherals and filter by MAC address and
413+
* the option of accepting all detectable Peripherals or just the
414+
* newly detected.
427415
*
428-
* @param[in] service The service
416+
* @param[in] macaddr The Peripheral MAC address
429417
*
430-
* @param[in] withDuplicates true - with duplicate filter
431-
* false- without duplicate filter
418+
* @param[in] withDuplicates true - return all detectable Peripherals.
419+
* false- return only new Peripherals.
432420
*
433421
* @return none
434422
*
435-
* @note option to filter out duplicate addresses for Arduino.
436-
* The current only support fileter duplicate mode.
423+
* @note When, withDuplicates = true (default), accept all detectable Peripherals.
424+
* No Peripheral filtering process applied to the scan result.
437425
*/
438-
void scanForUuid(String uuid, bool withDuplicates);
439-
440426
void scanForAddress(String macaddr, bool withDuplicates = true);
427+
441428
/**
442429
* @brief Stop scanning for peripherals
443430
*
@@ -679,15 +666,15 @@ class BLEDevice
679666
void preCheckProfile();
680667

681668
/**
682-
* @brief Start scanning for peripherals with/without duplicate filter
669+
* @brief Start scanning for peripherals with the option of accepting all
670+
* detectable Peripherals or just the newly detected.
683671
*
684672
* @param[in] withDuplicates true - with duplicate filter
685673
* false- without duplicate filter
686674
*
687675
* @return none
688676
*
689-
* @note option to filter out duplicate addresses for Arduino.
690-
* The current only support fileter duplicate mode.
677+
* @note When, withDuplicates = true (default), accept all detectable Peripherals.
691678
*/
692679
bool startScan(bool withDuplicates);
693680

Diff for: libraries/CurieBLE/src/internal/BLEDeviceManager.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ void BLEDeviceManager::_clearAdvertiseBuffer()
593593

594594
}
595595

596-
bool BLEDeviceManager::startScanning()
596+
bool BLEDeviceManager::startScanningWithDuplicates()
597597
{
598598
_adv_duplicate_filter_enabled = false;
599599
_scan_param.filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE;
@@ -609,7 +609,7 @@ bool BLEDeviceManager::startScanning()
609609
return true;
610610
}
611611

612-
bool BLEDeviceManager::startScanningWithDuplicates()
612+
bool BLEDeviceManager::startScanningNewPeripherals()
613613
{
614614
_adv_duplicate_filter_enabled = true;
615615
memset(_peer_duplicate_address_buffer, 0, sizeof(_peer_duplicate_address_buffer));
@@ -1096,8 +1096,8 @@ bool BLEDeviceManager::connect(BLEDevice &device)
10961096
_wait_for_connect_peripheral_adv_data_len = _available_for_connect_peripheral_adv_data_len;
10971097
_wait_for_connect_peripheral_scan_rsp_data_len = _available_for_connect_peripheral_scan_rsp_data_len;
10981098
_wait_for_connect_peripheral_adv_rssi = _available_for_connect_peripheral_adv_rssi;
1099-
1100-
startScanning();
1099+
1100+
startScanningWithDuplicates();
11011101

11021102
pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
11031103
// Wait for the connection

Diff for: libraries/CurieBLE/src/internal/BLEDeviceManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class BLEDeviceManager
310310
void setAdvertiseCritical(String name);
311311
void setAdvertiseCritical(BLEService& service);
312312
void setAdvertiseCritical(const char* macaddress);
313-
bool startScanning(); // start scanning for peripherals
313+
bool startScanningNewPeripherals(); // start scanning for new peripherals, don't report the detected ones
314314
bool startScanningWithDuplicates(); // start scanning for peripherals, and report all duplicates
315315
bool stopScanning(); // stop scanning for peripherals
316316

0 commit comments

Comments
 (0)