From 348e2de6c8b2badc1fd1fe7ae044c24c25244a11 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Thu, 3 Apr 2014 02:12:28 +0200 Subject: [PATCH] Added get/set method for GAP connection handle --- libraries/ble/nRF51822/btle/btle.cpp | 6 +++--- libraries/ble/nRF51822/nRF51Gap.cpp | 20 ++++++++++++++++++++ libraries/ble/nRF51822/nRF51Gap.h | 6 ++++-- libraries/ble/nRF51822/nRF51GattServer.cpp | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libraries/ble/nRF51822/btle/btle.cpp b/libraries/ble/nRF51822/btle/btle.cpp index aea17ad8d5..1870ebbaaa 100644 --- a/libraries/ble/nRF51822/btle/btle.cpp +++ b/libraries/ble/nRF51822/btle/btle.cpp @@ -94,13 +94,13 @@ static void btle_handler(ble_evt_t * p_ble_evt) switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: - nRF51Gap::getInstance().m_connectionHandle = p_ble_evt->evt.gap_evt.conn_handle; + nRF51Gap::getInstance().setConnectionHandle( p_ble_evt->evt.gap_evt.conn_handle ); nRF51Gap::getInstance().handleEvent(GapEvents::GAP_EVENT_CONNECTED); break; case BLE_GAP_EVT_DISCONNECTED: // Since we are not in a connection and have not started advertising, store bonds - nRF51Gap::getInstance().m_connectionHandle = BLE_CONN_HANDLE_INVALID; + nRF51Gap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID); ASSERT_STATUS_RET_VOID ( ble_bondmngr_bonded_centrals_store() ); nRF51Gap::getInstance().handleEvent(GapEvents::GAP_EVENT_DISCONNECTED); break; @@ -117,7 +117,7 @@ static void btle_handler(ble_evt_t * p_ble_evt) sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE ; sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE ; - ASSERT_STATUS_RET_VOID ( sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().m_connectionHandle, BLE_GAP_SEC_STATUS_SUCCESS, &sec_params) ); + ASSERT_STATUS_RET_VOID ( sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(), BLE_GAP_SEC_STATUS_SUCCESS, &sec_params) ); } break; diff --git a/libraries/ble/nRF51822/nRF51Gap.cpp b/libraries/ble/nRF51822/nRF51Gap.cpp index d69fa65918..b7a2291a31 100644 --- a/libraries/ble/nRF51822/nRF51Gap.cpp +++ b/libraries/ble/nRF51822/nRF51Gap.cpp @@ -234,6 +234,26 @@ ble_error_t nRF51Gap::disconnect(void) return BLE_ERROR_NONE; } +/**************************************************************************/ +/*! + @brief Sets the 16-bit connection handle +*/ +/**************************************************************************/ +void nRF51Gap::setConnectionHandle(uint16_t con_handle) +{ + m_connectionHandle = con_handle; +} + +/**************************************************************************/ +/*! + @brief Gets the 16-bit connection handle +*/ +/**************************************************************************/ +uint16_t nRF51Gap::getConnectionHandle(void) +{ + return m_connectionHandle; +} + /**************************************************************************/ /*! @brief Sets the BLE device address diff --git a/libraries/ble/nRF51822/nRF51Gap.h b/libraries/ble/nRF51822/nRF51Gap.h index 5efb1d0e7f..a010e947c7 100644 --- a/libraries/ble/nRF51822/nRF51Gap.h +++ b/libraries/ble/nRF51822/nRF51Gap.h @@ -45,10 +45,12 @@ class nRF51Gap : public Gap virtual ble_error_t startAdvertising(GapAdvertisingParams &); virtual ble_error_t stopAdvertising(void); virtual ble_error_t disconnect(void); - - uint16_t m_connectionHandle; // TODO move to private + void setConnectionHandle(uint16_t con_handle); + uint16_t getConnectionHandle(void); + private: + uint16_t m_connectionHandle; nRF51Gap() { m_connectionHandle = BLE_CONN_HANDLE_INVALID; }; nRF51Gap(nRF51Gap const&); void operator=(nRF51Gap const&); diff --git a/libraries/ble/nRF51822/nRF51GattServer.cpp b/libraries/ble/nRF51822/nRF51GattServer.cpp index cd6eb564a1..ec1c981d29 100644 --- a/libraries/ble/nRF51822/nRF51GattServer.cpp +++ b/libraries/ble/nRF51822/nRF51GattServer.cpp @@ -140,7 +140,7 @@ ble_error_t nRF51GattServer::readValue(uint16_t charHandle, uint8_t buffer[], ui /**************************************************************************/ ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[], uint16_t len, bool localOnly) { - uint16_t gapConnectionHandle = nRF51Gap::getInstance().m_connectionHandle; + uint16_t gapConnectionHandle = nRF51Gap::getInstance().getConnectionHandle(); if (localOnly) {