add a 'reason' parameter for disconnect() and onDisconnection callback

This commit is contained in:
Rohit Grover 2014-08-29 15:03:40 +01:00
parent 118f9d8bfa
commit 7050c1e1c8
3 changed files with 19 additions and 5 deletions

View File

@ -39,6 +39,8 @@
#include "nRF51Gap.h"
#include "nRF51GattServer.h"
#include "ble_hci.h"
#if NEED_BOND_MANAGER /* disabled by default */
static void service_error_callback(uint32_t nrf_error);
#endif
@ -133,7 +135,10 @@ static void btle_handler(ble_evt_t *p_ble_evt)
#if NEED_BOND_MANAGER /* disabled by default */
ASSERT_STATUS_RET_VOID ( ble_bondmngr_bonded_centrals_store());
#endif
nRF51Gap::getInstance().processHandleSpecificEvent(GapEvents::GAP_EVENT_DISCONNECTED, handle);
if (p_ble_evt->evt.gap_evt.params.disconnected.reason == BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION) {
nRF51Gap::getInstance().processDisconnectionEvent(handle, Gap::LOCAL_HOST_TERMINATED_CONNECTION);
}
break;
}

View File

@ -217,14 +217,23 @@ ble_error_t nRF51Gap::stopAdvertising(void)
@endcode
*/
/**************************************************************************/
ble_error_t nRF51Gap::disconnect(void)
ble_error_t nRF51Gap::disconnect(DisconnectionReason_t reason)
{
state.advertising = 0;
state.connected = 0;
uint8_t code = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION;
switch (reason) {
case REMOTE_USER_TERMINATED_CONNECTION:
code = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION;
break;
case CONN_INTERVAL_UNACCEPTABLE:
code = BLE_HCI_CONN_INTERVAL_UNACCEPTABLE;
break;
}
/* Disconnect if we are connected to a central device */
ASSERT_INT(ERROR_NONE,
sd_ble_gap_disconnect(m_connectionHandle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION), BLE_ERROR_PARAM_OUT_OF_RANGE);
ASSERT_INT(ERROR_NONE, sd_ble_gap_disconnect(m_connectionHandle, code), BLE_ERROR_PARAM_OUT_OF_RANGE);
return BLE_ERROR_NONE;
}

View File

@ -45,7 +45,7 @@ public:
const GapAdvertisingData &);
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
virtual ble_error_t stopAdvertising(void);
virtual ble_error_t disconnect(void);
virtual ble_error_t disconnect(DisconnectionReason_t reason);
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);