close #21: provide an implementation for areUpdatesEnabled()

master
Rohit Grover 2015-07-02 07:57:51 +01:00
parent 1682fb0932
commit bf1405414d
2 changed files with 35 additions and 0 deletions

View File

@ -259,6 +259,39 @@ ble_error_t nRF51GattServer::write(Gap::Handle_t connectionHandle, GattAttribute
return returnValue;
}
ble_error_t nRF51GattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
{
/* Forward the call with the default connection handle. */
return areUpdatesEnabled(nRF51Gap::getInstance().getConnectionHandle(), characteristic, enabledP);
}
ble_error_t nRF51GattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
{
int characteristicIndex = resolveValueHandleToCharIndex(characteristic.getValueHandle());
if (characteristicIndex == -1) {
return BLE_ERROR_INVALID_PARAM;
}
/* Read the cccd value from the GATT server. */
GattAttribute::Handle_t cccdHandle = nrfCharacteristicHandles[characteristicIndex].cccd_handle;
uint16_t cccdValue;
uint16_t length = sizeof(cccdValue);
ble_error_t rc = read(connectionHandle, cccdHandle, reinterpret_cast<uint8_t *>(&cccdValue), &length);
if (rc != BLE_ERROR_NONE) {
return rc;
}
if (length != sizeof(cccdValue)) {
return BLE_ERROR_INVALID_STATE;
}
/* Check for NOTFICATION or INDICATION in CCCD. */
if ((cccdValue & BLE_GATT_HVX_NOTIFICATION) || (cccdValue & BLE_GATT_HVX_INDICATION)) {
*enabledP = true;
}
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
@brief Callback handler for events getting pushed up from the SD

View File

@ -35,6 +35,8 @@ 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 areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
/* nRF51 Functions */
void eventCallback(void);