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