Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ble stop scanning #2796

Merged
merged 4 commits into from
Aug 12, 2024
Merged

Fix/ble stop scanning #2796

merged 4 commits into from
Aug 12, 2024

Conversation

avtolstoy
Copy link
Member

@avtolstoy avtolstoy commented Jul 5, 2024

Problem

  1. BLE.stopScanning() on Gen 4 is broken since 5.8.2 from inside ble scan result callback.
  2. In general behavior of Gen 3/4 scan() and stopScanning() is currently slightly different. Also different with indefinite/timed scans.
  3. No-fixture tests are missing for this.

Solution

  1. Fix this by making sure that only the scan caller semaphore is unblocked if hal_ble_gap_stop_scanning() is called from inside the ble event thread (the one ble results are being notified to the application from)
  2. Streamline the behavior to be:
    2.1. BLE.scan() is blocking no matter the timeout, but once scanning is started - BLE lock is not held, allowing other BLE operations to be performed.
    2.2. BLE.stopScanning() works correctly when called both from inside the scan result callback/other BLE callbacks and from some other thread (be that application/system/timer/custom etc).
    2.3. If called from a normal thread BLE.stopScanning() is a blocking operation and scanning MUST be stopped once its execution completes.
  3. Add a set of tests to validate scan/stopScanning.

Steps to Test

  • wiring/no_fixture_ble
  • wiring/ble_central_peripheral
  • wiring/ble_scanner_broadcaster

For cross-platform testing with test runner: particle-iot/device-os-test-runner#28

Example App

void setup() {
  /* A minimal example app is super helpful 
   * for testing new features and fixes. 
   * A link to a Docs PR is even better!
   */
}

void loop() {

}

References

Links to the Community, Docs, Other Issues, etc..


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@avtolstoy avtolstoy requested a review from XuGuohui July 5, 2024 23:35
@avtolstoy avtolstoy added this to the 5.8.3 milestone Jul 5, 2024
hal/src/nRF52840/ble_hal.cpp Show resolved Hide resolved
hal/src/nRF52840/ble_hal.cpp Show resolved Hide resolved
hal/src/nRF52840/ble_hal.cpp Show resolved Hide resolved
@avtolstoy avtolstoy force-pushed the fix/ble-stop-scanning branch from 0317538 to cb0757d Compare July 9, 2024 15:58
Copy link
Member

@XuGuohui XuGuohui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. no_fixture_ble passed
  2. ble_central_peripheral passed

@Kategrode Kategrode modified the milestones: 5.8.3, 5.9.0 Jul 29, 2024
@avtolstoy avtolstoy force-pushed the fix/ble-stop-scanning branch from cc7b3fa to 8ffeeba Compare August 12, 2024 18:22
@avtolstoy avtolstoy merged commit 615a136 into develop Aug 12, 2024
13 checks passed
@avtolstoy avtolstoy deleted the fix/ble-stop-scanning branch August 12, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants