HumanDynamics / openbadge

MIT License
49 stars 19 forks source link

Store only top 29 devices from scan by RSSI #67

Closed abartow closed 7 years ago

abartow commented 7 years ago

This commit changes the scanner to only store the top 29 devices (SCAN_DEVICES_PER_CHUNK) in any scan. This should allow us to deal with situations where there are many nearby devices without having to make major codebase changes.

This change functions by sorting the scan struct by RSSI and then setting scan.num to truncate the struct. We only do this if there were more than SCAN_DEVICES_PER_CHUNK in a scan, so the behavior in any other case is unchanged.

Testing Methodology:

For a given test I:

  1. Used the get_mock_adv_report_for_badge_with_id(id) function to generate mock BLE advertising reports for the specified number of devices. (The code for this function can be viewed in commit f3bf81a that removed it, but in short in mocked a device with id id and RSSI -100 + id.
  2. Watched the UART logs to ensure that the specified number of devices were stored correctly, verifying expected RSSI vs ID.
  3. Requested the data for that scan over BLE, and ensured the scan contained the correct number of devices with the expected RSSI - ID pairings.

I performed this test for the number of scan devices = 0, 1, 28 (just under one chunk), 29 (one chunk exactly), 30 (one chunk plus one device), 50 (one chunk plus some), 100 (max num devices per scan), and 105 (excess of max num devices per scan, additional devices should just be ignored).

I also performed an additional test where I mocked out some devices in addition to the iBeacon I had, which verified the code worked with an iBeacon, and that the sorting works even when two devices have the same RSSI.

abartow commented 7 years ago

I should add I've mostly tested this by mocking out devices into the BLEAdv event handler. If you could test in a place with actually many many devices, that would be great.

OrenLederman commented 7 years ago

This seems to fix bug #70 as well