nordic

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Mon Jul 06 10:21:03 2015 +0100
Revision:
382:c997e9717fb7
Parent:
btle/btle_discovery.cpp@378:808617124695
Child:
385:8a1747598ac2
Synchronized with git rev 094e94b9
Author: Rohit Grover
Merge branch 'master' of https://github.com/autopulated/nRF51822 into autopulated-master

Who changed what in which revision?

UserRevisionLine numberNew 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 378:808617124695 57 case BLE_GATTC_EVT_READ_RSP: {
rgrover1 345:2a44e5fd26bc 58 GattReadCallbackParams response = {
rgrover1 345:2a44e5fd26bc 59 .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
rgrover1 345:2a44e5fd26bc 60 .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
rgrover1 345:2a44e5fd26bc 61 .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
rgrover1 345:2a44e5fd26bc 62 .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
rgrover1 345:2a44e5fd26bc 63 };
rgrover1 378:808617124695 64 nRF51GattClient::getInstance().processReadResponse(&response);
rgrover1 345:2a44e5fd26bc 65 }
rgrover1 345:2a44e5fd26bc 66 break;
rgrover1 345:2a44e5fd26bc 67
rgrover1 378:808617124695 68 case BLE_GATTC_EVT_WRITE_RSP: {
rgrover1 345:2a44e5fd26bc 69 GattWriteCallbackParams response = {
rgrover1 345:2a44e5fd26bc 70 .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
rgrover1 345:2a44e5fd26bc 71 .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
rgrover1 345:2a44e5fd26bc 72 .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
rgrover1 345:2a44e5fd26bc 73 .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
rgrover1 345:2a44e5fd26bc 74 .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
rgrover1 345:2a44e5fd26bc 75 };
rgrover1 378:808617124695 76 nRF51GattClient::getInstance().processWriteResponse(&response);
rgrover1 345:2a44e5fd26bc 77 }
rgrover1 345:2a44e5fd26bc 78 break;
rgrover1 345:2a44e5fd26bc 79 }
rgrover1 345:2a44e5fd26bc 80
rgrover1 345:2a44e5fd26bc 81 sdSingleton.progressCharacteristicDiscovery();
rgrover1 345:2a44e5fd26bc 82 sdSingleton.progressServiceDiscovery();
rgrover1 345:2a44e5fd26bc 83 }