Enable and Disable BLE Service and/or associated Characteristic(s) | Cypress Semiconductor
Enable and Disable BLE Service and/or associated Characteristic(s)
The information below is for those who would like to enable and disable a BLE Service and/or an associated Characteristic (value), and possible Characteristic Configuration (e.g. for Notify), using the Cypress BLE API functions CyBle_GattsEnableAttribute() and CyBle_GattsDisableAttribute():
The defined constants below are as generated by Cypress in BLE_custom.h for a Custom Service having a Custom Characteristic (value) and a Custom Characteristic Configuration, with no Custom Descriptor:
#define CYBLE_CUSTOM_SERVICE_SERVICE_HANDLE (0x000Cu) /* Handle of Custom Service service */
#define CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE (0x000Eu) /* Handle of Custom Characteristic characteristic */
#define CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CUSTOM_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE (0x000Fu) /* Handle of Custom Characteristic Configuration descriptor */
A Service is enabled/disabled by utilizing the Service Handle (e.g. CYBLE_CUSTOM_SERVICE_SERVICE_HANDLE) with the functions CyBle_GattsEnableAttribute() and CyBle_GattsDisableAttribute().
However, to enable/disable only a Characteristic (of a Service), the required "Characteristic Declaration Handle" is produced by subtracting 1 from the "Characteristic Value Handle" (e.g. CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE) and any Characteristic Configuration (e.g. handle of CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CUSTOM_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE) associated with that Characteristic Value will also be enabled/disabled when calling CyBle_GattsEnableAttribute() and CyBle_GattsDisableAttribute() with the "Characteristic Declaration Handle".
Therefore, for the defined constants generated by Cypress above, the entire Service (and Characteristics) is enabled/disabled by calling CyBle_GattsEnableAttribute()/CyBle_GattsDisableAttribute() with the handle CYBLE_CUSTOM_SERVICE_SERVICE_HANDLE.
The Service Characteristic (value) and associated Characteristic Configuration is enabled/disabled by calling CyBle_GattsEnableAttribute()/CyBle_GattsDisableAttribute() with a handle value of CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE - 1 (e.g. 0x000Eu - 1 = 0x000Du) which is not defined anywhere by Cypress.