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

LED Button Service Server GATT code Question:)

Hi!
I'm studying the basic codes of the BLE Blinky Application for peripheral! 
(https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fble_sdk_app_blinky.html)

Here I have some questions. Can someone help me find out

1. BLE_LBS_DEF(m_lbs); /**< LED Button Service instance. */  
2. NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */
what codes 1 and 2 do? Why do we use these codes? 
And what does "instance" exactly mean here?

Thanks:) 

Parents
  • They are #defined macros.

    Use your IDE's code browsing facilities to find the definitions of those macros.

    What they do is to create the variable given within the parentheses:

    • BLE_LBS_DEF(m_lbs) creates a variable called 'm_lbs' - this is the data structure used to control the LED Button Service
    • NRF_BLE_GATT_DEF(m_gatt) creates a variable called 'm_gatt' - this is the data structure used to control the GATT module

    You will find that Nordic is this approach a lot throughout the SDK.

    what does "instance" exactly mean here

    https://en.wiktionary.org/wiki/instantiation

  • For example, we find the definition of NRF_BLE_GATT_DEF() in nrf_ble_gatt.h:

    /**@brief   Macro for defining a nrf_ble_gatt instance.
     *
     * @param   _name   Name of the instance.
     * @hideinitializer
     */
    #define NRF_BLE_GATT_DEF(_name)                        \
    static nrf_ble_gatt_t _name;                           \
    NRF_SDH_BLE_OBSERVER(_name ## _obs,                    \
                         NRF_BLE_GATT_BLE_OBSERVER_PRIO,   \
                         nrf_ble_gatt_on_ble_evt, &_name)
    

    Note that the created variable is static - Nordic use the m_ prefix to identify file-scope statics

Reply
  • For example, we find the definition of NRF_BLE_GATT_DEF() in nrf_ble_gatt.h:

    /**@brief   Macro for defining a nrf_ble_gatt instance.
     *
     * @param   _name   Name of the instance.
     * @hideinitializer
     */
    #define NRF_BLE_GATT_DEF(_name)                        \
    static nrf_ble_gatt_t _name;                           \
    NRF_SDH_BLE_OBSERVER(_name ## _obs,                    \
                         NRF_BLE_GATT_BLE_OBSERVER_PRIO,   \
                         nrf_ble_gatt_on_ble_evt, &_name)
    

    Note that the created variable is static - Nordic use the m_ prefix to identify file-scope statics

Children
Related