This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Would it make sense to add an NRF_ERROR_INVALID_ROLE to nrf_error.h?

Hello Nordic and fellow developers

While implementing bonding into an application based on S130 I found it necessary to test on the role of a given connection. Different parameters have to be filled out based on the role before calling functions like sd_ble_gap_sec_params_reply(), but what if something went wrong earlier on and the role is set to BLE_GAP_ROLE_INVALID? Which error code would be most appropriate? So far I am using NRF_ERROR_INVALID_STATE, but I am now pondering if a new error code like NRF_ERROR_INVALID_ROLE would be nice to have since this clearly isn't the only place we will be facing invalid roles in the future.

  • Hi Rasmus,

    If you check out the S130 example experimental_ble_app_example_c_s130 from SDK 8.1 you can see how it handles being multirole, central and peripheral.

    (located in ..\examples\ble_central_and_peripheral\experimental\app_s130_demo\pca10028\s130\arm5_no_packs)

    The idea is that since you "know" in your application if you want to be central or peripheral at a given time, you should not get BLE_GAP_ROLE_INVALID. Since many of these errors occur while you are in SoftDevice, which cannot be stepped by the debugger you will often have to use printf statements to do most of your debugging.

    However, if you do want to use one of the NRF_ERROR codes I think either NRF_ERROR_INVALID_PARAM(If your handler has been initialized wrongly) or NRF_ERROR_INVALID_STATE would work well.

    Best regards,

    Øyvind

Related