ble
ble copied to clipboard
Initial version of the setCCCD API for GattClient
This is an initial version of an API that automates the process of setting the Client Characteristic Configuration Descriptor (CCCD) to enable/disable notifications. The new API is DiscoveredCharacteristic::setCCCD().
The new API internally triggers a characteristic descriptor discovery procedure to find the handle of the CCCD. If this succeeds, it attempts to execute a write procedure. On termination, a user configured callback is executed to report the final outcome of the process.
NOTE: This pull request is NOT READY FOR MERGE, it is an early version of the new API to start discussion around this issue. In my opinion, there are still a few problems that need to be tackled:
- Shutdown should gracefully terminate the setCCCD procedure.
- CCCDSetter::launch (and OneShotWriteCallback::launch, OneShotReadCallback::launch as well) do not return ble_error_t, so its impossible to check whether they actually succeeded.
@pan- Please comment.
The build will fail because there is a problem in the API when registering onShutdown callbacks. The signature of the function should be void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *))
rather than void onShutdown(T *objPtr, void (T::*memberPtr)(void))
I have made a PR to solve this issue: https://github.com/ARMmbed/ble/pull/174
It seems that the ble-nrf51822 implementation of the API does shutdown the Service Discovery but NOT the Characteristic Descriptor Discoverer. I have raised an issue about this, see https://github.com/ARMmbed/ble-nrf51822/issues/110. In this case, the CCCDSetter objects will never receive the expected callbacks and the memory resources allocated will never be cleared.