BLE_GAP_ROLE_CENTRAL defined or value

In SDK 17.0.2, most places it looks like BLE_GAP_ROLE_CENTRAL is allowed to be undefined, except in nrf_ble_gatt.c line 142. Was there supposed to be "#ifdef BLE_GAP_ROLE_CENTRAL" to omit case BLE_GAP_ROLE_CENTRAL?

  • Hi,

    This is OK as this code is only included for SoftDevices that support the central feature:

    #if !defined (S112) && !defined(S312) && !defined(S113)
            case BLE_GAP_ROLE_CENTRAL:
                p_link->att_mtu_desired = p_gatt->att_mtu_desired_central;
                break;
    #endif // !defined (S112) && !defined(S312) && !defined(S113)

    though I agree that it would have been more elegant to just check if BLE_GAP_ROLE_CENTRAL was defined instead of checking for all the SoftDevices that does not support it (and for which it is not defined).

  • In file ble_conn_state.c line 242, it looks like the idea was to exclude code if the device was to be a peripheral only. It doesn't make much difference as it doesn't save much code space, just a technicality. Am I safe to wrap the above with #ifdef BLE_GAP_ROLE_CENTRAL same as ble_conn_state.c line 242?

  • don0u812 said:
    In file ble_conn_state.c line 242, it looks like the idea was to exclude code if the device was to be a peripheral only.

    Yes, sort of. But BLE_GAP_ROLE_CENTRAL is not a configuration macro. It is defined in the ble_gap.h file for SoftDevices that support the central role, and not those that do not. so this code will be present as long as the peripheral role is supported, regardless of it being used.

    don0u812 said:
    Am I safe to wrap the above with #ifdef BLE_GAP_ROLE_CENTRAL same as ble_conn_state.c line 242?

    I cannot see any problems with that - it would be more elegant. But the end result after the preprocessor would be exactly the same.

Related