nordic
Fork of nRF51822 by
Diff: source/btle/btle.cpp
- Revision:
- 571:f162898cb6c4
- Parent:
- 568:e1800bd55a9e
- Child:
- 572:bbf6410b6a89
--- a/source/btle/btle.cpp Mon Jan 11 10:19:20 2016 +0000 +++ b/source/btle/btle.cpp Mon Jan 11 10:19:21 2016 +0000 @@ -27,9 +27,7 @@ #include "custom/custom_helper.h" #include "ble/GapEvents.h" -#include "nRF5xGap.h" -#include "nRF5xGattServer.h" -#include "nRF5xSecurityManager.h" +#include "nRF5xn.h" extern "C" { #include "pstorage.h" @@ -41,10 +39,6 @@ #include "ble_hci.h" #include "btle_discovery.h" -#include "nRF5xGattClient.h" -#include "nRF5xServiceDiscovery.h" -#include "nRF5xCharacteristicDescriptorDiscoverer.h" - extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name); void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name); @@ -142,6 +136,11 @@ bleGattcEventHandler(p_ble_evt); #endif + nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE); + nRF5xGap &gap = (nRF5xGap &) ble.getGap(); + nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer(); + nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager(); + /* Custom event handler */ switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: { @@ -152,11 +151,11 @@ #else Gap::Role_t role = static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role); #endif - nRF5xGap::getInstance().setConnectionHandle(handle); + gap.setConnectionHandle(handle); const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params)); const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr; const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr; - nRF5xGap::getInstance().processConnectionEvent(handle, + gap.processConnectionEvent(handle, role, static_cast<Gap::AddressType_t>(peer->addr_type), peer->addr, static_cast<Gap::AddressType_t>(own->addr_type), own->addr, @@ -168,7 +167,7 @@ Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle; // Since we are not in a connection and have not started advertising, // store bonds - nRF5xGap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID); + gap.setConnectionHandle (BLE_CONN_HANDLE_INVALID); Gap::DisconnectionReason_t reason; switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) { @@ -187,22 +186,16 @@ reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason); break; } - - // Close all pending discoveries for this connection - nRF5xGattClient& gattClient = nRF5xGattClient::getInstance(); - gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE); - gattClient.discovery().terminate(handle); - - nRF5xGap::getInstance().processDisconnectionEvent(handle, reason); + gap.processDisconnectionEvent(handle, reason); break; } case BLE_GAP_EVT_PASSKEY_DISPLAY: - nRF5xSecurityManager::getInstance().processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey); + securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey); break; case BLE_GAP_EVT_TIMEOUT: - nRF5xGap::getInstance().processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src)); + gap.processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src)); break; case BLE_GATTC_EVT_TIMEOUT: @@ -214,12 +207,12 @@ case BLE_GAP_EVT_ADV_REPORT: { const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report; - nRF5xGap::getInstance().processAdvertisementReport(advReport->peer_addr.addr, - advReport->rssi, - advReport->scan_rsp, - static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type), - advReport->dlen, - advReport->data); + gap.processAdvertisementReport(advReport->peer_addr.addr, + advReport->rssi, + advReport->scan_rsp, + static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type), + advReport->dlen, + advReport->data); break; } @@ -227,7 +220,7 @@ break; } - nRF5xGattServer::getInstance().hwCallback(p_ble_evt); + gattServer.hwCallback(p_ble_evt); } /*! @brief Callback when an error occurs inside the SoftDevice */