library for BLE_GAP_backpack

Dependencies:   nrf51-sdk

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:19:21 2016 +0000
Revision:
570:f162898cb6c4
Parent:
566:e425ad9e5d6e
Child:
571:bbf6410b6a89
Synchronized with git rev 786cd0b9
Author: Andres Amaya Garcia
Modify nRF5xn::shutdown to return actual error code

Who changed what in which revision?

UserRevisionLine numberNew 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 570:f162898cb6c4 44 /**
vcoubard 570:f162898cb6c4 45 * Accessors to GAP. This function checks whether gapInstance points to an
vcoubard 570:f162898cb6c4 46 * object. If if does not, then the gapInstance is updated to
vcoubard 570:f162898cb6c4 47 * &_getInstance before returning.
vcoubard 570:f162898cb6c4 48 *
vcoubard 570:f162898cb6c4 49 * @return A reference to GattServer.
vcoubard 570:f162898cb6c4 50 *
vcoubard 570:f162898cb6c4 51 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is
vcoubard 570:f162898cb6c4 52 * always needed in a BLE application. Therefore it is allocated
vcoubard 570:f162898cb6c4 53 * statically.
vcoubard 570:f162898cb6c4 54 */
vcoubard 565:cf03471a4ec4 55 virtual Gap &getGap() {
vcoubard 570:f162898cb6c4 56 if (gapInstance == NULL) {
vcoubard 570:f162898cb6c4 57 gapInstance = &_gapInstance;
vcoubard 570:f162898cb6c4 58 }
vcoubard 570:f162898cb6c4 59 return *gapInstance;
vcoubard 570:f162898cb6c4 60 };
vcoubard 570:f162898cb6c4 61
vcoubard 570:f162898cb6c4 62 /**
vcoubard 570:f162898cb6c4 63 * Accessors to GATT Server. This function checks whether a GattServer
vcoubard 570:f162898cb6c4 64 * object was previously instantiated. If such object does not exist, then
vcoubard 570:f162898cb6c4 65 * it is created before returning.
vcoubard 570:f162898cb6c4 66 *
vcoubard 570:f162898cb6c4 67 * @return A reference to GattServer.
vcoubard 570:f162898cb6c4 68 */
vcoubard 570:f162898cb6c4 69 virtual GattServer &getGattServer() {
vcoubard 570:f162898cb6c4 70 if (gattServerInstance == NULL) {
vcoubard 570:f162898cb6c4 71 gattServerInstance = new nRF5xGattServer();
vcoubard 570:f162898cb6c4 72 }
vcoubard 570:f162898cb6c4 73 return *gattServerInstance;
vcoubard 565:cf03471a4ec4 74 };
vcoubard 570:f162898cb6c4 75
vcoubard 570:f162898cb6c4 76 /**
vcoubard 570:f162898cb6c4 77 * Accessors to GATT Client. This function checks whether a GattClient
vcoubard 570:f162898cb6c4 78 * object was previously instantiated. If such object does not exist, then
vcoubard 570:f162898cb6c4 79 * it is created before returning.
vcoubard 570:f162898cb6c4 80 *
vcoubard 570:f162898cb6c4 81 * @return A reference to GattClient.
vcoubard 570:f162898cb6c4 82 */
vcoubard 570:f162898cb6c4 83 virtual GattClient &getGattClient() {
vcoubard 570:f162898cb6c4 84 if (gattClientInstance == NULL) {
vcoubard 570:f162898cb6c4 85 gattClientInstance = new nRF5xGattClient();
vcoubard 570:f162898cb6c4 86 }
vcoubard 570:f162898cb6c4 87 return *gattClientInstance;
vcoubard 570:f162898cb6c4 88 }
vcoubard 570:f162898cb6c4 89
vcoubard 570:f162898cb6c4 90 /**
vcoubard 570:f162898cb6c4 91 * Accessors to Security Manager. This function checks whether a SecurityManager
vcoubard 570:f162898cb6c4 92 * object was previously instantiated. If such object does not exist, then
vcoubard 570:f162898cb6c4 93 * it is created before returning.
vcoubard 570:f162898cb6c4 94 *
vcoubard 570:f162898cb6c4 95 * @return A reference to GattServer.
vcoubard 570:f162898cb6c4 96 */
vcoubard 570:f162898cb6c4 97 virtual SecurityManager &getSecurityManager() {
vcoubard 570:f162898cb6c4 98 if (securityManagerInstance == NULL) {
vcoubard 570:f162898cb6c4 99 securityManagerInstance = new nRF5xSecurityManager();
vcoubard 570:f162898cb6c4 100 }
vcoubard 570:f162898cb6c4 101 return *securityManagerInstance;
vcoubard 570:f162898cb6c4 102 }
vcoubard 570:f162898cb6c4 103
vcoubard 570:f162898cb6c4 104 /**
vcoubard 570:f162898cb6c4 105 * Accessors to GAP. This function checks whether gapInstance points to an
vcoubard 570:f162898cb6c4 106 * object. If if does not, then the gapInstance is updated to
vcoubard 570:f162898cb6c4 107 * &_getInstance before returning.
vcoubard 570:f162898cb6c4 108 *
vcoubard 570:f162898cb6c4 109 * @return A const reference to GattServer.
vcoubard 570:f162898cb6c4 110 *
vcoubard 570:f162898cb6c4 111 * @note Unlike the GattClient, GattServer and SecurityManager, Gap is
vcoubard 570:f162898cb6c4 112 * always needed in a BLE application. Therefore it is allocated
vcoubard 570:f162898cb6c4 113 * statically.
vcoubard 570:f162898cb6c4 114 *
vcoubard 570:f162898cb6c4 115 * @note The accessor is able to modify the object's state because the
vcoubard 570:f162898cb6c4 116 * internal pointer has been declared mutable.
vcoubard 570:f162898cb6c4 117 */
vcoubard 566:e425ad9e5d6e 118 virtual const Gap &getGap() const {
vcoubard 570:f162898cb6c4 119 if (gapInstance == NULL) {
vcoubard 570:f162898cb6c4 120 gapInstance = &_gapInstance;
vcoubard 570:f162898cb6c4 121 }
vcoubard 570:f162898cb6c4 122 return *gapInstance;
vcoubard 566:e425ad9e5d6e 123 };
vcoubard 570:f162898cb6c4 124
vcoubard 570:f162898cb6c4 125 /**
vcoubard 570:f162898cb6c4 126 * Accessors to GATT Server. This function checks whether a GattServer
vcoubard 570:f162898cb6c4 127 * object was previously instantiated. If such object does not exist, then
vcoubard 570:f162898cb6c4 128 * it is created before returning.
vcoubard 570:f162898cb6c4 129 *
vcoubard 570:f162898cb6c4 130 * @return A const reference to GattServer.
vcoubard 570:f162898cb6c4 131 *
vcoubard 570:f162898cb6c4 132 * @note The accessor is able to modify the object's state because the
vcoubard 570:f162898cb6c4 133 * internal pointer has been declared mutable.
vcoubard 570:f162898cb6c4 134 */
vcoubard 566:e425ad9e5d6e 135 virtual const GattServer &getGattServer() const {
vcoubard 570:f162898cb6c4 136 if (gattServerInstance == NULL) {
vcoubard 570:f162898cb6c4 137 gattServerInstance = new nRF5xGattServer();
vcoubard 570:f162898cb6c4 138 }
vcoubard 570:f162898cb6c4 139 return *gattServerInstance;
vcoubard 566:e425ad9e5d6e 140 };
vcoubard 570:f162898cb6c4 141
vcoubard 570:f162898cb6c4 142 /**
vcoubard 570:f162898cb6c4 143 * Accessors to Security Manager. This function checks whether a SecurityManager
vcoubard 570:f162898cb6c4 144 * object was previously instantiated. If such object does not exist, then
vcoubard 570:f162898cb6c4 145 * it is created before returning.
vcoubard 570:f162898cb6c4 146 *
vcoubard 570:f162898cb6c4 147 * @return A const reference to GattServer.
vcoubard 570:f162898cb6c4 148 *
vcoubard 570:f162898cb6c4 149 * @note The accessor is able to modify the object's state because the
vcoubard 570:f162898cb6c4 150 * internal pointer has been declared mutable.
vcoubard 570:f162898cb6c4 151 */
vcoubard 565:cf03471a4ec4 152 virtual const SecurityManager &getSecurityManager() const {
vcoubard 570:f162898cb6c4 153 if (securityManagerInstance == NULL) {
vcoubard 570:f162898cb6c4 154 securityManagerInstance = new nRF5xSecurityManager();
vcoubard 570:f162898cb6c4 155 }
vcoubard 570:f162898cb6c4 156 return *securityManagerInstance;
vcoubard 565:cf03471a4ec4 157 }
vcoubard 570:f162898cb6c4 158
vcoubard 565:cf03471a4ec4 159 virtual void waitForEvent(void);
vcoubard 565:cf03471a4ec4 160
vcoubard 570:f162898cb6c4 161 public:
vcoubard 570:f162898cb6c4 162 static nRF5xn& Instance(BLE::InstanceID_t instanceId);
vcoubard 570:f162898cb6c4 163
vcoubard 565:cf03471a4ec4 164 private:
vcoubard 565:cf03471a4ec4 165 bool initialized;
vcoubard 565:cf03471a4ec4 166 BLE::InstanceID_t instanceID;
vcoubard 570:f162898cb6c4 167
vcoubard 570:f162898cb6c4 168 private:
vcoubard 570:f162898cb6c4 169 static nRF5xGap _gapInstance; /**< Gap instance whose reference is returned from a call to
vcoubard 570:f162898cb6c4 170 * getGap(). Unlike the GattClient, GattServer and
vcoubard 570:f162898cb6c4 171 * SecurityManager, Gap is always needed in a BLE application.
vcoubard 570:f162898cb6c4 172 * Therefore it is allocated statically. */
vcoubard 570:f162898cb6c4 173
vcoubard 570:f162898cb6c4 174 private:
vcoubard 570:f162898cb6c4 175 mutable nRF5xGap *gapInstance; /**< Pointer to the Gap object instance.
vcoubard 570:f162898cb6c4 176 * If NULL, then Gap has not been initialized.
vcoubard 570:f162898cb6c4 177 * The pointer has been declared as 'mutable' so that
vcoubard 570:f162898cb6c4 178 * it can be assigned inside a 'const' function. */
vcoubard 570:f162898cb6c4 179 mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance.
vcoubard 570:f162898cb6c4 180 * If NULL, then GattServer has not been initialized.
vcoubard 570:f162898cb6c4 181 * The pointer has been declared as 'mutable' so that
vcoubard 570:f162898cb6c4 182 * it can be assigned inside a 'const' function. */
vcoubard 570:f162898cb6c4 183 mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance.
vcoubard 570:f162898cb6c4 184 * If NULL, then GattClient has not been initialized.
vcoubard 570:f162898cb6c4 185 * The pointer has been declared as 'mutable' so that
vcoubard 570:f162898cb6c4 186 * it can be assigned inside a 'const' function. */
vcoubard 570:f162898cb6c4 187 mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
vcoubard 570:f162898cb6c4 188 * If NULL, then SecurityManager has not been initialized.
vcoubard 570:f162898cb6c4 189 * The pointer has been declared as 'mutable' so that
vcoubard 570:f162898cb6c4 190 * it can be assigned inside a 'const' function. */
vcoubard 565:cf03471a4ec4 191 };
vcoubard 565:cf03471a4ec4 192
rgrover1 388:db85a09c27ef 193 #endif