test
Fork of nRF51822 by
source/btle/btle_discovery.cpp@616:a8f9b022d8fd, 2016-04-06 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Apr 06 22:39:17 2016 +0100
- Revision:
- 616:a8f9b022d8fd
- Parent:
- 615:65ea2acfc6a2
Synchronized with git rev 67d0ac73
Author: Joe Finney
microbit: Update to indicate when system attributes require intialisation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LancasterUniversity | 615:65ea2acfc6a2 | 1 | /* mbed Microcontroller Library |
LancasterUniversity | 615:65ea2acfc6a2 | 2 | * Copyright (c) 2006-2013 ARM Limited |
LancasterUniversity | 615:65ea2acfc6a2 | 3 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
LancasterUniversity | 615:65ea2acfc6a2 | 5 | * you may not use this file except in compliance with the License. |
LancasterUniversity | 615:65ea2acfc6a2 | 6 | * You may obtain a copy of the License at |
LancasterUniversity | 615:65ea2acfc6a2 | 7 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
LancasterUniversity | 615:65ea2acfc6a2 | 9 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 10 | * Unless required by applicable law or agreed to in writing, software |
LancasterUniversity | 615:65ea2acfc6a2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
LancasterUniversity | 615:65ea2acfc6a2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
LancasterUniversity | 615:65ea2acfc6a2 | 13 | * See the License for the specific language governing permissions and |
LancasterUniversity | 615:65ea2acfc6a2 | 14 | * limitations under the License. |
LancasterUniversity | 615:65ea2acfc6a2 | 15 | */ |
LancasterUniversity | 615:65ea2acfc6a2 | 16 | |
LancasterUniversity | 615:65ea2acfc6a2 | 17 | #include "nRF5xServiceDiscovery.h" |
LancasterUniversity | 616:a8f9b022d8fd | 18 | #include "nRF5xCharacteristicDescriptorDiscoverer.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 19 | #include "nRF5xGattClient.h" |
LancasterUniversity | 616:a8f9b022d8fd | 20 | #include "nRF5xn.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 21 | |
LancasterUniversity | 615:65ea2acfc6a2 | 22 | #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) |
LancasterUniversity | 615:65ea2acfc6a2 | 23 | void bleGattcEventHandler(const ble_evt_t *p_ble_evt) |
LancasterUniversity | 615:65ea2acfc6a2 | 24 | { |
LancasterUniversity | 616:a8f9b022d8fd | 25 | nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE); |
LancasterUniversity | 616:a8f9b022d8fd | 26 | nRF5xGap &gap = (nRF5xGap &) ble.getGap(); |
LancasterUniversity | 616:a8f9b022d8fd | 27 | nRF5xGattClient &gattClient = (nRF5xGattClient &) ble.getGattClient(); |
LancasterUniversity | 616:a8f9b022d8fd | 28 | nRF5xServiceDiscovery &sdSingleton = gattClient.discovery(); |
LancasterUniversity | 616:a8f9b022d8fd | 29 | nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer = |
LancasterUniversity | 616:a8f9b022d8fd | 30 | gattClient.characteristicDescriptorDiscoverer(); |
LancasterUniversity | 615:65ea2acfc6a2 | 31 | |
LancasterUniversity | 615:65ea2acfc6a2 | 32 | switch (p_ble_evt->header.evt_id) { |
LancasterUniversity | 615:65ea2acfc6a2 | 33 | case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: |
LancasterUniversity | 615:65ea2acfc6a2 | 34 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
LancasterUniversity | 615:65ea2acfc6a2 | 35 | case BLE_GATT_STATUS_SUCCESS: |
LancasterUniversity | 615:65ea2acfc6a2 | 36 | sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp); |
LancasterUniversity | 615:65ea2acfc6a2 | 37 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 38 | |
LancasterUniversity | 615:65ea2acfc6a2 | 39 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
LancasterUniversity | 615:65ea2acfc6a2 | 40 | default: |
LancasterUniversity | 615:65ea2acfc6a2 | 41 | sdSingleton.terminate(); |
LancasterUniversity | 615:65ea2acfc6a2 | 42 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 43 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 44 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 45 | |
LancasterUniversity | 615:65ea2acfc6a2 | 46 | case BLE_GATTC_EVT_CHAR_DISC_RSP: |
LancasterUniversity | 615:65ea2acfc6a2 | 47 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
LancasterUniversity | 615:65ea2acfc6a2 | 48 | case BLE_GATT_STATUS_SUCCESS: |
LancasterUniversity | 615:65ea2acfc6a2 | 49 | sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp); |
LancasterUniversity | 615:65ea2acfc6a2 | 50 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 51 | |
LancasterUniversity | 615:65ea2acfc6a2 | 52 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
LancasterUniversity | 615:65ea2acfc6a2 | 53 | default: |
LancasterUniversity | 616:a8f9b022d8fd | 54 | sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE); |
LancasterUniversity | 615:65ea2acfc6a2 | 55 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 56 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 57 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 58 | |
LancasterUniversity | 615:65ea2acfc6a2 | 59 | case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: |
LancasterUniversity | 615:65ea2acfc6a2 | 60 | if (sdSingleton.isActive()) { |
LancasterUniversity | 615:65ea2acfc6a2 | 61 | sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp); |
LancasterUniversity | 615:65ea2acfc6a2 | 62 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 63 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 64 | |
LancasterUniversity | 615:65ea2acfc6a2 | 65 | case BLE_GATTC_EVT_READ_RSP: { |
LancasterUniversity | 615:65ea2acfc6a2 | 66 | GattReadCallbackParams response = { |
LancasterUniversity | 615:65ea2acfc6a2 | 67 | .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 68 | .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 69 | .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset, |
LancasterUniversity | 615:65ea2acfc6a2 | 70 | .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, |
LancasterUniversity | 615:65ea2acfc6a2 | 71 | .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, |
LancasterUniversity | 615:65ea2acfc6a2 | 72 | }; |
LancasterUniversity | 616:a8f9b022d8fd | 73 | gattClient.processReadResponse(&response); |
LancasterUniversity | 615:65ea2acfc6a2 | 74 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 75 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 76 | |
LancasterUniversity | 615:65ea2acfc6a2 | 77 | case BLE_GATTC_EVT_WRITE_RSP: { |
LancasterUniversity | 615:65ea2acfc6a2 | 78 | GattWriteCallbackParams response = { |
LancasterUniversity | 615:65ea2acfc6a2 | 79 | .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 80 | .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 81 | .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op), |
LancasterUniversity | 615:65ea2acfc6a2 | 82 | .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset, |
LancasterUniversity | 615:65ea2acfc6a2 | 83 | .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len, |
LancasterUniversity | 615:65ea2acfc6a2 | 84 | .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data, |
LancasterUniversity | 615:65ea2acfc6a2 | 85 | }; |
LancasterUniversity | 616:a8f9b022d8fd | 86 | gattClient.processWriteResponse(&response); |
LancasterUniversity | 615:65ea2acfc6a2 | 87 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 88 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 89 | |
LancasterUniversity | 615:65ea2acfc6a2 | 90 | case BLE_GATTC_EVT_HVX: { |
LancasterUniversity | 615:65ea2acfc6a2 | 91 | GattHVXCallbackParams params; |
LancasterUniversity | 615:65ea2acfc6a2 | 92 | params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle; |
LancasterUniversity | 615:65ea2acfc6a2 | 93 | params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle; |
LancasterUniversity | 615:65ea2acfc6a2 | 94 | params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type); |
LancasterUniversity | 615:65ea2acfc6a2 | 95 | params.len = p_ble_evt->evt.gattc_evt.params.hvx.len; |
LancasterUniversity | 615:65ea2acfc6a2 | 96 | params.data = p_ble_evt->evt.gattc_evt.params.hvx.data; |
LancasterUniversity | 615:65ea2acfc6a2 | 97 | |
LancasterUniversity | 616:a8f9b022d8fd | 98 | gattClient.processHVXEvent(¶ms); |
LancasterUniversity | 615:65ea2acfc6a2 | 99 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 100 | break; |
LancasterUniversity | 616:a8f9b022d8fd | 101 | |
LancasterUniversity | 616:a8f9b022d8fd | 102 | case BLE_GATTC_EVT_DESC_DISC_RSP: { |
LancasterUniversity | 616:a8f9b022d8fd | 103 | uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle; |
LancasterUniversity | 616:a8f9b022d8fd | 104 | uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status; |
LancasterUniversity | 616:a8f9b022d8fd | 105 | const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp; |
LancasterUniversity | 616:a8f9b022d8fd | 106 | |
LancasterUniversity | 616:a8f9b022d8fd | 107 | switch(status) { |
LancasterUniversity | 616:a8f9b022d8fd | 108 | case BLE_GATT_STATUS_SUCCESS: |
LancasterUniversity | 616:a8f9b022d8fd | 109 | characteristicDescriptorDiscoverer.process( |
LancasterUniversity | 616:a8f9b022d8fd | 110 | conn_handle, |
LancasterUniversity | 616:a8f9b022d8fd | 111 | discovered_descriptors |
LancasterUniversity | 616:a8f9b022d8fd | 112 | ); |
LancasterUniversity | 616:a8f9b022d8fd | 113 | break; |
LancasterUniversity | 616:a8f9b022d8fd | 114 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
LancasterUniversity | 616:a8f9b022d8fd | 115 | // end of discovery |
LancasterUniversity | 616:a8f9b022d8fd | 116 | characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE); |
LancasterUniversity | 616:a8f9b022d8fd | 117 | break; |
LancasterUniversity | 616:a8f9b022d8fd | 118 | default: |
LancasterUniversity | 616:a8f9b022d8fd | 119 | characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED); |
LancasterUniversity | 616:a8f9b022d8fd | 120 | break; |
LancasterUniversity | 616:a8f9b022d8fd | 121 | } |
LancasterUniversity | 616:a8f9b022d8fd | 122 | } break; |
LancasterUniversity | 615:65ea2acfc6a2 | 123 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 124 | |
LancasterUniversity | 615:65ea2acfc6a2 | 125 | sdSingleton.progressCharacteristicDiscovery(); |
LancasterUniversity | 615:65ea2acfc6a2 | 126 | sdSingleton.progressServiceDiscovery(); |
LancasterUniversity | 615:65ea2acfc6a2 | 127 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 128 | #endif |