test
Fork of nRF51822 by
source/btle/btle_discovery.cpp@615:65ea2acfc6a2, 2016-04-06 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Apr 06 22:38:43 2016 +0100
- Revision:
- 615:65ea2acfc6a2
- Parent:
- 592:f9574772b816
- Child:
- 616:a8f9b022d8fd
Synchronized with git rev 60a7c0c0
Author: Rohit Grover
bring in the latest changes for BLE::init() where we allow <object, member> tuples for init callback.
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 | 615:65ea2acfc6a2 | 18 | #include "nRF5xGattClient.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 19 | |
LancasterUniversity | 615:65ea2acfc6a2 | 20 | #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) |
LancasterUniversity | 615:65ea2acfc6a2 | 21 | void bleGattcEventHandler(const ble_evt_t *p_ble_evt) |
LancasterUniversity | 615:65ea2acfc6a2 | 22 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 23 | nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery; |
LancasterUniversity | 615:65ea2acfc6a2 | 24 | |
LancasterUniversity | 615:65ea2acfc6a2 | 25 | switch (p_ble_evt->header.evt_id) { |
LancasterUniversity | 615:65ea2acfc6a2 | 26 | case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: |
LancasterUniversity | 615:65ea2acfc6a2 | 27 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
LancasterUniversity | 615:65ea2acfc6a2 | 28 | case BLE_GATT_STATUS_SUCCESS: |
LancasterUniversity | 615:65ea2acfc6a2 | 29 | sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp); |
LancasterUniversity | 615:65ea2acfc6a2 | 30 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 31 | |
LancasterUniversity | 615:65ea2acfc6a2 | 32 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
LancasterUniversity | 615:65ea2acfc6a2 | 33 | default: |
LancasterUniversity | 615:65ea2acfc6a2 | 34 | sdSingleton.terminate(); |
LancasterUniversity | 615:65ea2acfc6a2 | 35 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 36 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 37 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 38 | |
LancasterUniversity | 615:65ea2acfc6a2 | 39 | case BLE_GATTC_EVT_CHAR_DISC_RSP: |
LancasterUniversity | 615:65ea2acfc6a2 | 40 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
LancasterUniversity | 615:65ea2acfc6a2 | 41 | case BLE_GATT_STATUS_SUCCESS: |
LancasterUniversity | 615:65ea2acfc6a2 | 42 | sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp); |
LancasterUniversity | 615:65ea2acfc6a2 | 43 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 44 | |
LancasterUniversity | 615:65ea2acfc6a2 | 45 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
LancasterUniversity | 615:65ea2acfc6a2 | 46 | default: |
LancasterUniversity | 615:65ea2acfc6a2 | 47 | sdSingleton.terminateCharacteristicDiscovery(); |
LancasterUniversity | 615:65ea2acfc6a2 | 48 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 49 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 50 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 51 | |
LancasterUniversity | 615:65ea2acfc6a2 | 52 | case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: |
LancasterUniversity | 615:65ea2acfc6a2 | 53 | if (sdSingleton.isActive()) { |
LancasterUniversity | 615:65ea2acfc6a2 | 54 | sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp); |
LancasterUniversity | 615:65ea2acfc6a2 | 55 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 56 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 57 | |
LancasterUniversity | 615:65ea2acfc6a2 | 58 | case BLE_GATTC_EVT_READ_RSP: { |
LancasterUniversity | 615:65ea2acfc6a2 | 59 | GattReadCallbackParams response = { |
LancasterUniversity | 615:65ea2acfc6a2 | 60 | .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 61 | .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 62 | .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset, |
LancasterUniversity | 615:65ea2acfc6a2 | 63 | .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, |
LancasterUniversity | 615:65ea2acfc6a2 | 64 | .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, |
LancasterUniversity | 615:65ea2acfc6a2 | 65 | }; |
LancasterUniversity | 615:65ea2acfc6a2 | 66 | nRF5xGattClient::getInstance().processReadResponse(&response); |
LancasterUniversity | 615:65ea2acfc6a2 | 67 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 68 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 69 | |
LancasterUniversity | 615:65ea2acfc6a2 | 70 | case BLE_GATTC_EVT_WRITE_RSP: { |
LancasterUniversity | 615:65ea2acfc6a2 | 71 | GattWriteCallbackParams response = { |
LancasterUniversity | 615:65ea2acfc6a2 | 72 | .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 73 | .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 74 | .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op), |
LancasterUniversity | 615:65ea2acfc6a2 | 75 | .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset, |
LancasterUniversity | 615:65ea2acfc6a2 | 76 | .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len, |
LancasterUniversity | 615:65ea2acfc6a2 | 77 | .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data, |
LancasterUniversity | 615:65ea2acfc6a2 | 78 | }; |
LancasterUniversity | 615:65ea2acfc6a2 | 79 | nRF5xGattClient::getInstance().processWriteResponse(&response); |
LancasterUniversity | 615:65ea2acfc6a2 | 80 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 81 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 82 | |
LancasterUniversity | 615:65ea2acfc6a2 | 83 | case BLE_GATTC_EVT_HVX: { |
LancasterUniversity | 615:65ea2acfc6a2 | 84 | GattHVXCallbackParams params; |
LancasterUniversity | 615:65ea2acfc6a2 | 85 | params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle; |
LancasterUniversity | 615:65ea2acfc6a2 | 86 | params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle; |
LancasterUniversity | 615:65ea2acfc6a2 | 87 | params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type); |
LancasterUniversity | 615:65ea2acfc6a2 | 88 | params.len = p_ble_evt->evt.gattc_evt.params.hvx.len; |
LancasterUniversity | 615:65ea2acfc6a2 | 89 | params.data = p_ble_evt->evt.gattc_evt.params.hvx.data; |
LancasterUniversity | 615:65ea2acfc6a2 | 90 | |
LancasterUniversity | 615:65ea2acfc6a2 | 91 | nRF5xGattClient::getInstance().processHVXEvent(¶ms); |
LancasterUniversity | 615:65ea2acfc6a2 | 92 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 93 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 94 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 95 | |
LancasterUniversity | 615:65ea2acfc6a2 | 96 | sdSingleton.progressCharacteristicDiscovery(); |
LancasterUniversity | 615:65ea2acfc6a2 | 97 | sdSingleton.progressServiceDiscovery(); |
LancasterUniversity | 615:65ea2acfc6a2 | 98 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 99 | #endif |