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

Interaction with multiple copies of the same services

Hello, I work with nrf51822. I need to use ble to control several LEDs. The control logic for each of them is the same. I am creating my own service to control a single LED. I initiate its service the required number of times. But I don't understand how in my application to distinguish which copy the command came from? Can you tell me something about this? Or to give an example ?

Parents
  • Hi,

    The services implemented in the SDK typically use a data structure containing all the status information for a given characteristic, including what handle it is on. See for instance the Heart Rate Application, where the data for the heart rate service is stored using the variable m_hrs, which is sent in for everything from initializing the service to handling events.

    In order to have mulitiple instances of the service, one must use one instance of this structure for each instance of the service, for instance in an array. In the code for the service itself, the structure is read on connect events, write events, disconnect events, hrx events, etc. in order to check if the handle from the event equals the handle for this instance (as read from the structure). For an example, see how a pointer, (named p_hrs,) to a structure ble_hrs_t, defined in ble_hrs.h, is used throughout ble_hrs.c.

    The main takeaway is to store status info (including handles) in a structure, and pass a pointer to that structure in to any function handling the service. For multiple instances of the service, use multiple instances of that structure, and initialize one new service for each of those structure instances.

    Regards,
    Terje

Reply
  • Hi,

    The services implemented in the SDK typically use a data structure containing all the status information for a given characteristic, including what handle it is on. See for instance the Heart Rate Application, where the data for the heart rate service is stored using the variable m_hrs, which is sent in for everything from initializing the service to handling events.

    In order to have mulitiple instances of the service, one must use one instance of this structure for each instance of the service, for instance in an array. In the code for the service itself, the structure is read on connect events, write events, disconnect events, hrx events, etc. in order to check if the handle from the event equals the handle for this instance (as read from the structure). For an example, see how a pointer, (named p_hrs,) to a structure ble_hrs_t, defined in ble_hrs.h, is used throughout ble_hrs.c.

    The main takeaway is to store status info (including handles) in a structure, and pass a pointer to that structure in to any function handling the service. For multiple instances of the service, use multiple instances of that structure, and initialize one new service for each of those structure instances.

    Regards,
    Terje

Children
No Data
Related