nordic
Fork of nRF51822 by
source/btle/btle_discovery.cpp@373:758e9a3a346a, 2015-07-06 (annotated)
- Committer:
- rgrover1
- Date:
- Mon Jul 06 10:21:00 2015 +0100
- Revision:
- 373:758e9a3a346a
- Parent:
- btle/btle_discovery.cpp@345:2a44e5fd26bc
Synchronized with git rev 488e2462
Author: James Crosby
restructure to yotta module, with a few tweaks to get things building
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 345:2a44e5fd26bc | 1 | /* mbed Microcontroller Library |
rgrover1 | 345:2a44e5fd26bc | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 345:2a44e5fd26bc | 3 | * |
rgrover1 | 345:2a44e5fd26bc | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 345:2a44e5fd26bc | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 345:2a44e5fd26bc | 6 | * You may obtain a copy of the License at |
rgrover1 | 345:2a44e5fd26bc | 7 | * |
rgrover1 | 345:2a44e5fd26bc | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 345:2a44e5fd26bc | 9 | * |
rgrover1 | 345:2a44e5fd26bc | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 345:2a44e5fd26bc | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 345:2a44e5fd26bc | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 345:2a44e5fd26bc | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 345:2a44e5fd26bc | 14 | * limitations under the License. |
rgrover1 | 345:2a44e5fd26bc | 15 | */ |
rgrover1 | 345:2a44e5fd26bc | 16 | |
rgrover1 | 345:2a44e5fd26bc | 17 | #include "nRF51ServiceDiscovery.h" |
rgrover1 | 345:2a44e5fd26bc | 18 | #include "nRF51GattClient.h" |
rgrover1 | 345:2a44e5fd26bc | 19 | |
rgrover1 | 345:2a44e5fd26bc | 20 | void bleGattcEventHandler(const ble_evt_t *p_ble_evt) |
rgrover1 | 345:2a44e5fd26bc | 21 | { |
rgrover1 | 345:2a44e5fd26bc | 22 | nRF51ServiceDiscovery &sdSingleton = nRF51GattClient::getInstance().discovery; |
rgrover1 | 345:2a44e5fd26bc | 23 | |
rgrover1 | 345:2a44e5fd26bc | 24 | switch (p_ble_evt->header.evt_id) { |
rgrover1 | 345:2a44e5fd26bc | 25 | case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: |
rgrover1 | 345:2a44e5fd26bc | 26 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
rgrover1 | 345:2a44e5fd26bc | 27 | case BLE_GATT_STATUS_SUCCESS: |
rgrover1 | 345:2a44e5fd26bc | 28 | sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp); |
rgrover1 | 345:2a44e5fd26bc | 29 | break; |
rgrover1 | 345:2a44e5fd26bc | 30 | |
rgrover1 | 345:2a44e5fd26bc | 31 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
rgrover1 | 345:2a44e5fd26bc | 32 | default: |
rgrover1 | 345:2a44e5fd26bc | 33 | sdSingleton.terminate(); |
rgrover1 | 345:2a44e5fd26bc | 34 | break; |
rgrover1 | 345:2a44e5fd26bc | 35 | } |
rgrover1 | 345:2a44e5fd26bc | 36 | break; |
rgrover1 | 345:2a44e5fd26bc | 37 | |
rgrover1 | 345:2a44e5fd26bc | 38 | case BLE_GATTC_EVT_CHAR_DISC_RSP: |
rgrover1 | 345:2a44e5fd26bc | 39 | switch (p_ble_evt->evt.gattc_evt.gatt_status) { |
rgrover1 | 345:2a44e5fd26bc | 40 | case BLE_GATT_STATUS_SUCCESS: |
rgrover1 | 345:2a44e5fd26bc | 41 | sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp); |
rgrover1 | 345:2a44e5fd26bc | 42 | break; |
rgrover1 | 345:2a44e5fd26bc | 43 | |
rgrover1 | 345:2a44e5fd26bc | 44 | case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND: |
rgrover1 | 345:2a44e5fd26bc | 45 | default: |
rgrover1 | 345:2a44e5fd26bc | 46 | sdSingleton.terminateCharacteristicDiscovery(); |
rgrover1 | 345:2a44e5fd26bc | 47 | break; |
rgrover1 | 345:2a44e5fd26bc | 48 | } |
rgrover1 | 345:2a44e5fd26bc | 49 | break; |
rgrover1 | 345:2a44e5fd26bc | 50 | |
rgrover1 | 345:2a44e5fd26bc | 51 | case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP: |
rgrover1 | 345:2a44e5fd26bc | 52 | if (sdSingleton.isActive()) { |
rgrover1 | 345:2a44e5fd26bc | 53 | sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp); |
rgrover1 | 345:2a44e5fd26bc | 54 | } |
rgrover1 | 345:2a44e5fd26bc | 55 | break; |
rgrover1 | 345:2a44e5fd26bc | 56 | |
rgrover1 | 345:2a44e5fd26bc | 57 | case BLE_GATTC_EVT_READ_RSP: |
rgrover1 | 345:2a44e5fd26bc | 58 | if (DiscoveredCharacteristic::onDataReadCallback != NULL) { |
rgrover1 | 345:2a44e5fd26bc | 59 | GattReadCallbackParams response = { |
rgrover1 | 345:2a44e5fd26bc | 60 | .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle, |
rgrover1 | 345:2a44e5fd26bc | 61 | .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset, |
rgrover1 | 345:2a44e5fd26bc | 62 | .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len, |
rgrover1 | 345:2a44e5fd26bc | 63 | .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data, |
rgrover1 | 345:2a44e5fd26bc | 64 | }; |
rgrover1 | 345:2a44e5fd26bc | 65 | DiscoveredCharacteristic::onDataReadCallback(&response); |
rgrover1 | 345:2a44e5fd26bc | 66 | } |
rgrover1 | 345:2a44e5fd26bc | 67 | break; |
rgrover1 | 345:2a44e5fd26bc | 68 | |
rgrover1 | 345:2a44e5fd26bc | 69 | case BLE_GATTC_EVT_WRITE_RSP: |
rgrover1 | 345:2a44e5fd26bc | 70 | if (DiscoveredCharacteristic::onDataWriteCallback != NULL) { |
rgrover1 | 345:2a44e5fd26bc | 71 | GattWriteCallbackParams response = { |
rgrover1 | 345:2a44e5fd26bc | 72 | .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle, |
rgrover1 | 345:2a44e5fd26bc | 73 | .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op), |
rgrover1 | 345:2a44e5fd26bc | 74 | .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset, |
rgrover1 | 345:2a44e5fd26bc | 75 | .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len, |
rgrover1 | 345:2a44e5fd26bc | 76 | .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data, |
rgrover1 | 345:2a44e5fd26bc | 77 | }; |
rgrover1 | 345:2a44e5fd26bc | 78 | DiscoveredCharacteristic::onDataWriteCallback(&response); |
rgrover1 | 345:2a44e5fd26bc | 79 | } |
rgrover1 | 345:2a44e5fd26bc | 80 | break; |
rgrover1 | 345:2a44e5fd26bc | 81 | } |
rgrover1 | 345:2a44e5fd26bc | 82 | |
rgrover1 | 345:2a44e5fd26bc | 83 | sdSingleton.progressCharacteristicDiscovery(); |
rgrover1 | 345:2a44e5fd26bc | 84 | sdSingleton.progressServiceDiscovery(); |
rgrover1 | 345:2a44e5fd26bc | 85 | } |