we now have a working GattClient::write()

This commit is contained in:
Rohit Grover 2015-06-05 13:30:01 +01:00
parent 5f0668ee2c
commit 03c8740344
3 changed files with 26 additions and 13 deletions

View file

@ -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
@ -33,6 +34,20 @@ DiscoveredCharacteristic::read(uint16_t offset) const
return gattc->read(connHandle, valueHandle, offset);
}
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
{
@ -44,5 +59,5 @@ DiscoveredCharacteristic::writeWoResponse(uint16_t length, const uint8_t *value)
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);
}

View file

@ -94,11 +94,8 @@ public:
* @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 @@ public:
onDataReadCallback = callback;
}
static void setupOnDataWrite(GattClient::WriteCallback_t callback) {
onDataWriteCallback = callback;
}
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
uuid.setupLong(longUUID);
}
@ -153,7 +154,8 @@ protected:
Gap::Handle_t connHandle;
public:
static GattClient::ReadCallback_t onDataReadCallback;
static GattClient::ReadCallback_t onDataReadCallback;
static GattClient::WriteCallback_t onDataWriteCallback;
};
#endif /*__DISCOVERED_CHARACTERISTIC_H__*/

View file

@ -28,12 +28,8 @@ public:
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 @@ public:
/* 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: