Nordic stack and drivers for the mbed BLE API. Version to work around build bug.

Dependents:   microbit_rubber_ducky microbit_mouse_BLE microbit_mouse_BLE_daybreak_version microbit_presenter

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:19 2016 +0000
Revision:
567:e1800bd55a9e
Parent:
566:e425ad9e5d6e
Child:
570:f162898cb6c4
Synchronized with git rev 59ced0b4
Author: Vincent Coubard
rename remainingCharacteristic member, now it is named
discoveredCharacteristic. Add doc to the discovery process and the
rationale behind discoveredCharacteristic member.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 542:1bf9c597f44f 1 /* mbed Microcontroller Library
vcoubard 542:1bf9c597f44f 2 * Copyright (c) 2006-2013 ARM Limited
vcoubard 542:1bf9c597f44f 3 *
vcoubard 542:1bf9c597f44f 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 542:1bf9c597f44f 5 * you may not use this file except in compliance with the License.
vcoubard 542:1bf9c597f44f 6 * You may obtain a copy of the License at
vcoubard 542:1bf9c597f44f 7 *
vcoubard 542:1bf9c597f44f 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 542:1bf9c597f44f 9 *
vcoubard 542:1bf9c597f44f 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 542:1bf9c597f44f 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 542:1bf9c597f44f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 542:1bf9c597f44f 13 * See the License for the specific language governing permissions and
vcoubard 542:1bf9c597f44f 14 * limitations under the License.
vcoubard 542:1bf9c597f44f 15 */
vcoubard 542:1bf9c597f44f 16
vcoubard 566:e425ad9e5d6e 17 #include "nRF5xServiceDiscovery.h"
vcoubard 567:e1800bd55a9e 18 #include "nRF5xCharacteristicDescriptorDiscoverer.h"
vcoubard 566:e425ad9e5d6e 19 #include "nRF5xGattClient.h"
vcoubard 542:1bf9c597f44f 20
vcoubard 542:1bf9c597f44f 21 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
vcoubard 542:1bf9c597f44f 22 void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
vcoubard 542:1bf9c597f44f 23 {
vcoubard 567:e1800bd55a9e 24 nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery();
vcoubard 567:e1800bd55a9e 25 nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer =
vcoubard 567:e1800bd55a9e 26 nRF5xGattClient::getInstance().characteristicDescriptorDiscoverer();
vcoubard 542:1bf9c597f44f 27
vcoubard 542:1bf9c597f44f 28 switch (p_ble_evt->header.evt_id) {
vcoubard 542:1bf9c597f44f 29 case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
vcoubard 542:1bf9c597f44f 30 switch (p_ble_evt->evt.gattc_evt.gatt_status) {
vcoubard 542:1bf9c597f44f 31 case BLE_GATT_STATUS_SUCCESS:
vcoubard 542:1bf9c597f44f 32 sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp);
vcoubard 542:1bf9c597f44f 33 break;
vcoubard 542:1bf9c597f44f 34
vcoubard 542:1bf9c597f44f 35 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
vcoubard 542:1bf9c597f44f 36 default:
vcoubard 542:1bf9c597f44f 37 sdSingleton.terminate();
vcoubard 542:1bf9c597f44f 38 break;
vcoubard 542:1bf9c597f44f 39 }
vcoubard 542:1bf9c597f44f 40 break;
vcoubard 542:1bf9c597f44f 41
vcoubard 542:1bf9c597f44f 42 case BLE_GATTC_EVT_CHAR_DISC_RSP:
vcoubard 542:1bf9c597f44f 43 switch (p_ble_evt->evt.gattc_evt.gatt_status) {
vcoubard 542:1bf9c597f44f 44 case BLE_GATT_STATUS_SUCCESS:
vcoubard 542:1bf9c597f44f 45 sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
vcoubard 542:1bf9c597f44f 46 break;
vcoubard 542:1bf9c597f44f 47
vcoubard 542:1bf9c597f44f 48 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
vcoubard 542:1bf9c597f44f 49 default:
vcoubard 567:e1800bd55a9e 50 sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE);
vcoubard 542:1bf9c597f44f 51 break;
vcoubard 542:1bf9c597f44f 52 }
vcoubard 542:1bf9c597f44f 53 break;
vcoubard 542:1bf9c597f44f 54
vcoubard 542:1bf9c597f44f 55 case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
vcoubard 542:1bf9c597f44f 56 if (sdSingleton.isActive()) {
vcoubard 542:1bf9c597f44f 57 sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp);
vcoubard 542:1bf9c597f44f 58 }
vcoubard 542:1bf9c597f44f 59 break;
vcoubard 542:1bf9c597f44f 60
vcoubard 542:1bf9c597f44f 61 case BLE_GATTC_EVT_READ_RSP: {
vcoubard 542:1bf9c597f44f 62 GattReadCallbackParams response = {
vcoubard 542:1bf9c597f44f 63 .connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
vcoubard 542:1bf9c597f44f 64 .handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
vcoubard 542:1bf9c597f44f 65 .offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
vcoubard 542:1bf9c597f44f 66 .len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
vcoubard 542:1bf9c597f44f 67 .data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
vcoubard 542:1bf9c597f44f 68 };
vcoubard 566:e425ad9e5d6e 69 nRF5xGattClient::getInstance().processReadResponse(&response);
vcoubard 542:1bf9c597f44f 70 }
vcoubard 542:1bf9c597f44f 71 break;
vcoubard 542:1bf9c597f44f 72
vcoubard 542:1bf9c597f44f 73 case BLE_GATTC_EVT_WRITE_RSP: {
vcoubard 542:1bf9c597f44f 74 GattWriteCallbackParams response = {
vcoubard 542:1bf9c597f44f 75 .connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
vcoubard 542:1bf9c597f44f 76 .handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
vcoubard 542:1bf9c597f44f 77 .writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
vcoubard 542:1bf9c597f44f 78 .offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
vcoubard 542:1bf9c597f44f 79 .len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
vcoubard 542:1bf9c597f44f 80 .data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
vcoubard 542:1bf9c597f44f 81 };
vcoubard 566:e425ad9e5d6e 82 nRF5xGattClient::getInstance().processWriteResponse(&response);
vcoubard 542:1bf9c597f44f 83 }
vcoubard 542:1bf9c597f44f 84 break;
vcoubard 542:1bf9c597f44f 85
vcoubard 542:1bf9c597f44f 86 case BLE_GATTC_EVT_HVX: {
vcoubard 542:1bf9c597f44f 87 GattHVXCallbackParams params;
vcoubard 542:1bf9c597f44f 88 params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle;
vcoubard 542:1bf9c597f44f 89 params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
vcoubard 542:1bf9c597f44f 90 params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
vcoubard 542:1bf9c597f44f 91 params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
vcoubard 542:1bf9c597f44f 92 params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
vcoubard 542:1bf9c597f44f 93
vcoubard 566:e425ad9e5d6e 94 nRF5xGattClient::getInstance().processHVXEvent(&params);
vcoubard 542:1bf9c597f44f 95 }
vcoubard 542:1bf9c597f44f 96 break;
vcoubard 567:e1800bd55a9e 97
vcoubard 567:e1800bd55a9e 98 case BLE_GATTC_EVT_DESC_DISC_RSP: {
vcoubard 567:e1800bd55a9e 99 uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
vcoubard 567:e1800bd55a9e 100 uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status;
vcoubard 567:e1800bd55a9e 101 const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp;
vcoubard 567:e1800bd55a9e 102
vcoubard 567:e1800bd55a9e 103 switch(status) {
vcoubard 567:e1800bd55a9e 104 case BLE_GATT_STATUS_SUCCESS:
vcoubard 567:e1800bd55a9e 105 characteristicDescriptorDiscoverer.process(
vcoubard 567:e1800bd55a9e 106 conn_handle,
vcoubard 567:e1800bd55a9e 107 discovered_descriptors
vcoubard 567:e1800bd55a9e 108 );
vcoubard 567:e1800bd55a9e 109 break;
vcoubard 567:e1800bd55a9e 110 case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
vcoubard 567:e1800bd55a9e 111 // end of discovery
vcoubard 567:e1800bd55a9e 112 characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE);
vcoubard 567:e1800bd55a9e 113 break;
vcoubard 567:e1800bd55a9e 114 default:
vcoubard 567:e1800bd55a9e 115 characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED);
vcoubard 567:e1800bd55a9e 116 break;
vcoubard 567:e1800bd55a9e 117 }
vcoubard 567:e1800bd55a9e 118 } break;
vcoubard 542:1bf9c597f44f 119 }
vcoubard 542:1bf9c597f44f 120
vcoubard 542:1bf9c597f44f 121 sdSingleton.progressCharacteristicDiscovery();
vcoubard 542:1bf9c597f44f 122 sdSingleton.progressServiceDiscovery();
vcoubard 542:1bf9c597f44f 123 }
vcoubard 542:1bf9c597f44f 124 #endif