BLE_API for nRF51
Fork of BLE_API by
Revision 720:ce8a760a4504, committed 2015-07-02
- Comitter:
- rgrover1
- Date:
- Thu Jul 02 09:06:12 2015 +0100
- Parent:
- 719:5f5c3812ea8f
- Child:
- 721:8f92a1a943d6
- Commit message:
- Synchronized with git rev 2d594048
Author: Rohit Grover
#49: replace DiscoveredCharacteristic::setupOnDataRead() with GattClient::onDataRead()
Changed in this revision
--- a/ble/DiscoveredCharacteristic.h Thu Jul 02 09:06:12 2015 +0100 +++ b/ble/DiscoveredCharacteristic.h Thu Jul 02 09:06:12 2015 +0100 @@ -135,14 +135,6 @@ */ ble_error_t write(uint16_t length, const uint8_t *value) const; - static void setupOnDataRead(GattClient::ReadCallback_t callback) { - onDataReadCallback = callback; - } - - static void setupOnDataWrite(GattClient::WriteCallback_t callback) { - onDataWriteCallback = callback; - } - void setupLongUUID(UUID::LongUUIDBytes_t longUUID) { uuid.setupLong(longUUID); } @@ -182,10 +174,6 @@ GattAttribute::Handle_t valueHandle; Gap::Handle_t connHandle; - -public: - static GattClient::ReadCallback_t onDataReadCallback; - static GattClient::WriteCallback_t onDataWriteCallback; }; #endif /*__DISCOVERED_CHARACTERISTIC_H__*/ \ No newline at end of file
--- a/ble/GattClient.h Thu Jul 02 09:06:12 2015 +0100 +++ b/ble/GattClient.h Thu Jul 02 09:06:12 2015 +0100 @@ -207,6 +207,23 @@ return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */ } + /* Event callback handlers. */ +public: + /** + * Setup a callback for read response events. + */ + void onDataRead(ReadCallback_t callback) { + onDataReadCallback = callback; + } + + /** + * Setup a callback for write response events. + * @Note: write commands (issued using writeWoResponse) don't generate a response. + */ + void onDataWrite(WriteCallback_t callback) { + onDataWriteCallback = callback; + } + /** * Setup callback for when serviceDiscovery terminates. */ @@ -219,6 +236,24 @@ /* empty */ } + /* Entry points for the underlying stack to report events back to the user. */ +public: + void processReadResponse(const GattReadCallbackParams *params) { + if (onDataReadCallback) { + onDataReadCallback(params); + } + } + + void processWriteResponse(const GattWriteCallbackParams *params) { + if (onDataWriteCallback) { + onDataWriteCallback(params); + } + } + +protected: + ReadCallback_t onDataReadCallback; + WriteCallback_t onDataWriteCallback; + private: /* disallow copy and assignment */ GattClient(const GattClient &);
--- a/source/DiscoveredCharacteristic.cpp Thu Jul 02 09:06:12 2015 +0100 +++ b/source/DiscoveredCharacteristic.cpp Thu Jul 02 09:06:12 2015 +0100 @@ -17,9 +17,6 @@ #include "ble/DiscoveredCharacteristic.h" #include "ble/GattClient.h" -GattClient::ReadCallback_t DiscoveredCharacteristic::onDataReadCallback; -GattClient::WriteCallback_t DiscoveredCharacteristic::onDataWriteCallback; - ble_error_t DiscoveredCharacteristic::read(uint16_t offset) const {