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

Exploring Introduction to service structure

I am new to BLE and I am exploring Introduction to service. However I am stuck with Step 1 and Step 2. Is Step 1: static ble_os_t   m_our_service; (to declare a service) and step 2: our_service_init(ble_os_t*m_our_service); (the error says expected expression before ble_os_t). What is the way to define and initialise a service?

  • Hello,

    I am new to BLE and I am exploring Introduction to service.

    Welcome! 

    However I am stuck with Step 1 and Step 2. Is Step 1: static ble_os_t   m_our_service; (to declare a service) and step 2: our_service_init(ble_os_t*m_our_service); (the error says expected expression before ble_os_t).

    How familiar are you with C and embedded programming?
    In short, we need to declare that a new service exists - and then we need to fill in the empty service with the contents and functionality it will provide, by initializing it.
    A more in-depth explanation of the concepts declaration, definition and initialization can be read here.

    What is the way to define and initialise a service?

    Have you retrieved the tutorials example code from the github?

    Step 1 of the tutorial calls for declaration of a service structure.
    If you check out the our_service.h file, you will see the code exempt:

    /**
     * @brief This structure contains various status information for our service. 
     * It only holds one entry now, but will be populated with more items as we go.
     * The name is based on the naming convention used in Nordic's SDKs. 
     * 'ble’ indicates that it is a Bluetooth Low Energy relevant structure and 
     * ‘os’ is short for Our Service). 
     */
    typedef struct
    {
        uint16_t    service_handle;     /**< Handle of Our Service (as provided by the BLE stack). */
    }ble_os_t;


    Relevant examples of other, similar, declarations can be seen in main.c, for example:
    static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID;                        /**< Handle of the current connection. */


    2: our_service_init(ble_os_t*m_our_service); (the error says expected expression before ble_os_t).

    Here, you are supposed to pass the function the service structure you declared earlier.

    Looking into the our_service.h file again, we see the following exempt:

    /**@brief Function for initializing our new service.
     *
     * @param[in]   p_our_service       Pointer to Our Service structure.
     */
    void our_service_init(ble_os_t * p_our_service);


    Which means that the our_service_init function takes a pointer to a ble_os_t struct as its argument.
    You must therefore provide this when you call the function, and it is done by using the referencing operator &, i.e passing the argument &m_our_service.
    You should read more about referencing and pointers in this stackoverflow discussion, as it is crucial when working with C and embedded programming.

    Please let me know if anything should still be unclear!

    Best regards,
    Karl

  • Hi Karl, I tried the below code on SDK 16.0. I have referred to the replies from the Intro to services and followed some of the edits to the code to update it in SDK16.0. However I got the following error. What do they mean?

  • Hello again,

    Sorry for my late reply.

    The ' conflicting types for "" ' error is commonly caused by providing the wrong type of argument to a function or structure.
    You could read more about this error here and here.
    I highly recommend using Stackoverflow to troubleshoot and learn more about the intrinsic of C programming.

    Best regards,
    Karl

  • Hi Karl,

    For Step 1 I have changed to : 

    static uint16_t  m_our_service;

    and Step 2: void our_service_init(ble_os_t * m_our_service);

    And it is able to compile. However it does not advertise successfully. I tried to refer to the forum here about the changing the RAM_START/RAM_SIZE  for it to advertise it still does not work. What could I have done wrong?

Related