nordic

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Fri Jun 19 15:55:33 2015 +0100
Revision:
340:e5e2157e8b44
Parent:
338:3d8b3bfe22e1
Synchronized with git rev d3889dfb
Author: Rohit Grover
rename nRF* to nRF51*

Who changed what in which revision?

UserRevisionLine numberNew 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 340:e5e2157e8b44 17 #include "nRF51ServiceDiscovery.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 340:e5e2157e8b44 22 nRF51ServiceDiscovery &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 337:6ac9e1b34de0 59 GattReadCallbackParams response = {
rgrover1 337:6ac9e1b34de0 60 .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
rgrover1 337:6ac9e1b34de0 61 .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
rgrover1 337:6ac9e1b34de0 62 .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
rgrover1 337:6ac9e1b34de0 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 338:3d8b3bfe22e1 68
rgrover1 338:3d8b3bfe22e1 69 case BLE_GATTC_EVT_WRITE_RSP:
rgrover1 338:3d8b3bfe22e1 70 if (DiscoveredCharacteristic::onDataWriteCallback != NULL) {
rgrover1 338:3d8b3bfe22e1 71 GattWriteCallbackParams response = {
rgrover1 338:3d8b3bfe22e1 72 .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
rgrover1 338:3d8b3bfe22e1 73 .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
rgrover1 338:3d8b3bfe22e1 74 .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
rgrover1 338:3d8b3bfe22e1 75 .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
rgrover1 338:3d8b3bfe22e1 76 .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
rgrover1 338:3d8b3bfe22e1 77 };
rgrover1 338:3d8b3bfe22e1 78 DiscoveredCharacteristic::onDataWriteCallback(&response);
rgrover1 338:3d8b3bfe22e1 79 }
rgrover1 338:3d8b3bfe22e1 80 break;
rgrover1 244:a966506d1e5b 81 }
rgrover1 244:a966506d1e5b 82
rgrover1 279:26e3f0ef1e14 83 sdSingleton.progressCharacteristicDiscovery();
rgrover1 279:26e3f0ef1e14 84 sdSingleton.progressServiceDiscovery();
rgrover1 333:b054000833d4 85 }