High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Thu Nov 26 12:52:34 2015 +0000
Parent:
961:259acb1c9d04
Child:
963:d111d9454aa9
Commit message:
Synchronized with git rev ebb982f7
Author: Vincent Coubard
Add read end to end operation

Changed in this revision

ble/DiscoveredCharacteristic.h Show annotated file Show diff for this revision Revisions of this file
source/DiscoveredCharacteristic.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ble/DiscoveredCharacteristic.h	Thu Nov 26 12:52:34 2015 +0000
+++ b/ble/DiscoveredCharacteristic.h	Thu Nov 26 12:52:34 2015 +0000
@@ -83,6 +83,8 @@
      */
     ble_error_t read(uint16_t offset = 0) const;
 
+    ble_error_t read(uint16_t offset, const GattClient::ReadCallback_t& onRead) const;
+
     /**
      * Perform a write without response procedure.
      *
--- a/source/DiscoveredCharacteristic.cpp	Thu Nov 26 12:52:34 2015 +0000
+++ b/source/DiscoveredCharacteristic.cpp	Thu Nov 26 12:52:34 2015 +0000
@@ -31,6 +31,47 @@
     return gattc->read(connHandle, valueHandle, offset);
 }
 
+
+struct OneShotReadCallback { 
+    static void launch(GattClient* client, const GattClient::ReadCallback_t& cb) { 
+        OneShotReadCallback* oneShot = new OneShotReadCallback(client, cb);
+        oneShot->attach();
+        // delete will be made when this callback is called
+    }
+
+private:
+    OneShotReadCallback(GattClient* client, const GattClient::ReadCallback_t& cb) : 
+        _client(client),
+        _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;
+    }
+
+    GattClient* _client;
+    GattClient::ReadCallback_t _callback;
+};
+
+ble_error_t DiscoveredCharacteristic::read(uint16_t offset, const GattClient::ReadCallback_t& onRead) const {
+    ble_error_t error = read(offset);
+    if(error) { 
+        return error;
+    }
+
+    OneShotReadCallback::launch(gattc, onRead);
+
+    return error;
+}
+
+
+
+
 ble_error_t
 DiscoveredCharacteristic::write(uint16_t length, const uint8_t *value) const
 {