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

samples: bluetooth: Fix bt_le_scan_stop() error checking in central_multilink sample #84369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ramana-g-123
Copy link

@ramana-g-123 ramana-g-123 commented Jan 22, 2025

Fixes #84187
The logic in central_multilink example outputs "Scanning successfully stopped" when the stop call has failed as the bt_le_scan_stop() call returns 0 when successful and error when unsuccessful

@zephyrbot zephyrbot added size: XS A PR changing only a single line of code area: Samples Samples area: Bluetooth area: Bluetooth Host Bluetooth Host (excluding BR/EDR) labels Jan 22, 2025
Copy link

Hello @ramana-g-123, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@jhedberg
Copy link
Member

@ramana-g-123 thanks for the pull request! The change itself looks great, however please fix the commit message to be compliant with Zephyr requirements:

  • Add a prefix to the subject. This can be e.g. "samples: bluetooth: ..."
  • Remove the issue reference from the subject and instead have a short version of what the actual change is there, e.g. "samples: bluetooth: Fix bt_le_scan_stop() error checking"
  • Add a Signed-off-by line. git will do this automatically for you when you pass -s to git commit.
  • Add the issue reference to the PR description. GitHub recognizes this in the format "Fixes #...." and will link the two automatically together then.

rugeGerritsen
rugeGerritsen previously approved these changes Jan 22, 2025
@@ -75,7 +75,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
return;
}

if (bt_le_scan_stop()) {
if (bt_le_scan_stop() == 0) {
printk("Scanning successfully stopped\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm isn't the check correct but printed error message is wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If bt_le_scan_stop returns 0 it means that it was stopped :) Looks right to me

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the more general flow of the function, I believe the purpose is to proceed to the bt_conn_le_create() step when scanning was stopped, so we shouldn't return from the function in a success case. So it does seem like @sjanc is right, i.e. the log message is wrong. Since the function has an err variable, I'd also take advantage of it in the same go:

err = bt_le_scan_stop();
if (err != 0) {
	printk("Failed to stop scanning (err %d)\n", err);
	return;
}

@ramana-g-123 can you update the PR accordingly? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @sjanc and @jhedberg, on failure to stop scanning the control should not proceed further to setup a connection. Hence, it is the message that is incorrect.

@ramana-g-123 Thank you for noticing the issue.

@@ -75,7 +75,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
return;
}

if (bt_le_scan_stop()) {
if (bt_le_scan_stop() == 0) {
printk("Scanning successfully stopped\n");
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the more general flow of the function, I believe the purpose is to proceed to the bt_conn_le_create() step when scanning was stopped, so we shouldn't return from the function in a success case. So it does seem like @sjanc is right, i.e. the log message is wrong. Since the function has an err variable, I'd also take advantage of it in the same go:

err = bt_le_scan_stop();
if (err != 0) {
	printk("Failed to stop scanning (err %d)\n", err);
	return;
}

@ramana-g-123 can you update the PR accordingly? Thanks.

@@ -75,7 +75,7 @@ static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
return;
}

if (bt_le_scan_stop()) {
if (bt_le_scan_stop() == 0) {
printk("Scanning successfully stopped\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @sjanc and @jhedberg, on failure to stop scanning the control should not proceed further to setup a connection. Hence, it is the message that is incorrect.

@ramana-g-123 Thank you for noticing the issue.

@ramana-g-123 ramana-g-123 changed the title Update central_multilink.c to fix #84187 samples: bluetooth: Fix bt_le_scan_stop() error checking in central_multilink sample Jan 23, 2025
@cvinayak
Copy link
Contributor

@ramana-g-123 thanks for the pull request! The change itself looks great, however please fix the commit message to be compliant with Zephyr requirements:

* Add a prefix to the subject. This can be e.g. "samples: bluetooth: ..."

* Remove the issue reference from the subject and instead have a short version of what the actual change is there, e.g. "samples: bluetooth: Fix bt_le_scan_stop() error checking"

* Add a Signed-off-by line. git will do this automatically for you when you pass `-s` to `git commit`.

* Add the issue reference to the PR description. GitHub recognizes this in the format "Fixes #...." and will link the two automatically together then.

Code looks good now... @ramana-g-123 please follow above suggestion to have single commit in this PR.

@jhedberg
Copy link
Member

@ramana-g-123 you still need a commit message body. You can find more info here: https://docs.zephyrproject.org/latest/contribute/guidelines.html#commit-message-guidelines

@jhedberg
Copy link
Member

@ramana-g-123 and also note this failure: UC5 Commit title exceeds max length (84>75). FWIW, you can run the compliance script yourself prior to pushing, if you want to save some time: scripts/ci/check_compliance.py

alwa-nordic
alwa-nordic previously approved these changes Jan 23, 2025
Thalley
Thalley previously approved these changes Jan 27, 2025
@jhedberg
Copy link
Member

@ramana-g-123 the commit message still isn't compliant, causing the Compliance check to fail: "Commit message body line exceeds max length (160>75)". Once that's fixed I think we can merge it.

@jhedberg
Copy link
Member

@ramana-g-123 you don't need to close/re-open pull requests like this. Just a force-push is enough.

Outputs error code to console if bt_le_scan_stop() fails

Signed-off-by: Ramana Gudipudi <[email protected]>
@ramana-g-123
Copy link
Author

Hey @jhedberg , sorry for the previous commit I was unable to run compliance_checks.py with the following issue even after installing all the packages needed using requirements.txt

  File "C:\Zephyr_RTOS\zephyr\scripts\ci\check_compliance.py", line 29, in <module>
    import magic
  File "C:\Zephyr_RTOS\zephyr\myenv\Lib\site-packages\magic\__init__.py", line 209, in <module>
    libmagic = loader.load_lib()
  File "C:\Zephyr_RTOS\zephyr\myenv\Lib\site-packages\magic\loader.py", line 49, in load_lib
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation

@Thalley
Copy link
Collaborator

Thalley commented Jan 27, 2025

Hey @jhedberg , sorry for the previous commit I was unable to run compliance_checks.py with the following issue even after installing all the packages needed using requirements.txt

  File "C:\Zephyr_RTOS\zephyr\scripts\ci\check_compliance.py", line 29, in <module>
    import magic
  File "C:\Zephyr_RTOS\zephyr\myenv\Lib\site-packages\magic\__init__.py", line 209, in <module>
    libmagic = loader.load_lib()
  File "C:\Zephyr_RTOS\zephyr\myenv\Lib\site-packages\magic\loader.py", line 49, in load_lib
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation

@ramana-g-123 did you install the requirements-compliance.txt as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth area: Samples Samples size: XS A PR changing only a single line of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect output printed in bt_le_scan_stop() evaluation in central_multilink sample
8 participants