hr with 30102

Dependencies:   BLE_API mbed X_NUCLEO_IDB0XA1

Fork of BLE_HeartRate by Bluetooth Low Energy

Committer:
mssarwar
Date:
Sun Jul 30 05:52:57 2017 +0000
Revision:
80:808f6f367f45
with 30102;

Who changed what in which revision?

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