Changed the device name.
Dependents: BLE_Health_Thermometer_HeartRateMonitor
Fork of BLE_API_Native_IRC by
Diff: hw/nRF51822n/nRF51GattServer.cpp
- Revision:
- 8:b346eddb9346
- Parent:
- 0:4c3097c65247
--- a/hw/nRF51822n/nRF51GattServer.cpp Thu Feb 13 11:27:58 2014 +0000 +++ b/hw/nRF51822n/nRF51GattServer.cpp Fri Feb 14 10:50:45 2014 +0000 @@ -71,7 +71,7 @@ /* Update the characteristic handle */ p_char->handle = characteristicCount; - characteristicCount++; + p_characteristics[characteristicCount++] = p_char; } serviceCount++; @@ -138,8 +138,31 @@ /**************************************************************************/ ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len) { - /* ToDo: Handle Notify/Indicate */ - ASSERT_INT( ERROR_NONE, sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), BLE_ERROR_PARAM_OUT_OF_RANGE ); + if ((p_characteristics[charHandle]->properties & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) && + (m_connectionHandle != BLE_CONN_HANDLE_INVALID) ) + { + /* HVX update for the characteristic value */ + ble_gatts_hvx_params_t hvx_params; + + hvx_params.handle = nrfCharacteristicHandles[charHandle].value_handle; + hvx_params.type = (p_characteristics[charHandle]->properties & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION; + hvx_params.offset = 0; + hvx_params.p_data = buffer; + hvx_params.p_len = &len; + + error_t error = (error_t) sd_ble_gatts_hvx(m_connectionHandle, &hvx_params); + + /* ERROR_INVALID_STATE, ERROR_BUSY, ERROR_GATTS_SYS_ATTR_MISSING and ERROR_NO_TX_BUFFERS the ATT table has been updated. */ + if ( (error != ERROR_NONE ) && (error != ERROR_INVALID_STATE) && + (error != ERROR_BLE_NO_TX_BUFFERS ) && (error != ERROR_BUSY ) && + (error != ERROR_BLEGATTS_SYS_ATTR_MISSING ) ) + { + ASSERT_INT( ERROR_NONE, sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), BLE_ERROR_PARAM_OUT_OF_RANGE ); + } + } else + { + ASSERT_INT( ERROR_NONE, sd_ble_gatts_value_set(nrfCharacteristicHandles[charHandle].value_handle, 0, &len, buffer), BLE_ERROR_PARAM_OUT_OF_RANGE ); + } return BLE_ERROR_NONE; }