aa
Dependents: Peripheral_1_serial_copy Peripheral_1_serial 151006_1st_Scenario_normal
Fork of nRF51822 by
source/btle/btle_discovery.cpp@448:088f5738bf18, 2015-09-25 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Sep 25 15:26:59 2015 +0100
- Revision:
- 448:088f5738bf18
- Parent:
- 446:8328a7d1eac2
Synchronized with git rev ad59bf47
Author: Rohit Grover
Merge branch 'develop'
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 387:b13ab9a7ddb9 | 1 | /* mbed Microcontroller Library |
rgrover1 | 387:b13ab9a7ddb9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 387:b13ab9a7ddb9 | 3 | * |
rgrover1 | 387:b13ab9a7ddb9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 387:b13ab9a7ddb9 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 387:b13ab9a7ddb9 | 6 | * You may obtain a copy of the License at |
rgrover1 | 387:b13ab9a7ddb9 | 7 | * |
rgrover1 | 387:b13ab9a7ddb9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 387:b13ab9a7ddb9 | 9 | * |
rgrover1 | 387:b13ab9a7ddb9 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 387:b13ab9a7ddb9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 387:b13ab9a7ddb9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 387:b13ab9a7ddb9 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 387:b13ab9a7ddb9 | 14 | * limitations under the License. |
rgrover1 | 387:b13ab9a7ddb9 | 15 | */ |
rgrover1 | 387:b13ab9a7ddb9 | 16 | |
rgrover1 | 393:0f7c5048efb3 | 17 | #include "nRF5xServiceDiscovery.h" |
rgrover1 | 393:0f7c5048efb3 | 18 | #include "nRF5xGattClient.h" |
rgrover1 | 387:b13ab9a7ddb9 | 19 | |
rgrover1 | 446:8328a7d1eac2 | 20 | #if !defined(MCU_NRF51_16K_S110) && !defined(MCU_NRF51_32K_S110) |
rgrover1 | 387:b13ab9a7ddb9 | 21 | void bleGattcEventHandler(const ble_evt_t *p_ble_evt) |
rgrover1 | 387:b13ab9a7ddb9 | 22 | { |
rgrover1 | 393:0f7c5048efb3 | 23 | nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery; |
rgrover1 | 387:b13ab9a7ddb9 | 24 | |
rgrover1 | 387:b13ab9a7ddb9 | 25 | switch (p_ble_evt->header.evt_id) { |
rgrover1 | 387:b13ab9a7ddb9 | 26 | case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: |
rgrover1 | 387:b13ab9a7ddb9 | 27 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
rgrover1 | 387:b13ab9a7ddb9 | 28 | case BLE_GATT_STATUS_SUCCESS: |
rgrover1 | 387:b13ab9a7ddb9 | 29 | sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp); |
rgrover1 | 387:b13ab9a7ddb9 | 30 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 31 | |
rgrover1 | 387:b13ab9a7ddb9 | 32 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
rgrover1 | 387:b13ab9a7ddb9 | 33 | default: |
rgrover1 | 387:b13ab9a7ddb9 | 34 | sdSingleton.terminate(); |
rgrover1 | 387:b13ab9a7ddb9 | 35 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 36 | } |
rgrover1 | 387:b13ab9a7ddb9 | 37 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 38 | |
rgrover1 | 387:b13ab9a7ddb9 | 39 | case BLE_GATTC_EVT_CHAR_DISC_RSP: |
rgrover1 | 387:b13ab9a7ddb9 | 40 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
rgrover1 | 387:b13ab9a7ddb9 | 41 | case BLE_GATT_STATUS_SUCCESS: |
rgrover1 | 387:b13ab9a7ddb9 | 42 | sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp); |
rgrover1 | 387:b13ab9a7ddb9 | 43 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 44 | |
rgrover1 | 387:b13ab9a7ddb9 | 45 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
rgrover1 | 387:b13ab9a7ddb9 | 46 | default: |
rgrover1 | 387:b13ab9a7ddb9 | 47 | sdSingleton.terminateCharacteristicDiscovery(); |
rgrover1 | 387:b13ab9a7ddb9 | 48 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 49 | } |
rgrover1 | 387:b13ab9a7ddb9 | 50 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 51 | |
rgrover1 | 387:b13ab9a7ddb9 | 52 | case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: |
rgrover1 | 387:b13ab9a7ddb9 | 53 | if (sdSingleton.isActive()) { |
rgrover1 | 387:b13ab9a7ddb9 | 54 | sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp); |
rgrover1 | 387:b13ab9a7ddb9 | 55 | } |
rgrover1 | 387:b13ab9a7ddb9 | 56 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 57 | |
rgrover1 | 387:b13ab9a7ddb9 | 58 | case BLE_GATTC_EVT_READ_RSP: { |
rgrover1 | 387:b13ab9a7ddb9 | 59 | GattReadCallbackParams response = { |
rgrover1 | 431:db7edc9ad0bc | 60 | .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, |
rgrover1 | 431:db7edc9ad0bc | 61 | .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle, |
rgrover1 | 431:db7edc9ad0bc | 62 | .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset, |
rgrover1 | 431:db7edc9ad0bc | 63 | .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, |
rgrover1 | 431:db7edc9ad0bc | 64 | .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, |
rgrover1 | 387:b13ab9a7ddb9 | 65 | }; |
rgrover1 | 393:0f7c5048efb3 | 66 | nRF5xGattClient::getInstance().processReadResponse(&response); |
rgrover1 | 387:b13ab9a7ddb9 | 67 | } |
rgrover1 | 387:b13ab9a7ddb9 | 68 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 69 | |
rgrover1 | 387:b13ab9a7ddb9 | 70 | case BLE_GATTC_EVT_WRITE_RSP: { |
rgrover1 | 387:b13ab9a7ddb9 | 71 | GattWriteCallbackParams response = { |
rgrover1 | 431:db7edc9ad0bc | 72 | .connHandle = p_ble_evt->evt.gattc_evt.conn_handle, |
rgrover1 | 431:db7edc9ad0bc | 73 | .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle, |
rgrover1 | 431:db7edc9ad0bc | 74 | .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op), |
rgrover1 | 431:db7edc9ad0bc | 75 | .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset, |
rgrover1 | 431:db7edc9ad0bc | 76 | .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len, |
rgrover1 | 431:db7edc9ad0bc | 77 | .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data, |
rgrover1 | 387:b13ab9a7ddb9 | 78 | }; |
rgrover1 | 393:0f7c5048efb3 | 79 | nRF5xGattClient::getInstance().processWriteResponse(&response); |
rgrover1 | 387:b13ab9a7ddb9 | 80 | } |
rgrover1 | 387:b13ab9a7ddb9 | 81 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 82 | |
rgrover1 | 387:b13ab9a7ddb9 | 83 | case BLE_GATTC_EVT_HVX: { |
rgrover1 | 387:b13ab9a7ddb9 | 84 | GattHVXCallbackParams params; |
rgrover1 | 431:db7edc9ad0bc | 85 | params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle; |
rgrover1 | 431:db7edc9ad0bc | 86 | params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle; |
rgrover1 | 431:db7edc9ad0bc | 87 | params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type); |
rgrover1 | 431:db7edc9ad0bc | 88 | params.len = p_ble_evt->evt.gattc_evt.params.hvx.len; |
rgrover1 | 431:db7edc9ad0bc | 89 | params.data = p_ble_evt->evt.gattc_evt.params.hvx.data; |
rgrover1 | 387:b13ab9a7ddb9 | 90 | |
rgrover1 | 393:0f7c5048efb3 | 91 | nRF5xGattClient::getInstance().processHVXEvent(¶ms); |
rgrover1 | 387:b13ab9a7ddb9 | 92 | } |
rgrover1 | 387:b13ab9a7ddb9 | 93 | break; |
rgrover1 | 387:b13ab9a7ddb9 | 94 | } |
rgrover1 | 387:b13ab9a7ddb9 | 95 | |
rgrover1 | 387:b13ab9a7ddb9 | 96 | sdSingleton.progressCharacteristicDiscovery(); |
rgrover1 | 387:b13ab9a7ddb9 | 97 | sdSingleton.progressServiceDiscovery(); |
rgrover1 | 387:b13ab9a7ddb9 | 98 | } |
rgrover1 | 431:db7edc9ad0bc | 99 | #endif |