No changes
Fork of nRF51822 by
source/nRF5xn.h@590:3bdd5346ded1, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 10:19:31 2016 +0000
- Revision:
- 590:3bdd5346ded1
- Parent:
- 588:65d256258533
- Child:
- 591:266079a50c20
Synchronized with git rev 19d1c406
Author: Vincent Coubard
Merge branch 'develop' of https://github.com/ARMmbed/ble-nrf51822 into characteristicDescriptorDiscovery
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 565:cf03471a4ec4 | 1 | /* mbed Microcontroller Library |
vcoubard | 565:cf03471a4ec4 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 565:cf03471a4ec4 | 3 | * |
vcoubard | 565:cf03471a4ec4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 565:cf03471a4ec4 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 565:cf03471a4ec4 | 6 | * You may obtain a copy of the License at |
vcoubard | 565:cf03471a4ec4 | 7 | * |
vcoubard | 565:cf03471a4ec4 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 565:cf03471a4ec4 | 9 | * |
vcoubard | 565:cf03471a4ec4 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 565:cf03471a4ec4 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 565:cf03471a4ec4 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 565:cf03471a4ec4 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 565:cf03471a4ec4 | 14 | * limitations under the License. |
vcoubard | 565:cf03471a4ec4 | 15 | */ |
vcoubard | 565:cf03471a4ec4 | 16 | |
vcoubard | 565:cf03471a4ec4 | 17 | #ifndef __NRF51822_H__ |
vcoubard | 565:cf03471a4ec4 | 18 | #define __NRF51822_H__ |
vcoubard | 565:cf03471a4ec4 | 19 | |
vcoubard | 565:cf03471a4ec4 | 20 | #include "ble/BLE.h" |
vcoubard | 565:cf03471a4ec4 | 21 | #include "ble/blecommon.h" |
vcoubard | 565:cf03471a4ec4 | 22 | #include "ble/BLEInstanceBase.h" |
vcoubard | 565:cf03471a4ec4 | 23 | |
vcoubard | 565:cf03471a4ec4 | 24 | #include "nRF5xGap.h" |
vcoubard | 565:cf03471a4ec4 | 25 | #include "nRF5xGattServer.h" |
vcoubard | 565:cf03471a4ec4 | 26 | #include "nRF5xGattClient.h" |
vcoubard | 565:cf03471a4ec4 | 27 | #include "nRF5xSecurityManager.h" |
vcoubard | 565:cf03471a4ec4 | 28 | |
vcoubard | 565:cf03471a4ec4 | 29 | #include "btle.h" |
vcoubard | 565:cf03471a4ec4 | 30 | |
vcoubard | 565:cf03471a4ec4 | 31 | class nRF5xn : public BLEInstanceBase |
vcoubard | 565:cf03471a4ec4 | 32 | { |
vcoubard | 565:cf03471a4ec4 | 33 | public: |
vcoubard | 565:cf03471a4ec4 | 34 | nRF5xn(void); |
vcoubard | 565:cf03471a4ec4 | 35 | virtual ~nRF5xn(void); |
vcoubard | 565:cf03471a4ec4 | 36 | |
vcoubard | 565:cf03471a4ec4 | 37 | virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback); |
vcoubard | 565:cf03471a4ec4 | 38 | virtual bool hasInitialized(void) const { |
vcoubard | 565:cf03471a4ec4 | 39 | return initialized; |
vcoubard | 565:cf03471a4ec4 | 40 | } |
vcoubard | 565:cf03471a4ec4 | 41 | virtual ble_error_t shutdown(void); |
vcoubard | 565:cf03471a4ec4 | 42 | virtual const char *getVersion(void); |
vcoubard | 565:cf03471a4ec4 | 43 | |
vcoubard | 575:7023a8204a1b | 44 | /** |
vcoubard | 575:7023a8204a1b | 45 | * Accessors to GAP. This function checks whether gapInstance points to an |
vcoubard | 575:7023a8204a1b | 46 | * object. If if does not, then the gapInstance is updated to |
vcoubard | 575:7023a8204a1b | 47 | * &_getInstance before returning. |
vcoubard | 575:7023a8204a1b | 48 | * |
vcoubard | 575:7023a8204a1b | 49 | * @return A reference to GattServer. |
vcoubard | 575:7023a8204a1b | 50 | * |
vcoubard | 575:7023a8204a1b | 51 | * @note Unlike the GattClient, GattServer and SecurityManager, Gap is |
vcoubard | 575:7023a8204a1b | 52 | * always needed in a BLE application. Therefore it is allocated |
vcoubard | 575:7023a8204a1b | 53 | * statically. |
vcoubard | 575:7023a8204a1b | 54 | */ |
vcoubard | 565:cf03471a4ec4 | 55 | virtual Gap &getGap() { |
vcoubard | 588:65d256258533 | 56 | return gapInstance; |
vcoubard | 575:7023a8204a1b | 57 | }; |
vcoubard | 575:7023a8204a1b | 58 | |
vcoubard | 575:7023a8204a1b | 59 | /** |
vcoubard | 575:7023a8204a1b | 60 | * Accessors to GATT Server. This function checks whether a GattServer |
vcoubard | 575:7023a8204a1b | 61 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 575:7023a8204a1b | 62 | * it is created before returning. |
vcoubard | 575:7023a8204a1b | 63 | * |
vcoubard | 575:7023a8204a1b | 64 | * @return A reference to GattServer. |
vcoubard | 575:7023a8204a1b | 65 | */ |
vcoubard | 575:7023a8204a1b | 66 | virtual GattServer &getGattServer() { |
vcoubard | 575:7023a8204a1b | 67 | if (gattServerInstance == NULL) { |
vcoubard | 575:7023a8204a1b | 68 | gattServerInstance = new nRF5xGattServer(); |
vcoubard | 575:7023a8204a1b | 69 | } |
vcoubard | 575:7023a8204a1b | 70 | return *gattServerInstance; |
vcoubard | 570:f162898cb6c4 | 71 | }; |
vcoubard | 575:7023a8204a1b | 72 | |
vcoubard | 575:7023a8204a1b | 73 | /** |
vcoubard | 575:7023a8204a1b | 74 | * Accessors to GATT Client. This function checks whether a GattClient |
vcoubard | 575:7023a8204a1b | 75 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 575:7023a8204a1b | 76 | * it is created before returning. |
vcoubard | 575:7023a8204a1b | 77 | * |
vcoubard | 575:7023a8204a1b | 78 | * @return A reference to GattClient. |
vcoubard | 575:7023a8204a1b | 79 | */ |
vcoubard | 590:3bdd5346ded1 | 80 | virtual nRF5xGattClient &getGattClient() { |
vcoubard | 575:7023a8204a1b | 81 | if (gattClientInstance == NULL) { |
vcoubard | 575:7023a8204a1b | 82 | gattClientInstance = new nRF5xGattClient(); |
vcoubard | 575:7023a8204a1b | 83 | } |
vcoubard | 575:7023a8204a1b | 84 | return *gattClientInstance; |
vcoubard | 575:7023a8204a1b | 85 | } |
vcoubard | 575:7023a8204a1b | 86 | |
vcoubard | 575:7023a8204a1b | 87 | /** |
vcoubard | 575:7023a8204a1b | 88 | * Accessors to Security Manager. This function checks whether a SecurityManager |
vcoubard | 575:7023a8204a1b | 89 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 575:7023a8204a1b | 90 | * it is created before returning. |
vcoubard | 575:7023a8204a1b | 91 | * |
vcoubard | 575:7023a8204a1b | 92 | * @return A reference to GattServer. |
vcoubard | 575:7023a8204a1b | 93 | */ |
vcoubard | 590:3bdd5346ded1 | 94 | virtual nRF5xSecurityManager &getSecurityManager() { |
vcoubard | 575:7023a8204a1b | 95 | if (securityManagerInstance == NULL) { |
vcoubard | 575:7023a8204a1b | 96 | securityManagerInstance = new nRF5xSecurityManager(); |
vcoubard | 575:7023a8204a1b | 97 | } |
vcoubard | 575:7023a8204a1b | 98 | return *securityManagerInstance; |
vcoubard | 575:7023a8204a1b | 99 | } |
vcoubard | 575:7023a8204a1b | 100 | |
vcoubard | 575:7023a8204a1b | 101 | /** |
vcoubard | 575:7023a8204a1b | 102 | * Accessors to GAP. This function checks whether gapInstance points to an |
vcoubard | 575:7023a8204a1b | 103 | * object. If if does not, then the gapInstance is updated to |
vcoubard | 575:7023a8204a1b | 104 | * &_getInstance before returning. |
vcoubard | 575:7023a8204a1b | 105 | * |
vcoubard | 575:7023a8204a1b | 106 | * @return A const reference to GattServer. |
vcoubard | 575:7023a8204a1b | 107 | * |
vcoubard | 575:7023a8204a1b | 108 | * @note Unlike the GattClient, GattServer and SecurityManager, Gap is |
vcoubard | 575:7023a8204a1b | 109 | * always needed in a BLE application. Therefore it is allocated |
vcoubard | 575:7023a8204a1b | 110 | * statically. |
vcoubard | 575:7023a8204a1b | 111 | * |
vcoubard | 575:7023a8204a1b | 112 | * @note The accessor is able to modify the object's state because the |
vcoubard | 575:7023a8204a1b | 113 | * internal pointer has been declared mutable. |
vcoubard | 575:7023a8204a1b | 114 | */ |
vcoubard | 590:3bdd5346ded1 | 115 | virtual const nRF5xGap &getGap() const { |
vcoubard | 588:65d256258533 | 116 | return gapInstance; |
vcoubard | 571:bbf6410b6a89 | 117 | }; |
vcoubard | 575:7023a8204a1b | 118 | |
vcoubard | 575:7023a8204a1b | 119 | /** |
vcoubard | 575:7023a8204a1b | 120 | * Accessors to GATT Server. This function checks whether a GattServer |
vcoubard | 575:7023a8204a1b | 121 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 575:7023a8204a1b | 122 | * it is created before returning. |
vcoubard | 575:7023a8204a1b | 123 | * |
vcoubard | 575:7023a8204a1b | 124 | * @return A const reference to GattServer. |
vcoubard | 575:7023a8204a1b | 125 | * |
vcoubard | 575:7023a8204a1b | 126 | * @note The accessor is able to modify the object's state because the |
vcoubard | 575:7023a8204a1b | 127 | * internal pointer has been declared mutable. |
vcoubard | 575:7023a8204a1b | 128 | */ |
vcoubard | 590:3bdd5346ded1 | 129 | virtual const nRF5xGattServer &getGattServer() const { |
vcoubard | 575:7023a8204a1b | 130 | if (gattServerInstance == NULL) { |
vcoubard | 575:7023a8204a1b | 131 | gattServerInstance = new nRF5xGattServer(); |
vcoubard | 575:7023a8204a1b | 132 | } |
vcoubard | 575:7023a8204a1b | 133 | return *gattServerInstance; |
vcoubard | 571:bbf6410b6a89 | 134 | }; |
vcoubard | 575:7023a8204a1b | 135 | |
vcoubard | 575:7023a8204a1b | 136 | /** |
vcoubard | 575:7023a8204a1b | 137 | * Accessors to Security Manager. This function checks whether a SecurityManager |
vcoubard | 575:7023a8204a1b | 138 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 575:7023a8204a1b | 139 | * it is created before returning. |
vcoubard | 575:7023a8204a1b | 140 | * |
vcoubard | 575:7023a8204a1b | 141 | * @return A const reference to GattServer. |
vcoubard | 575:7023a8204a1b | 142 | * |
vcoubard | 575:7023a8204a1b | 143 | * @note The accessor is able to modify the object's state because the |
vcoubard | 575:7023a8204a1b | 144 | * internal pointer has been declared mutable. |
vcoubard | 575:7023a8204a1b | 145 | */ |
vcoubard | 590:3bdd5346ded1 | 146 | virtual const nRF5xSecurityManager &getSecurityManager() const { |
vcoubard | 575:7023a8204a1b | 147 | if (securityManagerInstance == NULL) { |
vcoubard | 575:7023a8204a1b | 148 | securityManagerInstance = new nRF5xSecurityManager(); |
vcoubard | 575:7023a8204a1b | 149 | } |
vcoubard | 575:7023a8204a1b | 150 | return *securityManagerInstance; |
vcoubard | 565:cf03471a4ec4 | 151 | } |
vcoubard | 575:7023a8204a1b | 152 | |
vcoubard | 565:cf03471a4ec4 | 153 | virtual void waitForEvent(void); |
vcoubard | 565:cf03471a4ec4 | 154 | |
vcoubard | 575:7023a8204a1b | 155 | public: |
vcoubard | 575:7023a8204a1b | 156 | static nRF5xn& Instance(BLE::InstanceID_t instanceId); |
vcoubard | 575:7023a8204a1b | 157 | |
vcoubard | 565:cf03471a4ec4 | 158 | private: |
vcoubard | 565:cf03471a4ec4 | 159 | bool initialized; |
vcoubard | 565:cf03471a4ec4 | 160 | BLE::InstanceID_t instanceID; |
vcoubard | 575:7023a8204a1b | 161 | |
vcoubard | 575:7023a8204a1b | 162 | private: |
vcoubard | 588:65d256258533 | 163 | mutable nRF5xGap gapInstance; /**< Gap instance whose reference is returned from a call to |
vcoubard | 588:65d256258533 | 164 | * getGap(). Unlike the GattClient, GattServer and |
vcoubard | 588:65d256258533 | 165 | * SecurityManager, Gap is always needed in a BLE application. */ |
vcoubard | 575:7023a8204a1b | 166 | |
vcoubard | 575:7023a8204a1b | 167 | private: |
vcoubard | 575:7023a8204a1b | 168 | mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance. |
vcoubard | 575:7023a8204a1b | 169 | * If NULL, then GattServer has not been initialized. |
vcoubard | 575:7023a8204a1b | 170 | * The pointer has been declared as 'mutable' so that |
vcoubard | 575:7023a8204a1b | 171 | * it can be assigned inside a 'const' function. */ |
vcoubard | 575:7023a8204a1b | 172 | mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance. |
vcoubard | 575:7023a8204a1b | 173 | * If NULL, then GattClient has not been initialized. |
vcoubard | 575:7023a8204a1b | 174 | * The pointer has been declared as 'mutable' so that |
vcoubard | 575:7023a8204a1b | 175 | * it can be assigned inside a 'const' function. */ |
vcoubard | 575:7023a8204a1b | 176 | mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance. |
vcoubard | 575:7023a8204a1b | 177 | * If NULL, then SecurityManager has not been initialized. |
vcoubard | 575:7023a8204a1b | 178 | * The pointer has been declared as 'mutable' so that |
vcoubard | 575:7023a8204a1b | 179 | * it can be assigned inside a 'const' function. */ |
vcoubard | 565:cf03471a4ec4 | 180 | }; |
vcoubard | 565:cf03471a4ec4 | 181 | |
rgrover1 | 388:db85a09c27ef | 182 | #endif |