Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Define a BLE service instance on the header file

Hi, 

I'm currently development firmware for a application using a Nordic chip. This application will use some drivers allowing the communication with sensors and for the transmission of the sensor data I will use the BLE. So this application is expected to use 4 BLE services, but right now I only have implemented 3 (BAS, NUS and LLS). For the Battery and Nordic UART Service, I have define the each instance on a header file and everything work as expected. When I implement the Link Loss Service, I have done the same thing (define service macro on the header file) but, for some reason, I can't connect to the BLE. When I define the Link Loss Service instance on the .c file, the BLE work perfectly with the 3 Services. 

There is something special with the Link Loss Service that restrict the instance definition to the .c file?

Thanks in advance!

Parents Reply
  • Hi! Sorry for the late answer. Regarding your question, after doing some tests I believe that you are correct. The .h file are been called in different .c files. 

    But I have some questions, the others instances are also defined there, why for them there is no problem? And also, can I do something to define the LLS instance one time only (on the .h file)? 

    Thanks

Children
  • Hi, no worries.

    jpedroliveira said:
    But I have some questions, the others instances are also defined there, why for them there is no problem?

    It is problematic to have multiple instances of the service structs even you don't notice any problems right away. The reason the others don't cause a crash in their respective on_connect() implementations is that they happen to include additional checks that will prevent the program from calling the zero-initialized function pointer.

    e.g. here is the on_connect() implementation in ble_nus.c:

    jpedroliveira said:
    And also, can I do something to define the LLS instance one time only (on the .h file)? 

    Then you have to declared the variable as "extern" in your header file.

  • Hi! 

    So I think we can close this ticket! Thank you so much for your help

Related