From 6cdb6f161f28ec86603deb6fb6b5983b11f32e4d Mon Sep 17 00:00:00 2001 From: Fabien Comte Date: Fri, 28 Aug 2015 14:44:34 +0200 Subject: [PATCH 1/3] rgrover patch fixed --- source/nRF5xGattServer.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/source/nRF5xGattServer.cpp b/source/nRF5xGattServer.cpp index 82168a5..8b0fae7 100644 --- a/source/nRF5xGattServer.cpp +++ b/source/nRF5xGattServer.cpp @@ -223,8 +223,7 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute int characteristicIndex = resolveValueHandleToCharIndex(attributeHandle); if ((characteristicIndex != -1) && - (p_characteristics[characteristicIndex]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)) && - (gapConnectionHandle != connectionHandle)) { + (p_characteristics[characteristicIndex]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY))) { /* HVX update for the characteristic value */ ble_gatts_hvx_params_t hvx_params; @@ -234,23 +233,29 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute hvx_params.offset = 0; hvx_params.p_data = const_cast(buffer); hvx_params.p_len = &len; - + error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &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(connectionHandle, attributeHandle, &value), - BLE_ERROR_PARAM_OUT_OF_RANGE ); - } - - /* Notifications consume application buffers. The return value can - be used for resending notifications. - */ if (error != ERROR_NONE) { - returnValue = BLE_STACK_BUSY; + switch (error) { + case ERROR_BLE_NO_TX_BUFFERS: /* Notifications consume application buffers. The return value can be used for resending notifications. */ + case ERROR_BUSY: + returnValue = BLE_STACK_BUSY; + break; + + case ERROR_INVALID_STATE: + case ERROR_BLEGATTS_SYS_ATTR_MISSING: + returnValue = BLE_ERROR_INVALID_STATE; + break; + + default : + ASSERT_INT( ERROR_NONE, + sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value), + BLE_ERROR_PARAM_OUT_OF_RANGE ); + break; + } } } else { + returnValue = BLE_ERROR_INVALID_STATE; // if assert is not used ASSERT_INT( ERROR_NONE, sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value), BLE_ERROR_PARAM_OUT_OF_RANGE ); From 887426ad0bc2534159439f65fc23dd425b5db938 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Fri, 28 Aug 2015 14:01:52 +0100 Subject: [PATCH 2/3] minor white space diff --- source/nRF5xGattServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/nRF5xGattServer.cpp b/source/nRF5xGattServer.cpp index 70c0590..e0e009a 100644 --- a/source/nRF5xGattServer.cpp +++ b/source/nRF5xGattServer.cpp @@ -233,7 +233,7 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute hvx_params.offset = 0; hvx_params.p_data = const_cast(buffer); hvx_params.p_len = &len; - + error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params); if (error != ERROR_NONE) { switch (error) { From 167f304b686da284229de327acd5fabd692f08b3 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Wed, 2 Sep 2015 09:17:02 +0100 Subject: [PATCH 3/3] minor cleanup to Fabien's pull request; remove the un-necessary gapConnectionHandle --- source/nRF5xGattServer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/nRF5xGattServer.cpp b/source/nRF5xGattServer.cpp index e0e009a..b0aee36 100644 --- a/source/nRF5xGattServer.cpp +++ b/source/nRF5xGattServer.cpp @@ -204,7 +204,6 @@ ble_error_t nRF5xGattServer::write(GattAttribute::Handle_t attributeHandle, cons ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly) { - uint16_t gapConnectionHandle = nRF5xGap::getInstance().getConnectionHandle(); ble_error_t returnValue = BLE_ERROR_NONE; ble_gatts_value_t value = { @@ -234,7 +233,10 @@ ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute hvx_params.p_data = const_cast(buffer); hvx_params.p_len = &len; - error_t error = (error_t) sd_ble_gatts_hvx(gapConnectionHandle, &hvx_params); + if (connectionHandle == BLE_CONN_HANDLE_INVALID) { /* use the default connection handle if the caller hasn't specified a valid connectionHandle. */ + connectionHandle = nRF5xGap::getInstance().getConnectionHandle(); + } + error_t error = (error_t) sd_ble_gatts_hvx(connectionHandle, &hvx_params); if (error != ERROR_NONE) { switch (error) { case ERROR_BLE_NO_TX_BUFFERS: /* Notifications consume application buffers. The return value can be used for resending notifications. */