High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Revision 512:0584e40bece2, committed 2015-06-19
- Comitter:
- rgrover1
- Date:
- Fri Jun 19 15:52:05 2015 +0100
- Parent:
- 511:9f5046c0f741
- Child:
- 513:0e6ad6ac1d9b
- Commit message:
- Synchronized with git rev 03c87403
Author: Rohit Grover
we now have a working GattClient::write()
Changed in this revision
--- a/common/DiscoveredCharacteristic.cpp Fri Jun 19 15:52:04 2015 +0100 +++ b/common/DiscoveredCharacteristic.cpp Fri Jun 19 15:52:05 2015 +0100 @@ -17,7 +17,8 @@ #include "DiscoveredCharacteristic.h" #include "GattClient.h" -GattClient::ReadCallback_t DiscoveredCharacteristic::onDataReadCallback; +GattClient::ReadCallback_t DiscoveredCharacteristic::onDataReadCallback; +GattClient::WriteCallback_t DiscoveredCharacteristic::onDataWriteCallback; ble_error_t DiscoveredCharacteristic::read(uint16_t offset) const @@ -34,6 +35,20 @@ } ble_error_t +DiscoveredCharacteristic::write(uint16_t length, const uint8_t *value) const +{ + if (!props.write()) { + return BLE_ERROR_OPERATION_NOT_PERMITTED; + } + + if (!gattc) { + return BLE_ERROR_INVALID_STATE; + } + + return gattc->write(GattClient::GATT_OP_WRITE_REQ, connHandle, valueHandle, length, value); +} + +ble_error_t DiscoveredCharacteristic::writeWoResponse(uint16_t length, const uint8_t *value) const { if (!props.writeWoResp()) { @@ -44,5 +59,5 @@ return BLE_ERROR_INVALID_STATE; } - return gattc->write(GattClient::GATT_OP_WRITE_CMD, connHandle, length, value); + return gattc->write(GattClient::GATT_OP_WRITE_CMD, connHandle, valueHandle, length, value); } \ No newline at end of file
--- a/public/DiscoveredCharacteristic.h Fri Jun 19 15:52:04 2015 +0100 +++ b/public/DiscoveredCharacteristic.h Fri Jun 19 15:52:05 2015 +0100 @@ -94,11 +94,8 @@ * @param value * The bytes being written. * - * @note It is important to note that a write without response will generate - * an onDataSent() callback when the packet has been transmitted. There - * will be a BLE-stack specific limit to the number of pending - * writeWoResponse operations; the user may want to use the onDataSent() - * callback for flow-control. + * @note It is important to note that a write will generate + * an onDataWritten() callback when the peer acknowledges the request. * * @retval BLE_ERROR_NONE Successfully started the Write procedure, else * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or @@ -112,6 +109,10 @@ onDataReadCallback = callback; } + static void setupOnDataWrite(GattClient::WriteCallback_t callback) { + onDataWriteCallback = callback; + } + void setupLongUUID(UUID::LongUUIDBytes_t longUUID) { uuid.setupLong(longUUID); } @@ -153,7 +154,8 @@ Gap::Handle_t connHandle; public: - static GattClient::ReadCallback_t onDataReadCallback; + static GattClient::ReadCallback_t onDataReadCallback; + static GattClient::WriteCallback_t onDataWriteCallback; }; #endif /*__DISCOVERED_CHARACTERISTIC_H__*/ \ No newline at end of file
--- a/public/GattClient.h Fri Jun 19 15:52:04 2015 +0100 +++ b/public/GattClient.h Fri Jun 19 15:52:05 2015 +0100 @@ -28,12 +28,8 @@ typedef void (*ReadCallback_t)(const GattReadCallbackParams *params); enum WriteOp_t { - GATT_OP_INVALID = 0x00, /**< Invalid Operation. */ GATT_OP_WRITE_REQ = 0x01, /**< Write Request. */ GATT_OP_WRITE_CMD = 0x02, /**< Write Command. */ - GATT_OP_SIGN_WRITE_CMD = 0x03, /**< Signed Write Command. */ - GATT_OP_PREP_WRITE_REQ = 0x04, /**< Prepare Write Request. */ - GATT_OP_EXEC_WRITE_REQ = 0x05, /**< Execute Write Request. */ }; typedef void (*WriteCallback_t)(const GattWriteCallbackParams *params); @@ -88,7 +84,7 @@ /* Initiate a Gatt Client read procedure by attribute-handle.*/ virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const = 0; - virtual ble_error_t write(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, size_t length, const uint8_t *value) const = 0; + virtual ble_error_t write(GattClient::WriteOp_t cmd, Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, size_t length, const uint8_t *value) const = 0; #if 0 public: