-
Notifications
You must be signed in to change notification settings - Fork 22
lib: bluetooth: ble_adv: change error codes to nrf_error #436
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
base: main
Are you sure you want to change the base?
lib: bluetooth: ble_adv: change error codes to nrf_error #436
Conversation
|
You can find the documentation preview for this PR here. |
c94cb69 to
6fc813d
Compare
6fc813d to
c2fa6b6
Compare
|
|
||
| if (err) { | ||
| LOG_ERR("Failed to initialize advertising, err %d", err); | ||
| if (nrf_err != NRF_SUCCESS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to be this explicit? I think it's easier to read if (nrf_err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should for good practice, as we don't have full control over the nrf_error values (although in practice it is very unlikely that NRF_SUCCESS will change). It also makes a clear distinction between errnos and nrf_errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely stick to the simpler:
if (nrf_err) {
}
|
|
||
| if (err) { | ||
| LOG_ERR("Failed to initialize advertising, err %d", err); | ||
| if (nrf_err != NRF_SUCCESS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can safely stick to the simpler:
if (nrf_err) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be part of it...
lib/bluetooth/ble_adv/ble_adv_data.c
Outdated
| /* Check parameter consistency */ | ||
| if (ble_adv_data->srv_list.service == NULL) { | ||
| return -EFAULT; | ||
| return NRF_ERROR_INVALID_PARAM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use NRF_ERROR_NULL
lib/bluetooth/ble_adv/ble_adv_data.c
Outdated
| if (service_data->len > 0) { | ||
| if (service_data->data == NULL) { | ||
| return -EINVAL; | ||
| return NRF_ERROR_INVALID_PARAM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use NRF_ERROR_NULL when a check against NULL fails
lib/bluetooth/ble_adv/ble_adv.c
Outdated
| { | ||
| #if CONFIG_BLE_ADV_FAST_ADVERTISING | ||
| int err; | ||
| uint32_t err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should decide whether we want to store nrf_error values into nrf_err or whether it can be called generically err where there is only one error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was thinking about that as well. For now I've only updated in the samples where it collides.
031b124 to
89653ba
Compare
| LOG_ERR("Failed to start advertising, err %d", err); | ||
| nrf_err = ble_adv_start(&ble_adv, BLE_ADV_MODE_FAST); | ||
| if (nrf_err) { | ||
| LOG_ERR("Failed to start advertising, nrf_error %#x", err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| LOG_ERR("Failed to start advertising, nrf_error %#x", err); | |
| LOG_ERR("Failed to start advertising, nrf_error %#x", nrf_err); |
| static int advertising_start(bool erase_bonds) | ||
| { | ||
| int err = 0; | ||
| uint32_t nrf_err = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| uint32_t nrf_err = 0; | |
| uint32_t nrf_err = NRF_SUCCESS; |
|
|
||
| __cmock_sd_ble_gap_adv_set_configure_IgnoreAndReturn(NRF_ERROR_INVALID_PARAM); | ||
| ret = ble_adv_start(&ble_adv, BLE_ADV_MODE_SLOW); | ||
| TEST_ASSERT_EQUAL(-EINVAL, ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of test still ends with _einval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected, thanks!
| * @retval NRF_SUCCESS On success. | ||
| * @retval NRF_ERROR_INVALID_STATE Library is not initialized. | ||
| * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. | ||
| * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe align the error description here and for the other functions.
| * @retval NRF_SUCCESS On success. | |
| * @retval NRF_ERROR_INVALID_STATE Library is not initialized. | |
| * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. | |
| * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. | |
| * @retval NRF_SUCCESS On success. | |
| * @retval NRF_ERROR_INVALID_STATE Library is not initialized. | |
| * @retval NRF_ERROR_NULL @p ble_adv is @c NULL. | |
| * @retval NRF_ERROR_INVALID_PARAM Invalid parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are mant places we don't do that, but use a single space. Let's discuss offline and agree on the format for the repo.
lib/bluetooth/ble_adv/ble_adv_data.c
Outdated
| nrf_err = sd_ble_gap_addr_get(&device_addr); | ||
| if (nrf_err) { | ||
| LOG_ERR("Failed to get device GAP address, nrf_error %#x", nrf_err); | ||
| return NRF_ERROR_INVALID_ADDR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only error returned by the sd_ble_gap_addr_get apart from NRF_SUCCESS. The nRF5 SDK seems to return the error directly from sd_ble_gap_addr_get here.
lib/bluetooth/ble_adv/ble_adv_data.c
Outdated
| nrf_err = sd_ble_gap_device_name_get(&data[*offset + AD_DATA_OFFSET], &actual_length); | ||
| if (nrf_err) { | ||
| LOG_ERR("Failed to get device GAP name, nrf_error %#x", nrf_err); | ||
| return NRF_ERROR_INVALID_PARAM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe return nrf_err here. The nRF5 SDK returns the error directly from sd_ble_gap_device_name_get.
lib/bluetooth/ble_adv/ble_adv_data.c
Outdated
| nrf_err = sd_ble_gap_appearance_get(&appearance); | ||
| if (nrf_err) { | ||
| LOG_ERR("Failed to get GAP appearance, nrf_error %#x", nrf_err); | ||
| return NRF_ERROR_INVALID_ADDR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nRF5 SDK seems to return directly from sd_ble_gap_appearance_get here.
89653ba to
ff36289
Compare
lib/bluetooth/ble_adv/ble_adv.c
Outdated
| err = ble_adv_start(ble_adv, BLE_ADV_MODE_DIRECTED_HIGH_DUTY); | ||
| if (err) { | ||
| nrf_err = ble_adv_start(ble_adv, BLE_ADV_MODE_DIRECTED_HIGH_DUTY); | ||
| if (nrf_err != NRF_SUCCESS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be checking explictly against NRF_SUCCESS, it creates lots of noise for nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this here, will update.
Change error codes to nrf_errors. Signed-off-by: Eivind Jølsgard <[email protected]>
ff36289 to
9c3c4e3
Compare
Change error codes to nrf_errors.
This is the first PR for updating the error codes for BLE libraries. Starting with the ble_adv library.
Moving forward all non-BLE libraries and components will return errnos, while BLE related code as BLE services, libraries and the SoftDevice will return nrf_errors.