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

Building at State Machine that monitors ble evt

I am trying to only perform calculations for connected ble services.

I am implementing a state machine that monitors the ble evt. I use this for example when to perform calculations required for ble gatt services.

As result I need to know which ble gatt advertised service is connected to so that I only perform the calculations required. The function on_ble_evt refers events for all advertised ble services.

With the ble_nus.c "nordic ble uart" I am able to enable, disable calculations and monitoring by setting a State variable in the on_connect and on_disconnect functions.

How are these functions called? And regarding nrf51 SDK structuring,where are functions for other ble gatt services, such as csc?

What I am really looking for is a connection flow diagram outlining the progression of ble connection events for a device advertising multiple ble services.

  • If the services are using notifications and/or indications to send the calculated data, you can use the value of the Client Characteristic Configuration Descriptor (CCCD) to decide if your calculations are needed or not.

    In the SDK example services, this is usually handled in the ble_*on_ble_evt() for events of the type BLE_GATTS_EVT_WRITE, usually leading to a local on_write() function that again will multiplex the write to a on*_cccd_write() function if appliccable. For the ble_cscs example, the service will send an BLE_CSCS_EVT_NOTIFICATION_ENABLED signal if the main context has specified an event handler for the service. You can then either use this signal in your main context to enable calculations, or it can be done in the service itself if that's a better fit for you.

Related