microbit: Added support for explicit characteristic notification
Required to allow the mbed layer to avoid caching large amounts of state in its GattCharacteristics n.b. this should be removed once all optimisations to the mbed layer are completed.
This commit is contained in:
parent
a5bb9906b3
commit
031aeec3af
2 changed files with 33 additions and 0 deletions
|
@ -277,6 +277,38 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute
|
|||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an explicit BLE notification of a given attribute.
|
||||
*
|
||||
* @param[in] attributeHandle
|
||||
* Handle for the value attribute of the Characteristic.
|
||||
* @param[in] value
|
||||
* A pointer to a buffer holding the new value
|
||||
* @param[in] size
|
||||
* Size of the new value (in bytes).
|
||||
*
|
||||
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
|
||||
*/
|
||||
ble_error_t nRF5xGattServer::notify(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len)
|
||||
{
|
||||
uint16_t gapConnectionHandle = nRF5xGap::getInstance().getConnectionHandle();
|
||||
ble_gatts_hvx_params_t hvx_params;
|
||||
|
||||
hvx_params.handle = attributeHandle;
|
||||
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
|
||||
hvx_params.offset = 0;
|
||||
hvx_params.p_data = const_cast<uint8_t *>(buffer);
|
||||
hvx_params.p_len = &len;
|
||||
|
||||
error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params);
|
||||
|
||||
if (error == ERROR_NONE)
|
||||
return BLE_ERROR_NONE;
|
||||
else
|
||||
return BLE_STACK_BUSY;
|
||||
}
|
||||
|
||||
|
||||
ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
|
||||
{
|
||||
/* Forward the call with the default connection handle. */
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
|
||||
virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
|
||||
virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
|
||||
virtual ble_error_t notify(GattAttribute::Handle_t, const uint8_t[], uint16_t);
|
||||
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
|
||||
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
|
||||
|
||||
|
|
Loading…
Reference in a new issue