Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Diff: source/DiscoveredCharacteristic.cpp
- Revision:
- 963:d111d9454aa9
- Parent:
- 962:622ae38b3023
- Child:
- 964:9d12fedb6d69
--- a/source/DiscoveredCharacteristic.cpp Thu Nov 26 12:52:34 2015 +0000 +++ b/source/DiscoveredCharacteristic.cpp Thu Nov 26 12:52:34 2015 +0000 @@ -33,28 +33,37 @@ struct OneShotReadCallback { - static void launch(GattClient* client, const GattClient::ReadCallback_t& cb) { - OneShotReadCallback* oneShot = new OneShotReadCallback(client, cb); + static void launch(GattClient* client, Gap::Handle_t connHandle, + GattAttribute::Handle_t handle,const GattClient::ReadCallback_t& cb) { + OneShotReadCallback* oneShot = new OneShotReadCallback(client, connHandle, handle, cb); oneShot->attach(); // delete will be made when this callback is called } private: - OneShotReadCallback(GattClient* client, const GattClient::ReadCallback_t& cb) : + OneShotReadCallback(GattClient* client, Gap::Handle_t connHandle, + GattAttribute::Handle_t handle, const GattClient::ReadCallback_t& cb) : _client(client), + _connHandle(connHandle), + _handle(handle), _callback(cb) { } void attach() { _client->onDataRead(makeFunctionPointer(this, &OneShotReadCallback::call)); } - void call(const GattReadCallbackParams* params) { - _callback(params); - _client->onDataRead().detach(makeFunctionPointer(this, &OneShotReadCallback::call)); - delete this; + void call(const GattReadCallbackParams* params) { + // verifiy that it is the right characteristic on the right connection + if(params->connHandle == _connHandle && params->handle == _handle) { + _callback(params); + _client->onDataRead().detach(makeFunctionPointer(this, &OneShotReadCallback::call)); + delete this; + } } GattClient* _client; + Gap::Handle_t _connHandle; + GattAttribute::Handle_t _handle; GattClient::ReadCallback_t _callback; }; @@ -64,7 +73,7 @@ return error; } - OneShotReadCallback::launch(gattc, onRead); + OneShotReadCallback::launch(gattc, connHandle, valueHandle, onRead); return error; }