From 5f2aec8bc7f07caae65f868ab65eae45a7edf52e Mon Sep 17 00:00:00 2001 From: Emilio Monti Date: Mon, 24 Mar 2014 17:09:34 +0000 Subject: [PATCH] Update BLE library to latest version --- libraries/ble/nordic_native/hw/GattServer.h | 2 +- .../nordic_native/hw/nRF51822n/nRF51Gap.cpp | 21 +++++++++---------- .../hw/nRF51822n/nRF51GattServer.cpp | 7 ++++++- .../hw/nRF51822n/nRF51GattServer.h | 2 +- .../hw/nRF51822n/nordic/nordic_global.h | 15 +++++++++++++ .../nRF51822n/nordic/softdevice_handler.cpp | 2 +- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/libraries/ble/nordic_native/hw/GattServer.h b/libraries/ble/nordic_native/hw/GattServer.h index 0e3f0896b6..1855842dab 100644 --- a/libraries/ble/nordic_native/hw/GattServer.h +++ b/libraries/ble/nordic_native/hw/GattServer.h @@ -38,7 +38,7 @@ class GattServer /* These functions must be defined in the sub-class */ virtual ble_error_t addService(GattService &) = 0; virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t) = 0; - virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t) = 0; + virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false) = 0; // ToDo: For updateValue, check the CCCD to see if the value we are // updating has the notify or indicate bits sent, and if BOTH are set diff --git a/libraries/ble/nordic_native/hw/nRF51822n/nRF51Gap.cpp b/libraries/ble/nordic_native/hw/nRF51822n/nRF51Gap.cpp index 6fd923b901..9041c90cf0 100644 --- a/libraries/ble/nordic_native/hw/nRF51822n/nRF51Gap.cpp +++ b/libraries/ble/nordic_native/hw/nRF51822n/nRF51Gap.cpp @@ -162,7 +162,7 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params) return BLE_ERROR_PARAM_OUT_OF_RANGE; } - /* ToDo: Start Advertising */ + /* Start Advertising */ ble_gap_adv_params_t adv_para = { 0 }; adv_para.type = params.getAdvertisingType() ; @@ -174,7 +174,7 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params) ASSERT( ERROR_NONE == sd_ble_gap_adv_start(&adv_para), BLE_ERROR_PARAM_OUT_OF_RANGE); - state.advertising = 1; + state.advertising = 1; return BLE_ERROR_NONE; } @@ -197,12 +197,10 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params) /**************************************************************************/ ble_error_t nRF51Gap::stopAdvertising(void) { - /* ToDo: Stop Advertising */ + /* Stop Advertising */ + ASSERT( ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE); - /* ToDo: Check response */ - wait(0.1); - - state.advertising = 0; + state.advertising = 0; return BLE_ERROR_NONE; } @@ -225,10 +223,11 @@ ble_error_t nRF51Gap::stopAdvertising(void) /**************************************************************************/ ble_error_t nRF51Gap::disconnect(void) { - /* ToDo: Disconnect if we are connected to a central device */ - - state.advertising = 0; - state.connected = 0; + /* Disconnect if we are connected to a central device */ + // ASSERT( ERROR_NONE == sd_ble_gap_disconnect(), BLE_ERROR_PARAM_OUT_OF_RANGE); + + state.advertising = 0; + state.connected = 0; return BLE_ERROR_NONE; } diff --git a/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.cpp b/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.cpp index 021bf88d73..d7495eebd0 100644 --- a/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.cpp +++ b/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.cpp @@ -136,8 +136,13 @@ ble_error_t nRF51GattServer::readValue(uint16_t charHandle, uint8_t buffer[], ui @endcode */ /**************************************************************************/ -ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len) +ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len, bool localOnly) { + if (localOnly) + { + /* Only update locally regardless of 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) ) { diff --git a/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.h b/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.h index 74b34c31ad..5d11de6d00 100644 --- a/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.h +++ b/libraries/ble/nordic_native/hw/nRF51822n/nRF51GattServer.h @@ -43,7 +43,7 @@ class nRF51GattServer : public GattServer /* Functions that must be implemented from GattServer */ virtual ble_error_t addService(GattService &); virtual ble_error_t readValue(uint16_t, uint8_t[], uint16_t); - virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t); + virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false); /* nRF51 Functions */ void eventCallback(void); diff --git a/libraries/ble/nordic_native/hw/nRF51822n/nordic/nordic_global.h b/libraries/ble/nordic_native/hw/nRF51822n/nordic/nordic_global.h index 70ece25463..89fb77c0e5 100644 --- a/libraries/ble/nordic_native/hw/nRF51822n/nordic/nordic_global.h +++ b/libraries/ble/nordic_native/hw/nRF51822n/nordic/nordic_global.h @@ -1,3 +1,18 @@ +/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef _NORDIC_GLOBAL_H_ #define _NORDIC_GLOBAL_H_ diff --git a/libraries/ble/nordic_native/hw/nRF51822n/nordic/softdevice_handler.cpp b/libraries/ble/nordic_native/hw/nRF51822n/nordic/softdevice_handler.cpp index 928022a101..f7229ef9a0 100644 --- a/libraries/ble/nordic_native/hw/nRF51822n/nordic/softdevice_handler.cpp +++ b/libraries/ble/nordic_native/hw/nRF51822n/nordic/softdevice_handler.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. * * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC