https://developer.mbed.org/users/TheoHavercroft/code/nrf51-sdk/
Fork of nRF51822 by
Diff: source/btle/btle_discovery.cpp
- Revision:
- 616:a8f9b022d8fd
- Parent:
- 615:65ea2acfc6a2
--- a/source/btle/btle_discovery.cpp Wed Apr 06 22:38:43 2016 +0100 +++ b/source/btle/btle_discovery.cpp Wed Apr 06 22:39:17 2016 +0100 @@ -15,12 +15,19 @@ */ #include "nRF5xServiceDiscovery.h" +#include "nRF5xCharacteristicDescriptorDiscoverer.h" #include "nRF5xGattClient.h" +#include "nRF5xn.h" #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) void bleGattcEventHandler(const ble_evt_t *p_ble_evt) { - nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery; + nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE); + nRF5xGap &gap = (nRF5xGap &) ble.getGap(); + nRF5xGattClient &gattClient = (nRF5xGattClient &) ble.getGattClient(); + nRF5xServiceDiscovery &sdSingleton = gattClient.discovery(); + nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer = + gattClient.characteristicDescriptorDiscoverer(); switch (p_ble_evt->header.evt_id) { case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: @@ -44,7 +51,7 @@ case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: default: - sdSingleton.terminateCharacteristicDiscovery(); + sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE); break; } break; @@ -63,7 +70,7 @@ .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, }; - nRF5xGattClient::getInstance().processReadResponse(&response); + gattClient.processReadResponse(&response); } break; @@ -76,7 +83,7 @@ .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len, .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data, }; - nRF5xGattClient::getInstance().processWriteResponse(&response); + gattClient.processWriteResponse(&response); } break; @@ -88,9 +95,31 @@ params.len = p_ble_evt->evt.gattc_evt.params.hvx.len; params.data = p_ble_evt->evt.gattc_evt.params.hvx.data; - nRF5xGattClient::getInstance().processHVXEvent(¶ms); + gattClient.processHVXEvent(¶ms); } break; + + case BLE_GATTC_EVT_DESC_DISC_RSP: { + uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle; + uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status; + const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp; + + switch(status) { + case BLE_GATT_STATUS_SUCCESS: + characteristicDescriptorDiscoverer.process( + conn_handle, + discovered_descriptors + ); + break; + case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: + // end of discovery + characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE); + break; + default: + characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED); + break; + } + } break; } sdSingleton.progressCharacteristicDiscovery();