Shuta Nakamae / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:19 2016 +0000
Revision:
567:e1800bd55a9e
Parent:
563:9c4b96f7be8d
Child:
568:13b23a4b1f58
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 563:9c4b96f7be8d 1 /* mbed Microcontroller Library
vcoubard 563:9c4b96f7be8d 2 * Copyright (c) 2006-2015 ARM Limited
vcoubard 563:9c4b96f7be8d 3 *
vcoubard 563:9c4b96f7be8d 4 * Licensed under the Apache License, Version 2.0 (the "License");
vcoubard 563:9c4b96f7be8d 5 * you may not use this file except in compliance with the License.
vcoubard 563:9c4b96f7be8d 6 * You may obtain a copy of the License at
vcoubard 563:9c4b96f7be8d 7 *
vcoubard 563:9c4b96f7be8d 8 * http://www.apache.org/licenses/LICENSE-2.0
vcoubard 563:9c4b96f7be8d 9 *
vcoubard 563:9c4b96f7be8d 10 * Unless required by applicable law or agreed to in writing, software
vcoubard 563:9c4b96f7be8d 11 * distributed under the License is distributed on an "AS IS" BASIS,
vcoubard 563:9c4b96f7be8d 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
vcoubard 563:9c4b96f7be8d 13 * See the License for the specific language governing permissions and
vcoubard 563:9c4b96f7be8d 14 * limitations under the License.
vcoubard 563:9c4b96f7be8d 15 */
vcoubard 563:9c4b96f7be8d 16
vcoubard 563:9c4b96f7be8d 17 #ifndef __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__
vcoubard 563:9c4b96f7be8d 18 #define __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__
vcoubard 563:9c4b96f7be8d 19
vcoubard 563:9c4b96f7be8d 20 #include "ble/Gap.h"
vcoubard 563:9c4b96f7be8d 21 #include "ble/DiscoveredCharacteristic.h"
vcoubard 563:9c4b96f7be8d 22 #include "ble/CharacteristicDescriptorDiscovery.h"
vcoubard 563:9c4b96f7be8d 23 #include "ble/GattClient.h"
vcoubard 563:9c4b96f7be8d 24 #include "ble_gattc.h"
vcoubard 563:9c4b96f7be8d 25
vcoubard 563:9c4b96f7be8d 26 /**
vcoubard 563:9c4b96f7be8d 27 * @brief Manage the discovery of Characteristic descriptors
vcoubard 563:9c4b96f7be8d 28 * @details is a bridge beetween BLE API and nordic stack regarding Characteristic
vcoubard 563:9c4b96f7be8d 29 * Descriptor discovery. The BLE API can launch, monitorate and ask for termination
vcoubard 563:9c4b96f7be8d 30 * of a discovery. The nordic stack will provide new descriptors and indicate when
vcoubard 563:9c4b96f7be8d 31 * the discovery is done
vcoubard 563:9c4b96f7be8d 32 */
vcoubard 563:9c4b96f7be8d 33 class nRF5xCharacteristicDescriptorDiscoverer
vcoubard 563:9c4b96f7be8d 34 {
vcoubard 563:9c4b96f7be8d 35 typedef CharacteristicDescriptorDiscovery::DiscoveryCallback_t DiscoveryCallback_t;
vcoubard 563:9c4b96f7be8d 36 typedef CharacteristicDescriptorDiscovery::TerminationCallback_t TerminationCallback_t;
vcoubard 563:9c4b96f7be8d 37
vcoubard 563:9c4b96f7be8d 38 public:
vcoubard 563:9c4b96f7be8d 39 nRF5xCharacteristicDescriptorDiscoverer(size_t concurrentConnectionsCount = 3);
vcoubard 563:9c4b96f7be8d 40
vcoubard 563:9c4b96f7be8d 41 ~nRF5xCharacteristicDescriptorDiscoverer();
vcoubard 563:9c4b96f7be8d 42
vcoubard 563:9c4b96f7be8d 43 /**
vcoubard 563:9c4b96f7be8d 44 * Launch a new characteristic descriptor discovery for a given
vcoubard 563:9c4b96f7be8d 45 * DiscoveredCharacteristic.
vcoubard 563:9c4b96f7be8d 46 * @note: this will be called by BLE API side
vcoubard 563:9c4b96f7be8d 47 */
vcoubard 563:9c4b96f7be8d 48 ble_error_t launch(
vcoubard 563:9c4b96f7be8d 49 const DiscoveredCharacteristic& characteristic,
vcoubard 563:9c4b96f7be8d 50 const DiscoveryCallback_t& callback,
vcoubard 563:9c4b96f7be8d 51 const TerminationCallback_t& terminationCallback
vcoubard 563:9c4b96f7be8d 52 );
vcoubard 563:9c4b96f7be8d 53
vcoubard 563:9c4b96f7be8d 54 /**
vcoubard 563:9c4b96f7be8d 55 * @brief indicate if a characteristic descriptor discovery is active for a
vcoubard 563:9c4b96f7be8d 56 * given DiscoveredCharacteristic
vcoubard 563:9c4b96f7be8d 57 * @note: this will be called by BLE API side
vcoubard 563:9c4b96f7be8d 58 */
vcoubard 563:9c4b96f7be8d 59 bool isActive(const DiscoveredCharacteristic& characteristic) const;
vcoubard 563:9c4b96f7be8d 60
vcoubard 563:9c4b96f7be8d 61 /**
vcoubard 563:9c4b96f7be8d 62 * @brief reauest the termination of characteristic descriptor discovery
vcoubard 563:9c4b96f7be8d 63 * for a give DiscoveredCharacteristic
vcoubard 563:9c4b96f7be8d 64 * @note: this will be called by BLE API side
vcoubard 563:9c4b96f7be8d 65 */
vcoubard 563:9c4b96f7be8d 66 void requestTerminate(const DiscoveredCharacteristic& characteristic);
vcoubard 563:9c4b96f7be8d 67
vcoubard 563:9c4b96f7be8d 68 /**
vcoubard 563:9c4b96f7be8d 69 * @brief process descriptors discovered from the nordic stack
vcoubard 563:9c4b96f7be8d 70 */
vcoubard 563:9c4b96f7be8d 71 void process(uint16_t handle, const ble_gattc_evt_desc_disc_rsp_t& descriptors);
vcoubard 563:9c4b96f7be8d 72
vcoubard 563:9c4b96f7be8d 73 /**
vcoubard 563:9c4b96f7be8d 74 * @brief Called by the nordic stack when the discovery is over.
vcoubard 563:9c4b96f7be8d 75 */
vcoubard 563:9c4b96f7be8d 76 void terminate(uint16_t handle, ble_error_t err);
vcoubard 563:9c4b96f7be8d 77
vcoubard 563:9c4b96f7be8d 78 private:
vcoubard 563:9c4b96f7be8d 79 nRF5xCharacteristicDescriptorDiscoverer(const nRF5xCharacteristicDescriptorDiscoverer&);
vcoubard 563:9c4b96f7be8d 80 nRF5xCharacteristicDescriptorDiscoverer& operator=(const nRF5xCharacteristicDescriptorDiscoverer&);
vcoubard 563:9c4b96f7be8d 81
vcoubard 563:9c4b96f7be8d 82 struct Discovery {
vcoubard 563:9c4b96f7be8d 83 Discovery() : characteristic(), onDiscovery(), onTerminate() { }
vcoubard 563:9c4b96f7be8d 84
vcoubard 563:9c4b96f7be8d 85 Discovery(const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) :
vcoubard 563:9c4b96f7be8d 86 characteristic(c),
vcoubard 563:9c4b96f7be8d 87 onDiscovery(dCb),
vcoubard 563:9c4b96f7be8d 88 onTerminate(tCb) {
vcoubard 563:9c4b96f7be8d 89 }
vcoubard 563:9c4b96f7be8d 90
vcoubard 563:9c4b96f7be8d 91 DiscoveredCharacteristic characteristic;
vcoubard 563:9c4b96f7be8d 92 DiscoveryCallback_t onDiscovery;
vcoubard 563:9c4b96f7be8d 93 TerminationCallback_t onTerminate;
vcoubard 563:9c4b96f7be8d 94
vcoubard 563:9c4b96f7be8d 95 void process(GattAttribute::Handle_t handle, const UUID& uuid) {
vcoubard 563:9c4b96f7be8d 96 CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
vcoubard 563:9c4b96f7be8d 97 characteristic,
vcoubard 563:9c4b96f7be8d 98 DiscoveredCharacteristicDescriptor(
vcoubard 563:9c4b96f7be8d 99 characteristic.getGattClient(),
vcoubard 563:9c4b96f7be8d 100 characteristic.getConnectionHandle(),
vcoubard 563:9c4b96f7be8d 101 handle,
vcoubard 563:9c4b96f7be8d 102 uuid
vcoubard 563:9c4b96f7be8d 103 )
vcoubard 563:9c4b96f7be8d 104 };
vcoubard 563:9c4b96f7be8d 105 onDiscovery.call(&params);
vcoubard 563:9c4b96f7be8d 106 }
vcoubard 563:9c4b96f7be8d 107
vcoubard 563:9c4b96f7be8d 108 void terminate(ble_error_t err) {
vcoubard 563:9c4b96f7be8d 109 CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
vcoubard 563:9c4b96f7be8d 110 characteristic,
vcoubard 563:9c4b96f7be8d 111 err
vcoubard 563:9c4b96f7be8d 112 };
vcoubard 563:9c4b96f7be8d 113 onTerminate.call(&params);
vcoubard 563:9c4b96f7be8d 114 }
vcoubard 563:9c4b96f7be8d 115
vcoubard 563:9c4b96f7be8d 116 friend bool operator==(const Discovery& lhs, const Discovery& rhs) {
vcoubard 563:9c4b96f7be8d 117 return lhs.characteristic == rhs.characteristic &&
vcoubard 563:9c4b96f7be8d 118 lhs.onDiscovery == rhs.onDiscovery &&
vcoubard 563:9c4b96f7be8d 119 lhs.onTerminate == rhs.onTerminate;
vcoubard 563:9c4b96f7be8d 120 }
vcoubard 563:9c4b96f7be8d 121
vcoubard 563:9c4b96f7be8d 122 friend bool operator!=(const Discovery& lhs, const Discovery& rhs) {
vcoubard 563:9c4b96f7be8d 123 return !(lhs == rhs);
vcoubard 563:9c4b96f7be8d 124 }
vcoubard 563:9c4b96f7be8d 125 };
vcoubard 563:9c4b96f7be8d 126
vcoubard 563:9c4b96f7be8d 127 Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic);
vcoubard 563:9c4b96f7be8d 128 Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic) const;
vcoubard 563:9c4b96f7be8d 129 Discovery* findRunningDiscovery(uint16_t handle);
vcoubard 563:9c4b96f7be8d 130 void removeDiscovery(Discovery* discovery);
vcoubard 563:9c4b96f7be8d 131 Discovery* getAvailableDiscoverySlot();
vcoubard 563:9c4b96f7be8d 132 bool isConnectionInUse(uint16_t connHandle);
vcoubard 563:9c4b96f7be8d 133 static ble_error_t gattc_descriptors_discover(uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle);
vcoubard 563:9c4b96f7be8d 134
vcoubard 563:9c4b96f7be8d 135
vcoubard 563:9c4b96f7be8d 136 size_t maximumConcurrentConnectionsCount;
vcoubard 563:9c4b96f7be8d 137 Discovery *discoveryRunning;
vcoubard 563:9c4b96f7be8d 138 };
vcoubard 563:9c4b96f7be8d 139
vcoubard 563:9c4b96f7be8d 140 #endif /*__NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__*/