prova invio BLE
Dependents: BLE_HeartRate_IDB04A1
Fork of BLE_API by
Diff: source/DiscoveredCharacteristic.cpp
- Revision:
- 930:d6883d67fcb3
- Parent:
- 929:918d93d409c1
- Child:
- 931:97e69faa4a5c
--- a/source/DiscoveredCharacteristic.cpp Thu Nov 26 12:52:05 2015 +0000 +++ b/source/DiscoveredCharacteristic.cpp Thu Nov 26 12:52:05 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; }