Skip to content

Commit

Permalink
Added support for requesting HVX.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Cady committed Mar 25, 2016
1 parent 3de2ea8 commit 5027421
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ble/DiscoveredCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ class DiscoveredCharacteristic {
*/
ble_error_t write(uint16_t length, const uint8_t *value, const GattClient::WriteCallback_t& onWrite) const;

/**
* Request Server to send notify/inform messages for the characteristic
*
* @param type
* BLE_HVX_NOTIFICATION or BLE_HVX_INDICATION.
*
* @retval BLE_ERROR_NONE Successfully requested notification/informa messages
* BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or
* BLE_STACK_BUSY if some client procedure already in progress, or
* BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or
* BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties.
*/
ble_error_t requestHVX(HVXType_t type) const;

void setupLongUUID(UUID::LongUUIDBytes_t longUUID, UUID::ByteOrder_t order = UUID::MSB) {
uuid.setupLong(longUUID, order);
}
Expand Down
22 changes: 22 additions & 0 deletions source/DiscoveredCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ DiscoveredCharacteristic::writeWoResponse(uint16_t length, const uint8_t *value)
return gattc->write(GattClient::GATT_OP_WRITE_CMD, connHandle, valueHandle, length, value);
}

ble_error_t
DiscoveredCharacteristic::requestHVX(HVXType_t type) const
{
if (type == BLE_HVX_NOTIFICATION && !props.notify()) {
return BLE_ERROR_OPERATION_NOT_PERMITTED;
}

if (type == BLE_HVX_INDICATION && !props.indicate()) {
return BLE_ERROR_OPERATION_NOT_PERMITTED;
}

if (!gattc) {
return BLE_ERROR_INVALID_STATE;
}

/* Cargo Culted from: https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_ButtonSense/file/2dec89c76f68/main.cpp */
/* HACK. We're assuming that CCCD descriptor immediately follows the value attribute. */
/* TODO actually discover the handle for the CCCD descriptor */
uint16_t value = (uint16_t)type;
return gattc->write(GattClient::GATT_OP_WRITE_REQ, connHandle, valueHandle + 1, sizeof(value), (const uint8_t*)(&value));
}

struct OneShotWriteCallback {
static void launch(GattClient* client, Gap::Handle_t connHandle,
GattAttribute::Handle_t handle, const GattClient::WriteCallback_t& cb) {
Expand Down

0 comments on commit 5027421

Please sign in to comment.