nordic
Fork of nRF51822 by
btle/btle_discovery.cpp@333:b054000833d4, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:55:32 2015 +0100
- Revision:
- 333:b054000833d4
- Parent:
- 331:0a8ebc25b57c
- Child:
- 334:8eedcd324853
Synchronized with git rev 5a4e62f1
Author: Rohit Grover
one massive commit to integrate with GattClient.
DiscoveredCharacteristic still needs to setup gattc pointers.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 244:a966506d1e5b | 1 | /* mbed Microcontroller Library |
rgrover1 | 244:a966506d1e5b | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 244:a966506d1e5b | 3 | * |
rgrover1 | 244:a966506d1e5b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 244:a966506d1e5b | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 244:a966506d1e5b | 6 | * You may obtain a copy of the License at |
rgrover1 | 244:a966506d1e5b | 7 | * |
rgrover1 | 244:a966506d1e5b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 244:a966506d1e5b | 9 | * |
rgrover1 | 244:a966506d1e5b | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 244:a966506d1e5b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 244:a966506d1e5b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 244:a966506d1e5b | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 244:a966506d1e5b | 14 | * limitations under the License. |
rgrover1 | 244:a966506d1e5b | 15 | */ |
rgrover1 | 244:a966506d1e5b | 16 | |
rgrover1 | 333:b054000833d4 | 17 | #include "nRFServiceDiscovery.h" |
rgrover1 | 333:b054000833d4 | 18 | #include "nRF51GattClient.h" |
rgrover1 | 252:d4e0cf5e8751 | 19 | |
rgrover1 | 244:a966506d1e5b | 20 | void bleGattcEventHandler(const ble_evt_t *p_ble_evt) |
rgrover1 | 244:a966506d1e5b | 21 | { |
rgrover1 | 333:b054000833d4 | 22 | nRFServiceDiscovery &sdSingleton = nRF51GattClient::getInstance().discovery; |
rgrover1 | 333:b054000833d4 | 23 | |
rgrover1 | 244:a966506d1e5b | 24 | switch (p_ble_evt->header.evt_id) { |
rgrover1 | 244:a966506d1e5b | 25 | case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: |
rgrover1 | 244:a966506d1e5b | 26 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
rgrover1 | 244:a966506d1e5b | 27 | case BLE_GATT_STATUS_SUCCESS: |
rgrover1 | 279:26e3f0ef1e14 | 28 | sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp); |
rgrover1 | 244:a966506d1e5b | 29 | break; |
rgrover1 | 244:a966506d1e5b | 30 | |
rgrover1 | 244:a966506d1e5b | 31 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
rgrover1 | 244:a966506d1e5b | 32 | default: |
rgrover1 | 279:26e3f0ef1e14 | 33 | sdSingleton.terminate(); |
rgrover1 | 244:a966506d1e5b | 34 | break; |
rgrover1 | 244:a966506d1e5b | 35 | } |
rgrover1 | 244:a966506d1e5b | 36 | break; |
rgrover1 | 244:a966506d1e5b | 37 | |
rgrover1 | 244:a966506d1e5b | 38 | case BLE_GATTC_EVT_CHAR_DISC_RSP: |
rgrover1 | 244:a966506d1e5b | 39 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
rgrover1 | 244:a966506d1e5b | 40 | case BLE_GATT_STATUS_SUCCESS: |
rgrover1 | 279:26e3f0ef1e14 | 41 | sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp); |
rgrover1 | 244:a966506d1e5b | 42 | break; |
rgrover1 | 244:a966506d1e5b | 43 | |
rgrover1 | 244:a966506d1e5b | 44 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
rgrover1 | 244:a966506d1e5b | 45 | default: |
rgrover1 | 279:26e3f0ef1e14 | 46 | sdSingleton.terminateCharacteristicDiscovery(); |
rgrover1 | 244:a966506d1e5b | 47 | break; |
rgrover1 | 244:a966506d1e5b | 48 | } |
rgrover1 | 244:a966506d1e5b | 49 | break; |
rgrover1 | 314:d579d093f23f | 50 | |
rgrover1 | 314:d579d093f23f | 51 | case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: |
rgrover1 | 291:83c994bf62d0 | 52 | if (sdSingleton.isActive()) { |
rgrover1 | 291:83c994bf62d0 | 53 | sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp); |
rgrover1 | 291:83c994bf62d0 | 54 | } |
rgrover1 | 291:83c994bf62d0 | 55 | break; |
rgrover1 | 320:cf62d065e70a | 56 | |
rgrover1 | 320:cf62d065e70a | 57 | case BLE_GATTC_EVT_READ_RSP: |
rgrover1 | 320:cf62d065e70a | 58 | if (DiscoveredCharacteristic::onDataReadCallback != NULL) { |
rgrover1 | 320:cf62d065e70a | 59 | DiscoveredCharacteristic::ReadResponse_t response = { |
rgrover1 | 320:cf62d065e70a | 60 | .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle, |
rgrover1 | 320:cf62d065e70a | 61 | .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset, |
rgrover1 | 320:cf62d065e70a | 62 | .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, |
rgrover1 | 320:cf62d065e70a | 63 | .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, |
rgrover1 | 320:cf62d065e70a | 64 | }; |
rgrover1 | 320:cf62d065e70a | 65 | DiscoveredCharacteristic::onDataReadCallback(&response); |
rgrover1 | 320:cf62d065e70a | 66 | } |
rgrover1 | 320:cf62d065e70a | 67 | break; |
rgrover1 | 244:a966506d1e5b | 68 | } |
rgrover1 | 244:a966506d1e5b | 69 | |
rgrover1 | 279:26e3f0ef1e14 | 70 | sdSingleton.progressCharacteristicDiscovery(); |
rgrover1 | 279:26e3f0ef1e14 | 71 | sdSingleton.progressServiceDiscovery(); |
rgrover1 | 333:b054000833d4 | 72 | } |