BLE EddystoneService example

This example is a fork of the following mbed-os example:

https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-ble-EddystoneService/

Please read the documentation in this page.

Committer:
bcostm
Date:
Fri Jul 28 10:07:05 2017 +0200
Revision:
41:97bbb1eb43d7
Parent:
12:b31d7c0f906c
Add DISCO_L475VG_IOT01A in mbed_app.json

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 3:5120491ba317 1 /* mbed Microcontroller Library
mbed_official 3:5120491ba317 2 * Copyright (c) 2006-2015 ARM Limited
mbed_official 3:5120491ba317 3 *
mbed_official 3:5120491ba317 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 3:5120491ba317 5 * you may not use this file except in compliance with the License.
mbed_official 3:5120491ba317 6 * You may obtain a copy of the License at
mbed_official 3:5120491ba317 7 *
mbed_official 3:5120491ba317 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 3:5120491ba317 9 *
mbed_official 3:5120491ba317 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 3:5120491ba317 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 3:5120491ba317 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 3:5120491ba317 13 * See the License for the specific language governing permissions and
mbed_official 3:5120491ba317 14 * limitations under the License.
mbed_official 3:5120491ba317 15 */
mbed_official 3:5120491ba317 16
mbed_official 3:5120491ba317 17 #ifndef __EDDYSTONESERVICE_H__
mbed_official 3:5120491ba317 18 #define __EDDYSTONESERVICE_H__
mbed_official 3:5120491ba317 19
mbed_official 12:b31d7c0f906c 20 #include <events/mbed_events.h>
mbed_official 3:5120491ba317 21 #include "ble/BLE.h"
mbed_official 3:5120491ba317 22 #include "EddystoneTypes.h"
mbed_official 3:5120491ba317 23 #include "URLFrame.h"
mbed_official 3:5120491ba317 24 #include "UIDFrame.h"
mbed_official 3:5120491ba317 25 #include "TLMFrame.h"
mbed_official 3:5120491ba317 26 #include <string.h>
mbed_official 3:5120491ba317 27 #ifdef YOTTA_CFG_MBED_OS
mbed_official 3:5120491ba317 28 #include <mbed.h>
mbed_official 3:5120491ba317 29 #include "mbed-drivers/CircularBuffer.h"
mbed_official 3:5120491ba317 30 #else
mbed_official 3:5120491ba317 31 #include "mbed.h"
mbed_official 3:5120491ba317 32 #include "CircularBuffer.h"
mbed_official 3:5120491ba317 33 #endif
mbed_official 3:5120491ba317 34
mbed_official 3:5120491ba317 35 #ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_URL_FRAME_INTERVAL
mbed_official 3:5120491ba317 36 #define YOTTA_CFG_EDDYSTONE_DEFAULT_URL_FRAME_INTERVAL 700
mbed_official 3:5120491ba317 37 #endif
mbed_official 3:5120491ba317 38
mbed_official 3:5120491ba317 39 #ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_UID_FRAME_INTERVAL
mbed_official 3:5120491ba317 40 #define YOTTA_CFG_EDDYSTONE_DEFAULT_UID_FRAME_INTERVAL 300
mbed_official 3:5120491ba317 41 #endif
mbed_official 3:5120491ba317 42
mbed_official 3:5120491ba317 43 #ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_TLM_FRAME_INTERVAL
mbed_official 3:5120491ba317 44 #define YOTTA_CFG_EDDYSTONE_DEFAULT_TLM_FRAME_INTERVAL 2000
mbed_official 3:5120491ba317 45 #endif
mbed_official 3:5120491ba317 46
mbed_official 3:5120491ba317 47 #ifndef YOTTA_CFG_EDDYSTONE_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL
mbed_official 3:5120491ba317 48 #define YOTTA_CFG_EDDYSTONE_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL 1000
mbed_official 3:5120491ba317 49 #endif
mbed_official 3:5120491ba317 50
mbed_official 3:5120491ba317 51 /**
mbed_official 3:5120491ba317 52 * This class implements the Eddystone-URL Config Service and the Eddystone
mbed_official 3:5120491ba317 53 * Protocol Specification as defined in the publicly available specification at
mbed_official 3:5120491ba317 54 * https://github.com/google/eddystone/blob/master/protocol-specification.md.
mbed_official 3:5120491ba317 55 */
mbed_official 3:5120491ba317 56 class EddystoneService
mbed_official 3:5120491ba317 57 {
mbed_official 3:5120491ba317 58 public:
mbed_official 3:5120491ba317 59 /**
mbed_official 3:5120491ba317 60 * Total number of GATT Characteristics in the Eddystonei-URL Configuration
mbed_official 3:5120491ba317 61 * Service.
mbed_official 3:5120491ba317 62 */
mbed_official 3:5120491ba317 63 static const uint16_t TOTAL_CHARACTERISTICS = 9;
mbed_official 3:5120491ba317 64
mbed_official 3:5120491ba317 65 /**
mbed_official 3:5120491ba317 66 * Default interval for advertising packets for the Eddystone-URL
mbed_official 3:5120491ba317 67 * Configuration Service.
mbed_official 3:5120491ba317 68 */
mbed_official 3:5120491ba317 69 static const uint32_t DEFAULT_CONFIG_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_EDDYSTONE_URL_CONFIG_ADV_INTERVAL;
mbed_official 3:5120491ba317 70 /**
mbed_official 3:5120491ba317 71 * Recommended interval for advertising packets containing Eddystone URL
mbed_official 3:5120491ba317 72 * frames.
mbed_official 3:5120491ba317 73 */
mbed_official 3:5120491ba317 74 static const uint16_t DEFAULT_URL_FRAME_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_URL_FRAME_INTERVAL;
mbed_official 3:5120491ba317 75 /**
mbed_official 3:5120491ba317 76 * Recommended interval for advertising packets containing Eddystone UID
mbed_official 3:5120491ba317 77 * frames.
mbed_official 3:5120491ba317 78 */
mbed_official 3:5120491ba317 79 static const uint16_t DEFAULT_UID_FRAME_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_UID_FRAME_INTERVAL;
mbed_official 3:5120491ba317 80 /**
mbed_official 3:5120491ba317 81 * Recommended interval for advertising packets containing Eddystone TLM
mbed_official 3:5120491ba317 82 * frames.
mbed_official 3:5120491ba317 83 */
mbed_official 3:5120491ba317 84 static const uint16_t DEFAULT_TLM_FRAME_PERIOD_MSEC = YOTTA_CFG_EDDYSTONE_DEFAULT_TLM_FRAME_INTERVAL;
mbed_official 3:5120491ba317 85
mbed_official 3:5120491ba317 86 /**
mbed_official 3:5120491ba317 87 * Enumeration that defines the various operation modes of the
mbed_official 3:5120491ba317 88 * EddystoneService.
mbed_official 3:5120491ba317 89 *
mbed_official 3:5120491ba317 90 * @note The main app can change the mode of EddystoneService at any point
mbed_official 3:5120491ba317 91 * of time by calling startConfigService() or startBeaconService().
mbed_official 3:5120491ba317 92 * Resources from the previous mode will be freed.
mbed_official 3:5120491ba317 93 *
mbed_official 3:5120491ba317 94 * @note It is currently NOT possible to force EddystoneService back into
mbed_official 3:5120491ba317 95 * EDDYSTONE_MODE_NONE.
mbed_official 3:5120491ba317 96 */
mbed_official 3:5120491ba317 97 enum OperationModes {
mbed_official 3:5120491ba317 98 /**
mbed_official 3:5120491ba317 99 * NONE: EddystoneService has been initialized but no memory has been
mbed_official 3:5120491ba317 100 * dynamically allocated. Additionally, no services are running
mbed_official 3:5120491ba317 101 * nothing is being advertised.
mbed_official 3:5120491ba317 102 */
mbed_official 3:5120491ba317 103 EDDYSTONE_MODE_NONE,
mbed_official 3:5120491ba317 104 /**
mbed_official 3:5120491ba317 105 * CONFIG: EddystoneService has been initialized, the configuration
mbed_official 3:5120491ba317 106 * service started and memory has been allocated for BLE
mbed_official 3:5120491ba317 107 * characteristics. Memory consumption peaks during CONFIG
mbed_official 3:5120491ba317 108 * mode.
mbed_official 3:5120491ba317 109 */
mbed_official 3:5120491ba317 110 EDDYSTONE_MODE_CONFIG,
mbed_official 3:5120491ba317 111 /**
mbed_official 3:5120491ba317 112 * BEACON: Eddystone service is running as a beacon advertising URL,
mbed_official 3:5120491ba317 113 * UID and/or TLM frames depending on how it is configured.
mbed_official 3:5120491ba317 114 */
mbed_official 3:5120491ba317 115 EDDYSTONE_MODE_BEACON
mbed_official 3:5120491ba317 116 };
mbed_official 3:5120491ba317 117
mbed_official 3:5120491ba317 118 /**
mbed_official 3:5120491ba317 119 * Structure that encapsulates the Eddystone configuration parameters. This
mbed_official 3:5120491ba317 120 * structure is particularly useful when storing the parameters to
mbed_official 3:5120491ba317 121 * persistent storage.
mbed_official 3:5120491ba317 122 */
mbed_official 3:5120491ba317 123 struct EddystoneParams_t {
mbed_official 3:5120491ba317 124 /**
mbed_official 3:5120491ba317 125 * The value of the Eddystone-URL Configuration Service Lock State
mbed_official 3:5120491ba317 126 * characteristic.
mbed_official 3:5120491ba317 127 */
mbed_official 3:5120491ba317 128 bool lockState;
mbed_official 3:5120491ba317 129 /**
mbed_official 3:5120491ba317 130 * The value of the Eddystone-URL Configuration Service Lock
mbed_official 3:5120491ba317 131 * characteristic that can be used to lock the beacon and set the
mbed_official 3:5120491ba317 132 * single-use lock-code.
mbed_official 3:5120491ba317 133 */
mbed_official 3:5120491ba317 134 Lock_t lock;
mbed_official 3:5120491ba317 135 /**
mbed_official 3:5120491ba317 136 * The value of the Eddystone-URL Configuration Service Unlock
mbed_official 3:5120491ba317 137 * characteristic that can be used to unlock the beacon and clear the
mbed_official 3:5120491ba317 138 * single-use lock-code.
mbed_official 3:5120491ba317 139 */
mbed_official 3:5120491ba317 140 Lock_t unlock;
mbed_official 3:5120491ba317 141 /**
mbed_official 3:5120491ba317 142 * The value of the Eddystone-URL Configuration Service Flags
mbed_official 3:5120491ba317 143 * characteristic. This value is currently fixed to 0x10.
mbed_official 3:5120491ba317 144 */
mbed_official 3:5120491ba317 145 uint8_t flags;
mbed_official 3:5120491ba317 146 /**
mbed_official 3:5120491ba317 147 * The value of the Eddystone-URL Configuration Service Advertised TX
mbed_official 3:5120491ba317 148 * Power Levels characteristic that is an array of bytes whose values
mbed_official 3:5120491ba317 149 * are put into the advertising packets when in EDDYSTONE_BEACON_MODE.
mbed_official 3:5120491ba317 150 *
mbed_official 3:5120491ba317 151 * @note These are not the same values set internally into the radio tx
mbed_official 3:5120491ba317 152 * power.
mbed_official 3:5120491ba317 153 */
mbed_official 3:5120491ba317 154 PowerLevels_t advPowerLevels;
mbed_official 3:5120491ba317 155 /**
mbed_official 3:5120491ba317 156 * The value of the Eddystone-URL Configuration Service TX Power Mode
mbed_official 3:5120491ba317 157 * characteristic. This value is an index into the
mbed_official 3:5120491ba317 158 * EddystoneParams_t::advPowerLevels array.
mbed_official 3:5120491ba317 159 */
mbed_official 3:5120491ba317 160 uint8_t txPowerMode;
mbed_official 3:5120491ba317 161 /**
mbed_official 3:5120491ba317 162 * The value of the Eddystone-URL Configuration Service Beacon Period
mbed_official 3:5120491ba317 163 * characteristic that is the interval (in milliseconds) of the
mbed_official 3:5120491ba317 164 * Eddystone-URL frames.
mbed_official 3:5120491ba317 165 *
mbed_official 3:5120491ba317 166 * @note A value of zero disables Eddystone-URL frame trasmissions.
mbed_official 3:5120491ba317 167 */
mbed_official 3:5120491ba317 168 uint16_t urlFramePeriod;
mbed_official 3:5120491ba317 169 /**
mbed_official 3:5120491ba317 170 * The configured interval (in milliseconds) of the Eddystone-UID
mbed_official 3:5120491ba317 171 * frames.
mbed_official 3:5120491ba317 172 *
mbed_official 3:5120491ba317 173 * @note A value of zero disables Eddystone-UID frame transmissions.
mbed_official 3:5120491ba317 174 *
mbed_official 3:5120491ba317 175 * @note Currently it is only possible to modify this value by using
mbed_official 3:5120491ba317 176 * the setUIDFrameAdvertisingInterval() API.
mbed_official 3:5120491ba317 177 */
mbed_official 3:5120491ba317 178 uint16_t uidFramePeriod;
mbed_official 3:5120491ba317 179 /**
mbed_official 3:5120491ba317 180 * The configured interval (in milliseconds) of the Eddystone-TLM
mbed_official 3:5120491ba317 181 * frames.
mbed_official 3:5120491ba317 182 *
mbed_official 3:5120491ba317 183 * @note A value of zero disables Eddystone-TLM frame transmissions.
mbed_official 3:5120491ba317 184 *
mbed_official 3:5120491ba317 185 * @note Currently it is only possible to modify this value by using
mbed_official 3:5120491ba317 186 * the setTLMFrameAdvertisingInterval() API.
mbed_official 3:5120491ba317 187 */
mbed_official 3:5120491ba317 188 uint16_t tlmFramePeriod;
mbed_official 3:5120491ba317 189 /**
mbed_official 3:5120491ba317 190 * The configured version of the Eddystone-TLM frames.
mbed_official 3:5120491ba317 191 */
mbed_official 3:5120491ba317 192 uint8_t tlmVersion;
mbed_official 3:5120491ba317 193 /**
mbed_official 3:5120491ba317 194 * The length of the encoded URL in EddystoneParams_t::urlData used
mbed_official 3:5120491ba317 195 * within Eddystone-URL frames.
mbed_official 3:5120491ba317 196 */
mbed_official 3:5120491ba317 197 uint8_t urlDataLength;
mbed_official 3:5120491ba317 198 /**
mbed_official 3:5120491ba317 199 * The value of the Eddystone-URL Configuration Service URI Data
mbed_official 3:5120491ba317 200 * characteristic that contains an encoded URL as described in the
mbed_official 3:5120491ba317 201 * Eddystone Specification at
mbed_official 3:5120491ba317 202 * https://github.com/google/eddystone/blob/master/eddystone-url/README.md#eddystone-url-http-url-encoding.
mbed_official 3:5120491ba317 203 */
mbed_official 3:5120491ba317 204 UrlData_t urlData;
mbed_official 3:5120491ba317 205 /**
mbed_official 3:5120491ba317 206 * The configured 10-byte namespace ID in Eddystone-UID frames that may
mbed_official 3:5120491ba317 207 * be used to group a particular set of beacons.
mbed_official 3:5120491ba317 208 */
mbed_official 3:5120491ba317 209 UIDNamespaceID_t uidNamespaceID;
mbed_official 3:5120491ba317 210 /**
mbed_official 3:5120491ba317 211 * The configured 6-byte instance ID that may be used to uniquely
mbed_official 3:5120491ba317 212 * identify individual devices in a group.
mbed_official 3:5120491ba317 213 */
mbed_official 3:5120491ba317 214 UIDInstanceID_t uidInstanceID;
mbed_official 3:5120491ba317 215 };
mbed_official 3:5120491ba317 216
mbed_official 3:5120491ba317 217 /**
mbed_official 3:5120491ba317 218 * Enumeration that defines the various error codes for EddystoneService.
mbed_official 3:5120491ba317 219 */
mbed_official 3:5120491ba317 220 enum EddystoneError_t {
mbed_official 3:5120491ba317 221 /**
mbed_official 3:5120491ba317 222 * No error occurred.
mbed_official 3:5120491ba317 223 */
mbed_official 3:5120491ba317 224 EDDYSTONE_ERROR_NONE,
mbed_official 3:5120491ba317 225 /**
mbed_official 3:5120491ba317 226 * The supplied advertising interval is invalid. The interval may be
mbed_official 3:5120491ba317 227 * too short/long for the type of advertising packets being broadcast.
mbed_official 3:5120491ba317 228 *
mbed_official 3:5120491ba317 229 * @note For the acceptable range of advertising interval refer to the
mbed_official 3:5120491ba317 230 * following functions in mbed BLE API:
mbed_official 3:5120491ba317 231 * - Gap::getMinNonConnectableAdvertisingInterval()
mbed_official 3:5120491ba317 232 * - Gap::getMinAdvertisingInterval()
mbed_official 3:5120491ba317 233 * - Gap::getMaxAdvertisingInterval()
mbed_official 3:5120491ba317 234 */
mbed_official 3:5120491ba317 235 EDDYSTONE_ERROR_INVALID_ADVERTISING_INTERVAL,
mbed_official 3:5120491ba317 236 /**
mbed_official 3:5120491ba317 237 * The result of executing a call when the the EddystoneService is in
mbed_official 3:5120491ba317 238 * the incorrect operation mode.
mbed_official 3:5120491ba317 239 */
mbed_official 3:5120491ba317 240 EDDYSTONE_ERROR_INVALID_STATE
mbed_official 3:5120491ba317 241 };
mbed_official 3:5120491ba317 242
mbed_official 3:5120491ba317 243 /**
mbed_official 3:5120491ba317 244 * Enumeration that defines the available frame types within Eddystone
mbed_official 3:5120491ba317 245 * advertising packets.
mbed_official 3:5120491ba317 246 */
mbed_official 3:5120491ba317 247 enum FrameType {
mbed_official 3:5120491ba317 248 /**
mbed_official 3:5120491ba317 249 * The Eddystone-URL frame. Refer to
mbed_official 3:5120491ba317 250 * https://github.com/google/eddystone/tree/master/eddystone-url.
mbed_official 3:5120491ba317 251 */
mbed_official 3:5120491ba317 252 EDDYSTONE_FRAME_URL,
mbed_official 3:5120491ba317 253 /**
mbed_official 3:5120491ba317 254 * The Eddystone-URL frame. Refer to
mbed_official 3:5120491ba317 255 * https://github.com/google/eddystone/tree/master/eddystone-uid.
mbed_official 3:5120491ba317 256 */
mbed_official 3:5120491ba317 257 EDDYSTONE_FRAME_UID,
mbed_official 3:5120491ba317 258 /**
mbed_official 3:5120491ba317 259 * The Eddystone-URL frame. Refer to
mbed_official 3:5120491ba317 260 * https://github.com/google/eddystone/tree/master/eddystone-tlm.
mbed_official 3:5120491ba317 261 */
mbed_official 3:5120491ba317 262 EDDYSTONE_FRAME_TLM,
mbed_official 3:5120491ba317 263 /**
mbed_official 3:5120491ba317 264 * The total number Eddystone frame types.
mbed_official 3:5120491ba317 265 */
mbed_official 3:5120491ba317 266 NUM_EDDYSTONE_FRAMES
mbed_official 3:5120491ba317 267 };
mbed_official 3:5120491ba317 268
mbed_official 3:5120491ba317 269 /**
mbed_official 3:5120491ba317 270 * The size of the advertising frame queue.
mbed_official 3:5120491ba317 271 *
mbed_official 3:5120491ba317 272 * @note [WARNING] If the advertising rate for any of the frames is higher
mbed_official 3:5120491ba317 273 * than 100ms then frames will be dropped, this value must be
mbed_official 3:5120491ba317 274 * increased.
mbed_official 3:5120491ba317 275 */
mbed_official 3:5120491ba317 276 static const uint16_t ADV_FRAME_QUEUE_SIZE = NUM_EDDYSTONE_FRAMES;
mbed_official 3:5120491ba317 277
mbed_official 3:5120491ba317 278
mbed_official 3:5120491ba317 279 /**
mbed_official 3:5120491ba317 280 * Constructor that Initializes the EddystoneService using parameters from
mbed_official 3:5120491ba317 281 * the supplied EddystoneParams_t. This constructor is particularly useful
mbed_official 3:5120491ba317 282 * for configuring the EddystoneService with parameters fetched from
mbed_official 3:5120491ba317 283 * persistent storage.
mbed_official 3:5120491ba317 284 *
mbed_official 3:5120491ba317 285 * @param[in] bleIn
mbed_official 3:5120491ba317 286 * The BLE instance.
mbed_official 3:5120491ba317 287 * @param[in] paramIn
mbed_official 3:5120491ba317 288 * The input Eddystone configuration parameters.
mbed_official 3:5120491ba317 289 * @param[in] radioPowerLevelsIn
mbed_official 3:5120491ba317 290 * The value set internally into the radion tx power.
mbed_official 3:5120491ba317 291 * @param[in] advConfigIntervalIn
mbed_official 3:5120491ba317 292 * The advertising interval for advertising packets of the
mbed_official 3:5120491ba317 293 * Eddystone-URL Configuration Service.
mbed_official 3:5120491ba317 294 */
mbed_official 3:5120491ba317 295 EddystoneService(BLE &bleIn,
mbed_official 3:5120491ba317 296 EddystoneParams_t &paramsIn,
mbed_official 3:5120491ba317 297 const PowerLevels_t &radioPowerLevelsIn,
mbed_official 3:5120491ba317 298 events::EventQueue& eventQueue,
mbed_official 3:5120491ba317 299 uint32_t advConfigIntervalIn = DEFAULT_CONFIG_PERIOD_MSEC);
mbed_official 3:5120491ba317 300
mbed_official 3:5120491ba317 301 /**
mbed_official 3:5120491ba317 302 * Constructor to initialize the EddystoneService to default values.
mbed_official 3:5120491ba317 303 *
mbed_official 3:5120491ba317 304 * @param[in] bleIn
mbed_official 3:5120491ba317 305 * The BLE instance.
mbed_official 3:5120491ba317 306 * @param[in] advPowerLevelsIn
mbed_official 3:5120491ba317 307 * The value of the Eddystone-URL Configuration Service TX
mbed_official 3:5120491ba317 308 * Power Mode characteristic.
mbed_official 3:5120491ba317 309 * @param[in] radioPowerLevelsIn
mbed_official 3:5120491ba317 310 * The value set internally into the radion tx power.
mbed_official 3:5120491ba317 311 * @param[in] advConfigIntervalIn
mbed_official 3:5120491ba317 312 * The advertising interval for advertising packets of the
mbed_official 3:5120491ba317 313 * Eddystone-URL Configuration Service.
mbed_official 3:5120491ba317 314 *
mbed_official 3:5120491ba317 315 * @note When using this constructor the setURLData(), setTMLData() and
mbed_official 3:5120491ba317 316 * setUIDData() functions must be called to initialize
mbed_official 3:5120491ba317 317 * EddystoneService manually.
mbed_official 3:5120491ba317 318 */
mbed_official 3:5120491ba317 319 EddystoneService(BLE &bleIn,
mbed_official 3:5120491ba317 320 const PowerLevels_t &advPowerLevelsIn,
mbed_official 3:5120491ba317 321 const PowerLevels_t &radioPowerLevelsIn,
mbed_official 3:5120491ba317 322 EventQueue &eventQueue,
mbed_official 3:5120491ba317 323 uint32_t advConfigIntervalIn = DEFAULT_CONFIG_PERIOD_MSEC);
mbed_official 3:5120491ba317 324
mbed_official 3:5120491ba317 325 /**
mbed_official 3:5120491ba317 326 * Setup callback to update BatteryVoltage in Eddystone-TLM frames
mbed_official 3:5120491ba317 327 *
mbed_official 3:5120491ba317 328 * @param[in] tlmBatteryVoltageCallbackIn
mbed_official 3:5120491ba317 329 * The callback being registered.
mbed_official 3:5120491ba317 330 */
mbed_official 3:5120491ba317 331 void onTLMBatteryVoltageUpdate(TlmUpdateCallback_t tlmBatteryVoltageCallbackIn);
mbed_official 3:5120491ba317 332
mbed_official 3:5120491ba317 333 /**
mbed_official 3:5120491ba317 334 * Setup callback to update BeaconTemperature in Eddystone-TLM frames
mbed_official 3:5120491ba317 335 *
mbed_official 3:5120491ba317 336 * @param[in] tlmBeaconTemperatureCallbackIn
mbed_official 3:5120491ba317 337 * The callback being registered.
mbed_official 3:5120491ba317 338 */
mbed_official 3:5120491ba317 339 void onTLMBeaconTemperatureUpdate(TlmUpdateCallback_t tlmBeaconTemperatureCallbackIn);
mbed_official 3:5120491ba317 340
mbed_official 3:5120491ba317 341 /**
mbed_official 3:5120491ba317 342 * Set the Eddystone-TLM frame version. The other components of
mbed_official 3:5120491ba317 343 * Eddystone-TLM frames are updated just before the frame is broadcast
mbed_official 3:5120491ba317 344 * since information such as beacon temperature and time since boot changes
mbed_official 3:5120491ba317 345 * relatively quickly.
mbed_official 3:5120491ba317 346 *
mbed_official 3:5120491ba317 347 * @param[in] tlmVersionIn
mbed_official 3:5120491ba317 348 * The Eddyston-TLM version to set.
mbed_official 3:5120491ba317 349 */
mbed_official 3:5120491ba317 350 void setTLMData(uint8_t tlmVersionIn = 0);
mbed_official 3:5120491ba317 351
mbed_official 3:5120491ba317 352 /**
mbed_official 3:5120491ba317 353 * Set the Eddystone-URL frame URL data.
mbed_official 3:5120491ba317 354 *
mbed_official 3:5120491ba317 355 * @param[in] urlDataIn
mbed_official 3:5120491ba317 356 * A pointer to the plain null terminated string representing
mbed_official 3:5120491ba317 357 * a URL to be encoded.
mbed_official 3:5120491ba317 358 */
mbed_official 3:5120491ba317 359 void setURLData(const char *urlDataIn);
mbed_official 3:5120491ba317 360
mbed_official 3:5120491ba317 361 /**
mbed_official 3:5120491ba317 362 * Set the Eddystone-UID namespace and instance IDs.
mbed_official 3:5120491ba317 363 *
mbed_official 3:5120491ba317 364 * @param[in] uidNamespaceIDIn
mbed_official 3:5120491ba317 365 * The new Eddystone-UID namespace ID.
mbed_official 3:5120491ba317 366 * @param[in] uidInstanceIDIn
mbed_official 3:5120491ba317 367 * The new Eddystone-UID instance ID.
mbed_official 3:5120491ba317 368 */
mbed_official 3:5120491ba317 369 void setUIDData(const UIDNamespaceID_t &uidNamespaceIDIn, const UIDInstanceID_t &uidInstanceIDIn);
mbed_official 3:5120491ba317 370
mbed_official 3:5120491ba317 371 /**
mbed_official 3:5120491ba317 372 * Set the interval of the Eddystone-URL frames.
mbed_official 3:5120491ba317 373 *
mbed_official 3:5120491ba317 374 * @param[in] urlFrameIntervalIn
mbed_official 3:5120491ba317 375 * The new frame interval in milliseconds. The default is
mbed_official 3:5120491ba317 376 * DEFAULT_URL_FRAME_PERIOD_MSEC.
mbed_official 3:5120491ba317 377 *
mbed_official 3:5120491ba317 378 * @note A value of zero disables Eddystone-URL frame transmissions.
mbed_official 3:5120491ba317 379 */
mbed_official 3:5120491ba317 380 void setURLFrameAdvertisingInterval(uint16_t urlFrameIntervalIn = DEFAULT_URL_FRAME_PERIOD_MSEC);
mbed_official 3:5120491ba317 381
mbed_official 3:5120491ba317 382 /**
mbed_official 3:5120491ba317 383 * Set the interval of the Eddystone-UID frames.
mbed_official 3:5120491ba317 384 *
mbed_official 3:5120491ba317 385 * @param[in] uidFrameIntervalIn
mbed_official 3:5120491ba317 386 * The new frame interval in milliseconds. The default is
mbed_official 3:5120491ba317 387 * DEFAULT_UID_FRAME_PERIOD_MSEC.
mbed_official 3:5120491ba317 388 *
mbed_official 3:5120491ba317 389 * @note A value of zero disables Eddystone-UID frame transmissions.
mbed_official 3:5120491ba317 390 */
mbed_official 3:5120491ba317 391 void setUIDFrameAdvertisingInterval(uint16_t uidFrameIntervalIn = DEFAULT_UID_FRAME_PERIOD_MSEC);
mbed_official 3:5120491ba317 392
mbed_official 3:5120491ba317 393 /**
mbed_official 3:5120491ba317 394 * Set the interval for the Eddystone-TLM frames.
mbed_official 3:5120491ba317 395 *
mbed_official 3:5120491ba317 396 * @param[in] tlmFrameIntervalIn
mbed_official 3:5120491ba317 397 * The new frame interval in milliseconds. The default is
mbed_official 3:5120491ba317 398 * DEFAULT_TLM_FRAME_PERIOD_MSEC.
mbed_official 3:5120491ba317 399 *
mbed_official 3:5120491ba317 400 * @note A value of zero desables Eddystone-TLM frames.
mbed_official 3:5120491ba317 401 */
mbed_official 3:5120491ba317 402 void setTLMFrameAdvertisingInterval(uint16_t tlmFrameIntervalIn = DEFAULT_TLM_FRAME_PERIOD_MSEC);
mbed_official 3:5120491ba317 403
mbed_official 3:5120491ba317 404 /**
mbed_official 3:5120491ba317 405 * Change the EddystoneService OperationMode to EDDYSTONE_MODE_CONFIG.
mbed_official 3:5120491ba317 406 *
mbed_official 3:5120491ba317 407 * @retval EDDYSTONE_ERROR_NONE if the operation succeeded.
mbed_official 3:5120491ba317 408 * @retval EDDYSONE_ERROR_INVALID_ADVERTISING_INTERVAL if the configured
mbed_official 3:5120491ba317 409 * advertising interval is zero.
mbed_official 3:5120491ba317 410 *
mbed_official 3:5120491ba317 411 * @note If EddystoneService was previously in EDDYSTONE_MODE_BEACON, then
mbed_official 3:5120491ba317 412 * the resources allocated to that mode of operation such as memory
mbed_official 3:5120491ba317 413 * are freed and the BLE instance shutdown before the new operation
mbed_official 3:5120491ba317 414 * mode is configured.
mbed_official 3:5120491ba317 415 */
mbed_official 3:5120491ba317 416 EddystoneError_t startConfigService(void);
mbed_official 3:5120491ba317 417
mbed_official 3:5120491ba317 418 /**
mbed_official 3:5120491ba317 419 * Change the EddystoneService OperationMode to EDDYSTONE_MODE_BEACON.
mbed_official 3:5120491ba317 420 *
mbed_official 3:5120491ba317 421 * @retval EDDYSTONE_ERROR_NONE if the operation succeeded.
mbed_official 3:5120491ba317 422 * @retval EDDYSONE_ERROR_INVALID_ADVERTISING_INTERVAL if the configured
mbed_official 3:5120491ba317 423 * advertising interval is zero.
mbed_official 3:5120491ba317 424 *
mbed_official 3:5120491ba317 425 * @note If EddystoneService was previously in EDDYSTONE_MODE_CONFIG, then
mbed_official 3:5120491ba317 426 * the resources allocated to that mode of operation such as memory
mbed_official 3:5120491ba317 427 * are freed and the BLE instance shutdown before the new operation
mbed_official 3:5120491ba317 428 * mode is configured.
mbed_official 3:5120491ba317 429 */
mbed_official 3:5120491ba317 430 EddystoneError_t startBeaconService(void);
mbed_official 3:5120491ba317 431
mbed_official 3:5120491ba317 432 /**
mbed_official 3:5120491ba317 433 * Change the EddystoneService OperationMode to EDDYSTONE_MODE_NONE.
mbed_official 3:5120491ba317 434 *
mbed_official 3:5120491ba317 435 * @retval EDDYSTONE_ERROR_NONE if the operation succeeded.
mbed_official 3:5120491ba317 436 * @retval EDDYSTONE_ERROR_INVALID_STATE if the state of the
mbed_official 3:5120491ba317 437 * EddystoneService already is EDDYSTONE_MODE_NONE.
mbed_official 3:5120491ba317 438 *
mbed_official 3:5120491ba317 439 * @note If EddystoneService was previously in EDDYSTONE_MODE_CONFIG or
mbed_official 3:5120491ba317 440 * EDDYSTONE_MODE_BEACON, then the resources allocated to that mode
mbed_official 3:5120491ba317 441 * of operation such as memory are freed and the BLE instance
mbed_official 3:5120491ba317 442 * shutdown before the new operation mode is configured.
mbed_official 3:5120491ba317 443 */
mbed_official 3:5120491ba317 444 EddystoneError_t stopCurrentService(void);
mbed_official 3:5120491ba317 445
mbed_official 3:5120491ba317 446 /**
mbed_official 3:5120491ba317 447 * Set the Comple Local Name for the BLE device. This not only updates
mbed_official 3:5120491ba317 448 * the value of the Device Name Characteristic, it also updates the scan
mbed_official 3:5120491ba317 449 * response payload if the EddystoneService is currently in
mbed_official 3:5120491ba317 450 * EDDYSTONE_MODE_CONFIG.
mbed_official 3:5120491ba317 451 *
mbed_official 3:5120491ba317 452 * @param[in] deviceNameIn
mbed_official 3:5120491ba317 453 * A pointer to a null terminated string containing the new
mbed_official 3:5120491ba317 454 * device name.
mbed_official 3:5120491ba317 455 *
mbed_official 3:5120491ba317 456 * @return BLE_ERROR_NONE if the name was successfully set. Otherwise an
mbed_official 3:5120491ba317 457 * appropriate error.
mbed_official 3:5120491ba317 458 *
mbed_official 3:5120491ba317 459 * @note EddystoneService does not make an internal copy of the string
mbed_official 3:5120491ba317 460 * pointed to by @p deviceNameIn. Therefore, the user is responsible
mbed_official 3:5120491ba317 461 * for ensuring that the string persists in memory as long as it is
mbed_official 3:5120491ba317 462 * in use by the EddystoneService.
mbed_official 3:5120491ba317 463 *
mbed_official 3:5120491ba317 464 * @note The device name is not considered an Eddystone configuration
mbed_official 3:5120491ba317 465 * parameter; therefore, it is not contained within the
mbed_official 3:5120491ba317 466 * EddystoneParams_t structure and must be stored to persistent
mbed_official 3:5120491ba317 467 * storage separately.
mbed_official 3:5120491ba317 468 */
mbed_official 3:5120491ba317 469 ble_error_t setCompleteDeviceName(const char *deviceNameIn);
mbed_official 3:5120491ba317 470
mbed_official 3:5120491ba317 471 /**
mbed_official 3:5120491ba317 472 * Get the Eddystone Configuration parameters. This is particularly useful
mbed_official 3:5120491ba317 473 * for storing the configuration parameters in persistent storage.
mbed_official 3:5120491ba317 474 * It is not the responsibility of the Eddystone implementation to store
mbed_official 3:5120491ba317 475 * the configured parameters in persistent storage since this is
mbed_official 3:5120491ba317 476 * platform-specific.
mbed_official 3:5120491ba317 477 *
mbed_official 3:5120491ba317 478 * @param[out] params
mbed_official 3:5120491ba317 479 * A reference to an EddystoneParams_t structure with the
mbed_official 3:5120491ba317 480 * configured parameters of the EddystoneService.
mbed_official 3:5120491ba317 481 */
mbed_official 3:5120491ba317 482 void getEddystoneParams(EddystoneParams_t &params);
mbed_official 3:5120491ba317 483
mbed_official 3:5120491ba317 484 private:
mbed_official 3:5120491ba317 485 /**
mbed_official 3:5120491ba317 486 * Helper function used only once during construction of an
mbed_official 3:5120491ba317 487 * EddystoneService object to avoid duplicated code.
mbed_official 3:5120491ba317 488 *
mbed_official 3:5120491ba317 489 * @param[in] advPowerLevelsIn
mbed_official 3:5120491ba317 490 * The value of the Eddystone-URL Configuration Service TX
mbed_official 3:5120491ba317 491 * Power Mode characteristic.
mbed_official 3:5120491ba317 492 * @param[in] radioPowerLevelsIn
mbed_official 3:5120491ba317 493 * The value set internally into the radion tx power.
mbed_official 3:5120491ba317 494 * @param[in] advConfigIntervalIn
mbed_official 3:5120491ba317 495 * The advertising interval for advertising packets of the
mbed_official 3:5120491ba317 496 * Eddystone-URL Configuration Service.
mbed_official 3:5120491ba317 497 */
mbed_official 3:5120491ba317 498 void eddystoneConstructorHelper(const PowerLevels_t &advPowerLevelsIn,
mbed_official 3:5120491ba317 499 const PowerLevels_t &radioPowerLevelsIn,
mbed_official 3:5120491ba317 500 uint32_t advConfigIntervalIn);
mbed_official 3:5120491ba317 501
mbed_official 3:5120491ba317 502 /**
mbed_official 3:5120491ba317 503 * Helper funtion that will be registered as an initialization complete
mbed_official 3:5120491ba317 504 * callback when BLE::shutdown() is called. This is necessary when changing
mbed_official 3:5120491ba317 505 * Eddystone OperationModes. Once the BLE initialization is complete, this
mbed_official 3:5120491ba317 506 * callback will initialize all the necessary resource to operate
mbed_official 3:5120491ba317 507 * Eddystone service in the selected mode.
mbed_official 3:5120491ba317 508 *
mbed_official 3:5120491ba317 509 * @param[in] initContext
mbed_official 3:5120491ba317 510 * The context provided by BLE API when initialization
mbed_official 3:5120491ba317 511 * completes.
mbed_official 3:5120491ba317 512 */
mbed_official 3:5120491ba317 513 void bleInitComplete(BLE::InitializationCompleteCallbackContext* initContext);
mbed_official 3:5120491ba317 514
mbed_official 3:5120491ba317 515 /**
mbed_official 3:5120491ba317 516 * When in EDDYSTONE_MODE_BEACON this function is called to update the
mbed_official 3:5120491ba317 517 * advertising payload to contain the information related to the specified
mbed_official 3:5120491ba317 518 * FrameType.
mbed_official 3:5120491ba317 519 *
mbed_official 3:5120491ba317 520 * @param[in] frameType
mbed_official 3:5120491ba317 521 * The frame to populate the advertising payload with.
mbed_official 3:5120491ba317 522 */
mbed_official 3:5120491ba317 523 void swapAdvertisedFrame(FrameType frameType);
mbed_official 3:5120491ba317 524
mbed_official 3:5120491ba317 525 /**
mbed_official 3:5120491ba317 526 * Helper function that manages the BLE radio that is used to broadcast
mbed_official 3:5120491ba317 527 * advertising packets. To advertise frames at the configured intervals
mbed_official 3:5120491ba317 528 * the actual advertising interval of the BLE instance is set to the value
mbed_official 3:5120491ba317 529 * returned by Gap::getMaxAdvertisingInterval() from the BLE API. When a
mbed_official 3:5120491ba317 530 * frame needs to be advertised, the enqueueFrame() callbacks add the frame
mbed_official 3:5120491ba317 531 * type to the advFrameQueue and post a manageRadio() callback. When the
mbed_official 3:5120491ba317 532 * callback is executed, the frame is dequeued and advertised using the
mbed_official 3:5120491ba317 533 * radio (by updating the advertising payload). manageRadio() also posts a
mbed_official 3:5120491ba317 534 * callback to itself Gap::getMinNonConnectableAdvertisingInterval()
mbed_official 3:5120491ba317 535 * milliseconds later. In this callback, manageRadio() will advertise the
mbed_official 3:5120491ba317 536 * next frame in the queue, yet if there is none it calls
mbed_official 3:5120491ba317 537 * Gap::stopAdvertising() and does not post any further callbacks.
mbed_official 3:5120491ba317 538 */
mbed_official 3:5120491ba317 539 void manageRadio(void);
mbed_official 3:5120491ba317 540
mbed_official 3:5120491ba317 541 /**
mbed_official 3:5120491ba317 542 * Regular callbacks posted at the rate of urlFramePeriod, uidFramePeriod
mbed_official 3:5120491ba317 543 * and tlmFramePeriod milliseconds enqueue frames to be advertised. If the
mbed_official 3:5120491ba317 544 * frame queue is currently empty, then this function directly calls
mbed_official 3:5120491ba317 545 * manageRadio() to broadcast the required FrameType.
mbed_official 3:5120491ba317 546 *
mbed_official 3:5120491ba317 547 * @param[in] frameType
mbed_official 3:5120491ba317 548 * The FrameType to enqueue for broadcasting.
mbed_official 3:5120491ba317 549 */
mbed_official 3:5120491ba317 550 void enqueueFrame(FrameType frameType);
mbed_official 3:5120491ba317 551
mbed_official 3:5120491ba317 552 /**
mbed_official 3:5120491ba317 553 * Helper function that updates the advertising payload when in
mbed_official 3:5120491ba317 554 * EDDYSTONE_MODE_BEACON to contain a new frame.
mbed_official 3:5120491ba317 555 *
mbed_official 3:5120491ba317 556 * @param[in] rawFrame
mbed_official 3:5120491ba317 557 * The raw bytes of the frame to advertise.
mbed_official 3:5120491ba317 558 * @param[in] rawFrameLength
mbed_official 3:5120491ba317 559 * The length in bytes of the array pointed to by @p rawFrame.
mbed_official 3:5120491ba317 560 */
mbed_official 3:5120491ba317 561 void updateAdvertisementPacket(const uint8_t* rawFrame, size_t rawFrameLength);
mbed_official 3:5120491ba317 562
mbed_official 3:5120491ba317 563 /**
mbed_official 3:5120491ba317 564 * Helper function that updates the information in the Eddystone-TLM frames
mbed_official 3:5120491ba317 565 * Internally, this function executes the registered callbacks to update
mbed_official 3:5120491ba317 566 * beacon Battery Voltage and Temperature (if available). Furthermore, this
mbed_official 3:5120491ba317 567 * function updates the raw frame data. This operation must be done fairly
mbed_official 3:5120491ba317 568 * often because the Eddystone-TLM frame Time Since Boot must have a 0.1
mbed_official 3:5120491ba317 569 * seconds resolution according to the Eddystone specification.
mbed_official 3:5120491ba317 570 */
mbed_official 3:5120491ba317 571 void updateRawTLMFrame(void);
mbed_official 3:5120491ba317 572
mbed_official 3:5120491ba317 573 /**
mbed_official 3:5120491ba317 574 * Initialize the resources required when switching to
mbed_official 3:5120491ba317 575 * EDDYSTONE_MODE_BEACON.
mbed_official 3:5120491ba317 576 */
mbed_official 3:5120491ba317 577 void setupBeaconService(void);
mbed_official 3:5120491ba317 578
mbed_official 3:5120491ba317 579 /**
mbed_official 3:5120491ba317 580 * Initialize the resources required when switching to
mbed_official 3:5120491ba317 581 * EDDYSTONE_MODE_CONFIG. This includes the GATT services and
mbed_official 3:5120491ba317 582 * characteristics required by the Eddystone-URL Configuration Service.
mbed_official 3:5120491ba317 583 */
mbed_official 3:5120491ba317 584 void setupConfigService(void);
mbed_official 3:5120491ba317 585
mbed_official 3:5120491ba317 586 /**
mbed_official 3:5120491ba317 587 * Free the resources acquired by a call to setupConfigService().
mbed_official 3:5120491ba317 588 */
mbed_official 3:5120491ba317 589 void freeConfigCharacteristics(void);
mbed_official 3:5120491ba317 590
mbed_official 3:5120491ba317 591 /**
mbed_official 3:5120491ba317 592 * Free the resources acquired by a call to setupBeaconService() and
mbed_official 3:5120491ba317 593 * cancel all pending callbacks that operate the radio and frame queue.
mbed_official 3:5120491ba317 594 *
mbed_official 3:5120491ba317 595 * @note This call will not modify the current state of the BLE device.
mbed_official 3:5120491ba317 596 * EddystoneService::stopBeaconService should only be called after
mbed_official 3:5120491ba317 597 * a call to BLE::shutdown().
mbed_official 3:5120491ba317 598 */
mbed_official 3:5120491ba317 599 void stopBeaconService(void);
mbed_official 3:5120491ba317 600
mbed_official 3:5120491ba317 601 /**
mbed_official 3:5120491ba317 602 * Helper function used to update the GATT database following any
mbed_official 3:5120491ba317 603 * change to the internal state of the service object.
mbed_official 3:5120491ba317 604 */
mbed_official 3:5120491ba317 605 void updateCharacteristicValues(void);
mbed_official 3:5120491ba317 606
mbed_official 3:5120491ba317 607 /**
mbed_official 3:5120491ba317 608 * Setup the payload of advertising packets for Eddystone-URL Configuration
mbed_official 3:5120491ba317 609 * Service.
mbed_official 3:5120491ba317 610 */
mbed_official 3:5120491ba317 611 void setupEddystoneConfigAdvertisements(void);
mbed_official 3:5120491ba317 612
mbed_official 3:5120491ba317 613 /**
mbed_official 3:5120491ba317 614 * Helper function to setup the payload of scan response packets for
mbed_official 3:5120491ba317 615 * Eddystone-URL Configuration Service.
mbed_official 3:5120491ba317 616 */
mbed_official 3:5120491ba317 617 void setupEddystoneConfigScanResponse(void);
mbed_official 3:5120491ba317 618
mbed_official 3:5120491ba317 619 /**
mbed_official 3:5120491ba317 620 * Callback registered to the BLE API to authorize write operations to the
mbed_official 3:5120491ba317 621 * Eddystone-URL Configuration Service Lock characteristic.
mbed_official 3:5120491ba317 622 *
mbed_official 3:5120491ba317 623 * @param[in] authParams
mbed_official 3:5120491ba317 624 * Write authentication information.
mbed_official 3:5120491ba317 625 */
mbed_official 3:5120491ba317 626 void lockAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
mbed_official 3:5120491ba317 627
mbed_official 3:5120491ba317 628 /**
mbed_official 3:5120491ba317 629 * Callback registered to the BLE API to authorize write operations to the
mbed_official 3:5120491ba317 630 * Eddystone-URL Configuration Service Unlock characteristic.
mbed_official 3:5120491ba317 631 *
mbed_official 3:5120491ba317 632 * @param[in] authParams
mbed_official 3:5120491ba317 633 * Write authentication information.
mbed_official 3:5120491ba317 634 */
mbed_official 3:5120491ba317 635 void unlockAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
mbed_official 3:5120491ba317 636
mbed_official 3:5120491ba317 637 /**
mbed_official 3:5120491ba317 638 * Callback registered to the BLE API to authorize write operations to the
mbed_official 3:5120491ba317 639 * Eddystone-URL Configuration Service URI Data characteristic.
mbed_official 3:5120491ba317 640 *
mbed_official 3:5120491ba317 641 * @param[in] authParams
mbed_official 3:5120491ba317 642 * Write authentication information.
mbed_official 3:5120491ba317 643 */
mbed_official 3:5120491ba317 644 void urlDataWriteAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
mbed_official 3:5120491ba317 645
mbed_official 3:5120491ba317 646 void powerModeAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
mbed_official 3:5120491ba317 647
mbed_official 3:5120491ba317 648 /**
mbed_official 3:5120491ba317 649 * Callback registered to the BLE API to authorize write operations to the
mbed_official 3:5120491ba317 650 * following Eddystone-URL Configuration Service characteristics:
mbed_official 3:5120491ba317 651 * - Flags
mbed_official 3:5120491ba317 652 * - Beacon Period
mbed_official 3:5120491ba317 653 * - Reset
mbed_official 3:5120491ba317 654 *
mbed_official 3:5120491ba317 655 * @param[in] authParams
mbed_official 3:5120491ba317 656 * Write authentication information.
mbed_official 3:5120491ba317 657 */
mbed_official 3:5120491ba317 658 template <typename T>
mbed_official 3:5120491ba317 659 void basicAuthorizationCallback(GattWriteAuthCallbackParams *authParams);
mbed_official 3:5120491ba317 660
mbed_official 3:5120491ba317 661 /**
mbed_official 3:5120491ba317 662 * This callback is invoked when a GATT client attempts to modify any of the
mbed_official 3:5120491ba317 663 * characteristics of this service. Attempts to do so are also applied to
mbed_official 3:5120491ba317 664 * the internal state of this service object.
mbed_official 3:5120491ba317 665 *
mbed_official 3:5120491ba317 666 * @param[in] writeParams
mbed_official 3:5120491ba317 667 * Information about the values that are being written.
mbed_official 3:5120491ba317 668 */
mbed_official 3:5120491ba317 669 void onDataWrittenCallback(const GattWriteCallbackParams *writeParams);
mbed_official 3:5120491ba317 670
mbed_official 3:5120491ba317 671 /**
mbed_official 3:5120491ba317 672 * Correct the advertising interval for non-connectable packets.
mbed_official 3:5120491ba317 673 *
mbed_official 3:5120491ba317 674 * @param[in] beaconPeriodIn
mbed_official 3:5120491ba317 675 * The input interval in milliseconds.
mbed_official 3:5120491ba317 676 *
mbed_official 3:5120491ba317 677 * @return The corrected interval in milliseconds.
mbed_official 3:5120491ba317 678 *
mbed_official 3:5120491ba317 679 * @note For the acceptable range of advertising interval refer to the
mbed_official 3:5120491ba317 680 * following functions in mbed BLE API:
mbed_official 3:5120491ba317 681 * - Gap::getMinNonConnectableAdvertisingInterval()
mbed_official 3:5120491ba317 682 * - Gap::getMaxAdvertisingInterval()
mbed_official 3:5120491ba317 683 */
mbed_official 3:5120491ba317 684 uint16_t correctAdvertisementPeriod(uint16_t beaconPeriodIn) const;
mbed_official 3:5120491ba317 685
mbed_official 3:5120491ba317 686 /**
mbed_official 3:5120491ba317 687 * BLE instance that EddystoneService will operate on.
mbed_official 3:5120491ba317 688 */
mbed_official 3:5120491ba317 689 BLE &ble;
mbed_official 3:5120491ba317 690 /**
mbed_official 3:5120491ba317 691 * The advertising interval for Eddystone-URL Config Service advertising
mbed_official 3:5120491ba317 692 * packets.
mbed_official 3:5120491ba317 693 */
mbed_official 3:5120491ba317 694 uint32_t advConfigInterval;
mbed_official 3:5120491ba317 695 /**
mbed_official 3:5120491ba317 696 * Current EddystoneServce operation mode.
mbed_official 3:5120491ba317 697 */
mbed_official 3:5120491ba317 698 uint8_t operationMode;
mbed_official 3:5120491ba317 699
mbed_official 3:5120491ba317 700 /**
mbed_official 3:5120491ba317 701 * Encapsulation of a URL frame.
mbed_official 3:5120491ba317 702 */
mbed_official 3:5120491ba317 703 URLFrame urlFrame;
mbed_official 3:5120491ba317 704 /**
mbed_official 3:5120491ba317 705 * Encapsulation of a UID frame.
mbed_official 3:5120491ba317 706 */
mbed_official 3:5120491ba317 707 UIDFrame uidFrame;
mbed_official 3:5120491ba317 708 /**
mbed_official 3:5120491ba317 709 * Encapsulation of a TLM frame.
mbed_official 3:5120491ba317 710 */
mbed_official 3:5120491ba317 711 TLMFrame tlmFrame;
mbed_official 3:5120491ba317 712
mbed_official 3:5120491ba317 713 /**
mbed_official 3:5120491ba317 714 * The value set internally into the radion tx power.
mbed_official 3:5120491ba317 715 */
mbed_official 3:5120491ba317 716 PowerLevels_t radioPowerLevels;
mbed_official 3:5120491ba317 717 /**
mbed_official 3:5120491ba317 718 * An array containing possible values for advertised tx power in Eddystone
mbed_official 3:5120491ba317 719 * frames. Also, the value of the Eddystone-URL Configuration Service
mbed_official 3:5120491ba317 720 * Advertised TX Power Levels characteristic.
mbed_official 3:5120491ba317 721 */
mbed_official 3:5120491ba317 722 PowerLevels_t advPowerLevels;
mbed_official 3:5120491ba317 723 /**
mbed_official 3:5120491ba317 724 * The value of the Eddystone-URL Configuration Service Lock State
mbed_official 3:5120491ba317 725 * characteristic.
mbed_official 3:5120491ba317 726 */
mbed_official 3:5120491ba317 727 bool lockState;
mbed_official 3:5120491ba317 728 /**
mbed_official 3:5120491ba317 729 * The value of the Eddystone-URL Configuration Service reset
mbed_official 3:5120491ba317 730 * characteristic.
mbed_official 3:5120491ba317 731 */
mbed_official 3:5120491ba317 732 bool resetFlag;
mbed_official 3:5120491ba317 733 /**
mbed_official 3:5120491ba317 734 * The value of the Eddystone-URL Configuration Service Lock
mbed_official 3:5120491ba317 735 * characteristic.
mbed_official 3:5120491ba317 736 */
mbed_official 3:5120491ba317 737 Lock_t lock;
mbed_official 3:5120491ba317 738 /**
mbed_official 3:5120491ba317 739 * The value of the Eddystone-URL Configuration Service Unlock
mbed_official 3:5120491ba317 740 * characteristic.
mbed_official 3:5120491ba317 741 */
mbed_official 3:5120491ba317 742 Lock_t unlock;
mbed_official 3:5120491ba317 743 /**
mbed_official 3:5120491ba317 744 * The value of the Eddystone-URL Configuration Service Flags
mbed_official 3:5120491ba317 745 * characteristic.
mbed_official 3:5120491ba317 746 */
mbed_official 3:5120491ba317 747 uint8_t flags;
mbed_official 3:5120491ba317 748 /**
mbed_official 3:5120491ba317 749 * The value of the Eddystone-URL Configuration Service TX Power Mode
mbed_official 3:5120491ba317 750 * characteristic.
mbed_official 3:5120491ba317 751 */
mbed_official 3:5120491ba317 752 uint8_t txPowerMode;
mbed_official 3:5120491ba317 753 /**
mbed_official 3:5120491ba317 754 * The value of the Eddystone-URL Configuration Service Beacon Period
mbed_official 3:5120491ba317 755 * characteristic. Also, the advertising interval (in milliseconds) of
mbed_official 3:5120491ba317 756 * Eddystone-URL frames.
mbed_official 3:5120491ba317 757 */
mbed_official 3:5120491ba317 758 uint16_t urlFramePeriod;
mbed_official 3:5120491ba317 759 /**
mbed_official 3:5120491ba317 760 * The advertising interval (in milliseconds) of Eddystone-UID frames.
mbed_official 3:5120491ba317 761 */
mbed_official 3:5120491ba317 762 uint16_t uidFramePeriod;
mbed_official 3:5120491ba317 763 /**
mbed_official 3:5120491ba317 764 * The advertising interval (in milliseconds) of Eddystone-TLM frames.
mbed_official 3:5120491ba317 765 */
mbed_official 3:5120491ba317 766 uint16_t tlmFramePeriod;
mbed_official 3:5120491ba317 767
mbed_official 3:5120491ba317 768 /**
mbed_official 3:5120491ba317 769 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 770 * Configuration Service Lock State characteristic.
mbed_official 3:5120491ba317 771 */
mbed_official 3:5120491ba317 772 ReadOnlyGattCharacteristic<bool> *lockStateChar;
mbed_official 3:5120491ba317 773 /**
mbed_official 3:5120491ba317 774 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 775 * Configuration Service Lock characteristic.
mbed_official 3:5120491ba317 776 */
mbed_official 3:5120491ba317 777 WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(Lock_t)> *lockChar;
mbed_official 3:5120491ba317 778 /**
mbed_official 3:5120491ba317 779 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 780 * Configuration Service Unlock characteristic.
mbed_official 3:5120491ba317 781 */
mbed_official 3:5120491ba317 782 WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(Lock_t)> *unlockChar;
mbed_official 3:5120491ba317 783 /**
mbed_official 3:5120491ba317 784 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 785 * Configuration Service URI Data characteristic.
mbed_official 3:5120491ba317 786 */
mbed_official 3:5120491ba317 787 GattCharacteristic *urlDataChar;
mbed_official 3:5120491ba317 788 /**
mbed_official 3:5120491ba317 789 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 790 * Configuration Service Flags characteristic.
mbed_official 3:5120491ba317 791 */
mbed_official 3:5120491ba317 792 ReadWriteGattCharacteristic<uint8_t> *flagsChar;
mbed_official 3:5120491ba317 793 /**
mbed_official 3:5120491ba317 794 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 795 * Configuration Service Advertised TX Power Levels characteristic.
mbed_official 3:5120491ba317 796 */
mbed_official 3:5120491ba317 797 ReadWriteArrayGattCharacteristic<int8_t, sizeof(PowerLevels_t)> *advPowerLevelsChar;
mbed_official 3:5120491ba317 798 /**
mbed_official 3:5120491ba317 799 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 800 * Configuration Service TX Power Mode characteristic.
mbed_official 3:5120491ba317 801 */
mbed_official 3:5120491ba317 802 ReadWriteGattCharacteristic<uint8_t> *txPowerModeChar;
mbed_official 3:5120491ba317 803 /**
mbed_official 3:5120491ba317 804 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 805 * Configuration Service Beacon Period characteristic.
mbed_official 3:5120491ba317 806 */
mbed_official 3:5120491ba317 807 ReadWriteGattCharacteristic<uint16_t> *beaconPeriodChar;
mbed_official 3:5120491ba317 808 /**
mbed_official 3:5120491ba317 809 * Pointer to the BLE API characteristic encapsulation for the Eddystone-URL
mbed_official 3:5120491ba317 810 * Configuration Service Reset characteristic.
mbed_official 3:5120491ba317 811 */
mbed_official 3:5120491ba317 812 WriteOnlyGattCharacteristic<bool> *resetChar;
mbed_official 3:5120491ba317 813
mbed_official 3:5120491ba317 814 /**
mbed_official 3:5120491ba317 815 * Pointer to the raw bytes that will be used to populate Eddystone-URL
mbed_official 3:5120491ba317 816 * frames.
mbed_official 3:5120491ba317 817 */
mbed_official 3:5120491ba317 818 uint8_t *rawUrlFrame;
mbed_official 3:5120491ba317 819 /**
mbed_official 3:5120491ba317 820 * Pointer to the raw bytes that will be used to populate Eddystone-UID
mbed_official 3:5120491ba317 821 * frames.
mbed_official 3:5120491ba317 822 */
mbed_official 3:5120491ba317 823 uint8_t *rawUidFrame;
mbed_official 3:5120491ba317 824 /**
mbed_official 3:5120491ba317 825 * Pointer to the raw bytes that will be used to populate Eddystone-TLM
mbed_official 3:5120491ba317 826 * frames.
mbed_official 3:5120491ba317 827 */
mbed_official 3:5120491ba317 828 uint8_t *rawTlmFrame;
mbed_official 3:5120491ba317 829
mbed_official 3:5120491ba317 830 /**
mbed_official 3:5120491ba317 831 * Circular buffer that represents of Eddystone frames to be advertised.
mbed_official 3:5120491ba317 832 */
mbed_official 3:5120491ba317 833 CircularBuffer<FrameType, ADV_FRAME_QUEUE_SIZE> advFrameQueue;
mbed_official 3:5120491ba317 834
mbed_official 3:5120491ba317 835 /**
mbed_official 3:5120491ba317 836 * The registered callback to update the Eddystone-TLM frame Battery
mbed_official 3:5120491ba317 837 * Voltage.
mbed_official 3:5120491ba317 838 */
mbed_official 3:5120491ba317 839 TlmUpdateCallback_t tlmBatteryVoltageCallback;
mbed_official 3:5120491ba317 840 /**
mbed_official 3:5120491ba317 841 * The registered callback to update the Eddystone-TLM frame Beacon
mbed_official 3:5120491ba317 842 * Temperature.
mbed_official 3:5120491ba317 843 */
mbed_official 3:5120491ba317 844 TlmUpdateCallback_t tlmBeaconTemperatureCallback;
mbed_official 3:5120491ba317 845
mbed_official 3:5120491ba317 846 /**
mbed_official 3:5120491ba317 847 * Timer that keeps track of the time since boot.
mbed_official 3:5120491ba317 848 */
mbed_official 3:5120491ba317 849 Timer timeSinceBootTimer;
mbed_official 3:5120491ba317 850
mbed_official 3:5120491ba317 851 /**
mbed_official 3:5120491ba317 852 * Callback handle to keep track of periodic
mbed_official 3:5120491ba317 853 * enqueueFrame(EDDYSTONE_FRAME_UID) callbacks that populate the
mbed_official 3:5120491ba317 854 * advFrameQueue.
mbed_official 3:5120491ba317 855 */
mbed_official 3:5120491ba317 856 int uidFrameCallbackHandle;
mbed_official 3:5120491ba317 857 /**
mbed_official 3:5120491ba317 858 * Minar callback handle to keep track of periodic
mbed_official 3:5120491ba317 859 * enqueueFrame(EDDYSTONE_FRAME_URL) callbacks that populate the
mbed_official 3:5120491ba317 860 * advFrameQueue.
mbed_official 3:5120491ba317 861 */
mbed_official 3:5120491ba317 862 int urlFrameCallbackHandle;
mbed_official 3:5120491ba317 863 /**
mbed_official 3:5120491ba317 864 * Minar callback handle to keep track of periodic
mbed_official 3:5120491ba317 865 * enqueueFrame(EDDYSTONE_FRAME_TLM) callbacks that populate the
mbed_official 3:5120491ba317 866 * advFrameQueue.
mbed_official 3:5120491ba317 867 */
mbed_official 3:5120491ba317 868 int tlmFrameCallbackHandle;
mbed_official 3:5120491ba317 869 /**
mbed_official 3:5120491ba317 870 * Minar callback handle to keep track of manageRadio() callbacks.
mbed_official 3:5120491ba317 871 */
mbed_official 3:5120491ba317 872 int radioManagerCallbackHandle;
mbed_official 3:5120491ba317 873
mbed_official 3:5120491ba317 874 /**
mbed_official 3:5120491ba317 875 * GattCharacteristic table used to populate the BLE ATT table in the
mbed_official 3:5120491ba317 876 * GATT Server.
mbed_official 3:5120491ba317 877 */
mbed_official 3:5120491ba317 878 GattCharacteristic *charTable[TOTAL_CHARACTERISTICS];
mbed_official 3:5120491ba317 879
mbed_official 3:5120491ba317 880 /**
mbed_official 3:5120491ba317 881 * Pointer to the device name currently being used.
mbed_official 3:5120491ba317 882 */
mbed_official 3:5120491ba317 883 const char *deviceName;
mbed_official 3:5120491ba317 884
mbed_official 3:5120491ba317 885 /**
mbed_official 3:5120491ba317 886 * Event queue used to post callbacks s
mbed_official 3:5120491ba317 887 */
mbed_official 3:5120491ba317 888 EventQueue& eventQueue;
mbed_official 3:5120491ba317 889 };
mbed_official 3:5120491ba317 890
mbed_official 3:5120491ba317 891 #endif /* __EDDYSTONESERVICE_H__ */