High level Bluetooth Low Energy API and radio abstraction layer

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Thu Nov 26 12:52:04 2015 +0000
Revision:
918:2b12b53101ea
Synchronized with git rev 162fb4f7
Author: Vincent Coubard
Add detach operation to CallChainOfFunctionPointersWithContext, Add
operator== to functionpointerWithContext class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 918:2b12b53101ea 1 /* mbed Microcontroller Library
rgrover1 918:2b12b53101ea 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 918:2b12b53101ea 3 *
rgrover1 918:2b12b53101ea 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 918:2b12b53101ea 5 * you may not use this file except in compliance with the License.
rgrover1 918:2b12b53101ea 6 * You may obtain a copy of the License at
rgrover1 918:2b12b53101ea 7 *
rgrover1 918:2b12b53101ea 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 918:2b12b53101ea 9 *
rgrover1 918:2b12b53101ea 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 918:2b12b53101ea 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 918:2b12b53101ea 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 918:2b12b53101ea 13 * See the License for the specific language governing permissions and
rgrover1 918:2b12b53101ea 14 * limitations under the License.
rgrover1 918:2b12b53101ea 15 */
rgrover1 918:2b12b53101ea 16
rgrover1 918:2b12b53101ea 17 #ifndef SERVICES_EDDYSTONE_BEACON_CONFIG_SERVICE_H_
rgrover1 918:2b12b53101ea 18 #define SERVICES_EDDYSTONE_BEACON_CONFIG_SERVICE_H_
rgrover1 918:2b12b53101ea 19
rgrover1 918:2b12b53101ea 20 #include "mbed.h"
rgrover1 918:2b12b53101ea 21 #include "ble/BLE.h"
rgrover1 918:2b12b53101ea 22 #include "ble/services/EddystoneService.h"
rgrover1 918:2b12b53101ea 23
rgrover1 918:2b12b53101ea 24 #define UUID_URI_BEACON(FIRST, SECOND) { \
rgrover1 918:2b12b53101ea 25 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \
rgrover1 918:2b12b53101ea 26 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \
rgrover1 918:2b12b53101ea 27 }
rgrover1 918:2b12b53101ea 28
rgrover1 918:2b12b53101ea 29 static const uint8_t UUID_URI_BEACON_SERVICE[] = UUID_URI_BEACON(0x20, 0x80);
rgrover1 918:2b12b53101ea 30 static const uint8_t UUID_LOCK_STATE_CHAR[] = UUID_URI_BEACON(0x20, 0x81);
rgrover1 918:2b12b53101ea 31 static const uint8_t UUID_LOCK_CHAR[] = UUID_URI_BEACON(0x20, 0x82);
rgrover1 918:2b12b53101ea 32 static const uint8_t UUID_UNLOCK_CHAR[] = UUID_URI_BEACON(0x20, 0x83);
rgrover1 918:2b12b53101ea 33 static const uint8_t UUID_URI_DATA_CHAR[] = UUID_URI_BEACON(0x20, 0x84);
rgrover1 918:2b12b53101ea 34 static const uint8_t UUID_FLAGS_CHAR[] = UUID_URI_BEACON(0x20, 0x85);
rgrover1 918:2b12b53101ea 35 static const uint8_t UUID_ADV_POWER_LEVELS_CHAR[] = UUID_URI_BEACON(0x20, 0x86);
rgrover1 918:2b12b53101ea 36 static const uint8_t UUID_TX_POWER_MODE_CHAR[] = UUID_URI_BEACON(0x20, 0x87);
rgrover1 918:2b12b53101ea 37 static const uint8_t UUID_BEACON_PERIOD_CHAR[] = UUID_URI_BEACON(0x20, 0x88);
rgrover1 918:2b12b53101ea 38 static const uint8_t UUID_RESET_CHAR[] = UUID_URI_BEACON(0x20, 0x89);
rgrover1 918:2b12b53101ea 39 extern const uint8_t BEACON_EDDYSTONE[2];
rgrover1 918:2b12b53101ea 40
rgrover1 918:2b12b53101ea 41 /**
rgrover1 918:2b12b53101ea 42 * @class EddystoneConfigService
rgrover1 918:2b12b53101ea 43 * @brief Eddystone Configuration Service. Can be used to set URL, adjust power levels, and set flags.
rgrover1 918:2b12b53101ea 44 * See https://github.com/google/eddystone
rgrover1 918:2b12b53101ea 45 *
rgrover1 918:2b12b53101ea 46 */
rgrover1 918:2b12b53101ea 47 class EddystoneConfigService
rgrover1 918:2b12b53101ea 48 {
rgrover1 918:2b12b53101ea 49 public:
rgrover1 918:2b12b53101ea 50 /**
rgrover1 918:2b12b53101ea 51 * @brief Transmission Power Modes for UriBeacon
rgrover1 918:2b12b53101ea 52 */
rgrover1 918:2b12b53101ea 53 enum {
rgrover1 918:2b12b53101ea 54 TX_POWER_MODE_LOWEST,
rgrover1 918:2b12b53101ea 55 TX_POWER_MODE_LOW,
rgrover1 918:2b12b53101ea 56 TX_POWER_MODE_MEDIUM,
rgrover1 918:2b12b53101ea 57 TX_POWER_MODE_HIGH,
rgrover1 918:2b12b53101ea 58 NUM_POWER_MODES
rgrover1 918:2b12b53101ea 59 };
rgrover1 918:2b12b53101ea 60
rgrover1 918:2b12b53101ea 61 static const unsigned ADVERTISING_INTERVAL_MSEC = 1000; // Advertising interval for config service.
rgrover1 918:2b12b53101ea 62 static const unsigned SERVICE_DATA_MAX = 31; // Maximum size of service data in ADV packets
rgrover1 918:2b12b53101ea 63
rgrover1 918:2b12b53101ea 64 typedef uint8_t Lock_t[16]; /* 128 bits */
rgrover1 918:2b12b53101ea 65 typedef int8_t PowerLevels_t[NUM_POWER_MODES];
rgrover1 918:2b12b53101ea 66
rgrover1 918:2b12b53101ea 67 // There are currently 3 subframes defined, URI, UID, and TLM
rgrover1 918:2b12b53101ea 68 #define EDDYSTONE_MAX_FRAMETYPE 3
rgrover1 918:2b12b53101ea 69 static const unsigned URI_DATA_MAX = 18;
rgrover1 918:2b12b53101ea 70 typedef uint8_t UriData_t[URI_DATA_MAX];
rgrover1 918:2b12b53101ea 71
rgrover1 918:2b12b53101ea 72 // UID Frame Type subfields
rgrover1 918:2b12b53101ea 73 static const size_t UID_NAMESPACEID_SIZE = 10;
rgrover1 918:2b12b53101ea 74 typedef uint8_t UIDNamespaceID_t[UID_NAMESPACEID_SIZE];
rgrover1 918:2b12b53101ea 75 static const size_t UID_INSTANCEID_SIZE = 6;
rgrover1 918:2b12b53101ea 76 typedef uint8_t UIDInstanceID_t[UID_INSTANCEID_SIZE];
rgrover1 918:2b12b53101ea 77
rgrover1 918:2b12b53101ea 78 // Eddystone Frame Type ID
rgrover1 918:2b12b53101ea 79 static const uint8_t FRAME_TYPE_UID = 0x00;
rgrover1 918:2b12b53101ea 80 static const uint8_t FRAME_TYPE_URL = 0x10;
rgrover1 918:2b12b53101ea 81 static const uint8_t FRAME_TYPE_TLM = 0x20;
rgrover1 918:2b12b53101ea 82
rgrover1 918:2b12b53101ea 83 static const uint8_t FRAME_SIZE_TLM = 14; // TLM frame is a constant 14Bytes
rgrover1 918:2b12b53101ea 84 static const uint8_t FRAME_SIZE_UID = 20; // includes RFU bytes
rgrover1 918:2b12b53101ea 85
rgrover1 918:2b12b53101ea 86 struct Params_t {
rgrover1 918:2b12b53101ea 87 // Config Data
rgrover1 918:2b12b53101ea 88 bool isConfigured; // Flag for configuration being complete,
rgrover1 918:2b12b53101ea 89 // True = configured, false = not configured. Reset at instantiation, used for external callbacks.
rgrover1 918:2b12b53101ea 90 uint8_t lockedState;
rgrover1 918:2b12b53101ea 91 Lock_t lock;
rgrover1 918:2b12b53101ea 92 uint8_t flags;
rgrover1 918:2b12b53101ea 93 PowerLevels_t advPowerLevels; // Current value of AdvertisedPowerLevels
rgrover1 918:2b12b53101ea 94 uint8_t txPowerMode; // Firmware power levels used with setTxPower()
rgrover1 918:2b12b53101ea 95 uint16_t beaconPeriod;
rgrover1 918:2b12b53101ea 96 // TLM Frame Data
rgrover1 918:2b12b53101ea 97 uint8_t tlmVersion; // version of TLM packet
rgrover1 918:2b12b53101ea 98 bool tlmEnabled;
rgrover1 918:2b12b53101ea 99 float tlmBeaconPeriod; // how often to broadcat TLM frame, in seconds.
rgrover1 918:2b12b53101ea 100 // URI Frame Data
rgrover1 918:2b12b53101ea 101 uint8_t uriDataLength;
rgrover1 918:2b12b53101ea 102 UriData_t uriData;
rgrover1 918:2b12b53101ea 103 bool uriEnabled;
rgrover1 918:2b12b53101ea 104 float uriBeaconPeriod; // how often to broadcast URIFrame, in seconds.
rgrover1 918:2b12b53101ea 105 // UID Frame Data
rgrover1 918:2b12b53101ea 106 UIDNamespaceID_t uidNamespaceID; // UUID type, Namespace ID, 10B
rgrover1 918:2b12b53101ea 107 UIDInstanceID_t uidInstanceID; // UUID type, Instance ID, 6B
rgrover1 918:2b12b53101ea 108 bool uidEnabled;
rgrover1 918:2b12b53101ea 109 float uidBeaconPeriod; // how often to broadcast UID Frame, in seconds.
rgrover1 918:2b12b53101ea 110 };
rgrover1 918:2b12b53101ea 111
rgrover1 918:2b12b53101ea 112 /**
rgrover1 918:2b12b53101ea 113 * @param[ref] ble
rgrover1 918:2b12b53101ea 114 * BLEDevice object for the underlying controller.
rgrover1 918:2b12b53101ea 115 * @param[in/out] paramsIn
rgrover1 918:2b12b53101ea 116 * Reference to application-visible beacon state, loaded
rgrover1 918:2b12b53101ea 117 * from persistent storage at startup.
rgrover1 918:2b12b53101ea 118 * @param[in] defaultAdvPowerLevelsIn
rgrover1 918:2b12b53101ea 119 * Default power-levels array; applies only if the resetToDefaultsFlag is true.
rgrover1 918:2b12b53101ea 120 */
rgrover1 918:2b12b53101ea 121 EddystoneConfigService(BLEDevice &bleIn,
rgrover1 918:2b12b53101ea 122 Params_t &paramsIn,
rgrover1 918:2b12b53101ea 123 PowerLevels_t &defaultAdvPowerLevelsIn,
rgrover1 918:2b12b53101ea 124 PowerLevels_t &radioPowerLevelsIn) :
rgrover1 918:2b12b53101ea 125 ble(bleIn),
rgrover1 918:2b12b53101ea 126 params(paramsIn), // Initialize URL Data
rgrover1 918:2b12b53101ea 127 defaultAdvPowerLevels(defaultAdvPowerLevelsIn),
rgrover1 918:2b12b53101ea 128 radioPowerLevels(radioPowerLevelsIn),
rgrover1 918:2b12b53101ea 129 initSucceeded(false),
rgrover1 918:2b12b53101ea 130 resetFlag(),
rgrover1 918:2b12b53101ea 131 defaultUidNamespaceID(), // Initialize UID Data
rgrover1 918:2b12b53101ea 132 defaultUidInstanceID(),
rgrover1 918:2b12b53101ea 133 defaultUidPower(defaultAdvPowerLevelsIn[params.txPowerMode]),
rgrover1 918:2b12b53101ea 134 uidIsSet(false),
rgrover1 918:2b12b53101ea 135 defaultUriDataLength(),
rgrover1 918:2b12b53101ea 136 defaultUriData(),
rgrover1 918:2b12b53101ea 137 defaultUrlPower(defaultAdvPowerLevelsIn[params.txPowerMode]),
rgrover1 918:2b12b53101ea 138 urlIsSet(false),
rgrover1 918:2b12b53101ea 139 tlmIsSet(false),
rgrover1 918:2b12b53101ea 140 lockedStateChar(UUID_LOCK_STATE_CHAR, &params.lockedState),
rgrover1 918:2b12b53101ea 141 lockChar(UUID_LOCK_CHAR, &params.lock),
rgrover1 918:2b12b53101ea 142 uriDataChar(UUID_URI_DATA_CHAR, params.uriData, 0, URI_DATA_MAX,
rgrover1 918:2b12b53101ea 143 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE),
rgrover1 918:2b12b53101ea 144 unlockChar(UUID_UNLOCK_CHAR, &params.lock),
rgrover1 918:2b12b53101ea 145 flagsChar(UUID_FLAGS_CHAR, &params.flags),
rgrover1 918:2b12b53101ea 146 advPowerLevelsChar(UUID_ADV_POWER_LEVELS_CHAR, &params.advPowerLevels),
rgrover1 918:2b12b53101ea 147 txPowerModeChar(UUID_TX_POWER_MODE_CHAR, &params.txPowerMode),
rgrover1 918:2b12b53101ea 148 beaconPeriodChar(UUID_BEACON_PERIOD_CHAR, &params.beaconPeriod),
rgrover1 918:2b12b53101ea 149 resetChar(UUID_RESET_CHAR, &resetFlag) {
rgrover1 918:2b12b53101ea 150 // set eddystone as not configured yet. Used to exit config before timeout if GATT services are written to.
rgrover1 918:2b12b53101ea 151 params.isConfigured = false;
rgrover1 918:2b12b53101ea 152
rgrover1 918:2b12b53101ea 153 lockChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::lockAuthorizationCallback);
rgrover1 918:2b12b53101ea 154 unlockChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::unlockAuthorizationCallback);
rgrover1 918:2b12b53101ea 155 uriDataChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::uriDataWriteAuthorizationCallback);
rgrover1 918:2b12b53101ea 156 flagsChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::basicAuthorizationCallback<uint8_t>);
rgrover1 918:2b12b53101ea 157 advPowerLevelsChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::basicAuthorizationCallback<PowerLevels_t>);
rgrover1 918:2b12b53101ea 158 txPowerModeChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::powerModeAuthorizationCallback);
rgrover1 918:2b12b53101ea 159 beaconPeriodChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::basicAuthorizationCallback<uint16_t>);
rgrover1 918:2b12b53101ea 160 resetChar.setWriteAuthorizationCallback(this, &EddystoneConfigService::basicAuthorizationCallback<uint8_t>);
rgrover1 918:2b12b53101ea 161
rgrover1 918:2b12b53101ea 162 static GattCharacteristic *charTable[] = {
rgrover1 918:2b12b53101ea 163 &lockedStateChar, &lockChar, &unlockChar, &uriDataChar,
rgrover1 918:2b12b53101ea 164 &flagsChar, &advPowerLevelsChar, &txPowerModeChar, &beaconPeriodChar, &resetChar
rgrover1 918:2b12b53101ea 165 };
rgrover1 918:2b12b53101ea 166
rgrover1 918:2b12b53101ea 167 GattService configService(UUID_URI_BEACON_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
rgrover1 918:2b12b53101ea 168
rgrover1 918:2b12b53101ea 169 ble.addService(configService);
rgrover1 918:2b12b53101ea 170 ble.onDataWritten(this, &EddystoneConfigService::onDataWrittenCallback);
rgrover1 918:2b12b53101ea 171 }
rgrover1 918:2b12b53101ea 172
rgrover1 918:2b12b53101ea 173 /**
rgrover1 918:2b12b53101ea 174 * @brief Start EddystoneConfig advertising. This function should be called
rgrover1 918:2b12b53101ea 175 * after the EddystoneConfig constructor and after all the frames have been added.
rgrover1 918:2b12b53101ea 176 *
rgrover1 918:2b12b53101ea 177 * @paramsP[in] resetToDefaultsFlag
rgrover1 918:2b12b53101ea 178 * Applies to the state of the 'paramsIn' parameter.
rgrover1 918:2b12b53101ea 179 * If true, it indicates that paramsIn is potentially
rgrover1 918:2b12b53101ea 180 * un-initialized, and default values should be used
rgrover1 918:2b12b53101ea 181 * instead. Otherwise, paramsIn overrides the defaults.
rgrover1 918:2b12b53101ea 182 */
rgrover1 918:2b12b53101ea 183 void start(bool resetToDefaultsFlag){
rgrover1 918:2b12b53101ea 184 INFO("reset to defaults flag = %d", resetToDefaultsFlag);
rgrover1 918:2b12b53101ea 185 if (!resetToDefaultsFlag && (params.uriDataLength > URI_DATA_MAX)) {
rgrover1 918:2b12b53101ea 186 INFO("Reset to Defaults triggered");
rgrover1 918:2b12b53101ea 187 resetToDefaultsFlag = true;
rgrover1 918:2b12b53101ea 188 }
rgrover1 918:2b12b53101ea 189
rgrover1 918:2b12b53101ea 190 if (resetToDefaultsFlag) {
rgrover1 918:2b12b53101ea 191 resetToDefaults();
rgrover1 918:2b12b53101ea 192 } else {
rgrover1 918:2b12b53101ea 193 updateCharacteristicValues();
rgrover1 918:2b12b53101ea 194 }
rgrover1 918:2b12b53101ea 195
rgrover1 918:2b12b53101ea 196 setupEddystoneConfigAdvertisements(); /* Setup advertising for the configService. */
rgrover1 918:2b12b53101ea 197 initSucceeded = true;
rgrover1 918:2b12b53101ea 198 }
rgrover1 918:2b12b53101ea 199
rgrover1 918:2b12b53101ea 200 /*
rgrover1 918:2b12b53101ea 201 * Check if eddystone initialized successfully
rgrover1 918:2b12b53101ea 202 */
rgrover1 918:2b12b53101ea 203 bool initSuccessfully(void) const {
rgrover1 918:2b12b53101ea 204 return initSucceeded;
rgrover1 918:2b12b53101ea 205 }
rgrover1 918:2b12b53101ea 206
rgrover1 918:2b12b53101ea 207 /*
rgrover1 918:2b12b53101ea 208 * @brief Function to update the default values for the TLM frame. Only applied if Reset Defaults is applied.
rgrover1 918:2b12b53101ea 209 *
rgrover1 918:2b12b53101ea 210 * @param[in] tlmVersionIn Version of the TLM frame being used
rgrover1 918:2b12b53101ea 211 * @param[in] advPeriodInMin how long between TLM frames being advertised, this is measured in minutes.
rgrover1 918:2b12b53101ea 212 *
rgrover1 918:2b12b53101ea 213 */
rgrover1 918:2b12b53101ea 214 void setDefaultTLMFrameData(uint8_t tlmVersionIn = 0, float advPeriodInSec = 60){
rgrover1 918:2b12b53101ea 215 DBG("Setting Default TLM Data, version = %d, advPeriodInMind= %f", tlmVersionIn, advPeriodInSec);
rgrover1 918:2b12b53101ea 216 defaultTlmVersion = tlmVersionIn;
rgrover1 918:2b12b53101ea 217 TlmBatteryVoltage = 0;
rgrover1 918:2b12b53101ea 218 TlmBeaconTemp = 0x8000;
rgrover1 918:2b12b53101ea 219 TlmPduCount = 0;
rgrover1 918:2b12b53101ea 220 TlmTimeSinceBoot = 0;
rgrover1 918:2b12b53101ea 221 defaultTlmAdvPeriod = advPeriodInSec;
rgrover1 918:2b12b53101ea 222 tlmIsSet = true; // flag to add this to eddystone service when config is done
rgrover1 918:2b12b53101ea 223 }
rgrover1 918:2b12b53101ea 224
rgrover1 918:2b12b53101ea 225 /*
rgrover1 918:2b12b53101ea 226 * @brief Function to update the default values for the URI frame. Only applied if Reset Defaults is applied.
rgrover1 918:2b12b53101ea 227 *
rgrover1 918:2b12b53101ea 228 * @param[in] uriIn url to advertise
rgrover1 918:2b12b53101ea 229 * @param[in] advPeriod how long to advertise the url for, measured in number of ADV frames.
rgrover1 918:2b12b53101ea 230 *
rgrover1 918:2b12b53101ea 231 */
rgrover1 918:2b12b53101ea 232 void setDefaultURIFrameData(const char *uriIn, float advPeriod = 1){
rgrover1 918:2b12b53101ea 233 DBG("Setting Default URI Data");
rgrover1 918:2b12b53101ea 234 // Set URL Frame
rgrover1 918:2b12b53101ea 235 EddystoneService::encodeURL(uriIn, defaultUriData, defaultUriDataLength); // encode URL to URL Formatting
rgrover1 918:2b12b53101ea 236 if (defaultUriDataLength > URI_DATA_MAX) {
rgrover1 918:2b12b53101ea 237 return;
rgrover1 918:2b12b53101ea 238 }
rgrover1 918:2b12b53101ea 239 INFO("\t URI input = %s : %d", uriIn, defaultUriDataLength);
rgrover1 918:2b12b53101ea 240 INFO("\t default URI = %s : %d ", defaultUriData, defaultUriDataLength );
rgrover1 918:2b12b53101ea 241 defaultUriAdvPeriod = advPeriod;
rgrover1 918:2b12b53101ea 242 urlIsSet = true; // flag to add this to eddystone service when config is done
rgrover1 918:2b12b53101ea 243 }
rgrover1 918:2b12b53101ea 244
rgrover1 918:2b12b53101ea 245 /*
rgrover1 918:2b12b53101ea 246 * @brief Function to update the default values for the UID frame. Only applied if Reset Defaults is applied.
rgrover1 918:2b12b53101ea 247 *
rgrover1 918:2b12b53101ea 248 * @param[in] namespaceID 10Byte Namespace ID
rgrover1 918:2b12b53101ea 249 * @param[in] instanceID 6Byte Instance ID
rgrover1 918:2b12b53101ea 250 * @param[in] advPeriod how long to advertise the URL for, measured in the number of adv frames.
rgrover1 918:2b12b53101ea 251 *
rgrover1 918:2b12b53101ea 252 */
rgrover1 918:2b12b53101ea 253 void setDefaultUIDFrameData(UIDNamespaceID_t *namespaceID, UIDInstanceID_t *instanceID, float advPeriod = 10){
rgrover1 918:2b12b53101ea 254 //Set UID frame
rgrover1 918:2b12b53101ea 255 DBG("Setting default UID Data");
rgrover1 918:2b12b53101ea 256 memcpy(defaultUidNamespaceID, namespaceID, UID_NAMESPACEID_SIZE);
rgrover1 918:2b12b53101ea 257 memcpy(defaultUidInstanceID, instanceID, UID_INSTANCEID_SIZE);
rgrover1 918:2b12b53101ea 258 defaultUidAdvPeriod = advPeriod;
rgrover1 918:2b12b53101ea 259 uidIsSet = true; // flag to add this to eddystone service when config is done
rgrover1 918:2b12b53101ea 260 }
rgrover1 918:2b12b53101ea 261
rgrover1 918:2b12b53101ea 262 /* Start out by advertising the configService for a limited time after
rgrover1 918:2b12b53101ea 263 * startup; and switch to the normal non-connectible beacon functionality
rgrover1 918:2b12b53101ea 264 * afterwards. */
rgrover1 918:2b12b53101ea 265 void setupEddystoneConfigAdvertisements() {
rgrover1 918:2b12b53101ea 266 const char DEVICE_NAME[] = "eddystone Config";
rgrover1 918:2b12b53101ea 267
rgrover1 918:2b12b53101ea 268 ble.clearAdvertisingPayload();
rgrover1 918:2b12b53101ea 269
rgrover1 918:2b12b53101ea 270 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
rgrover1 918:2b12b53101ea 271
rgrover1 918:2b12b53101ea 272 // UUID is in different order in the ADV frame (!)
rgrover1 918:2b12b53101ea 273 uint8_t reversedServiceUUID[sizeof(UUID_URI_BEACON_SERVICE)];
rgrover1 918:2b12b53101ea 274 for (unsigned int i = 0; i < sizeof(UUID_URI_BEACON_SERVICE); i++) {
rgrover1 918:2b12b53101ea 275 reversedServiceUUID[i] = UUID_URI_BEACON_SERVICE[sizeof(UUID_URI_BEACON_SERVICE) - i - 1];
rgrover1 918:2b12b53101ea 276 }
rgrover1 918:2b12b53101ea 277 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, reversedServiceUUID, sizeof(reversedServiceUUID));
rgrover1 918:2b12b53101ea 278 ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_TAG);
rgrover1 918:2b12b53101ea 279 ble.accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, reinterpret_cast<const uint8_t *>(&DEVICE_NAME), sizeof(DEVICE_NAME));
rgrover1 918:2b12b53101ea 280 ble.accumulateScanResponse(
rgrover1 918:2b12b53101ea 281 GapAdvertisingData::TX_POWER_LEVEL,
rgrover1 918:2b12b53101ea 282 reinterpret_cast<uint8_t *>(&defaultAdvPowerLevels[EddystoneConfigService::TX_POWER_MODE_LOW]),
rgrover1 918:2b12b53101ea 283 sizeof(uint8_t));
rgrover1 918:2b12b53101ea 284
rgrover1 918:2b12b53101ea 285 ble.setTxPower(radioPowerLevels[params.txPowerMode]);
rgrover1 918:2b12b53101ea 286 ble.setDeviceName(reinterpret_cast<const uint8_t *>(&DEVICE_NAME));
rgrover1 918:2b12b53101ea 287 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
rgrover1 918:2b12b53101ea 288 ble.setAdvertisingInterval(ADVERTISING_INTERVAL_MSEC);
rgrover1 918:2b12b53101ea 289 }
rgrover1 918:2b12b53101ea 290
rgrover1 918:2b12b53101ea 291 /*
rgrover1 918:2b12b53101ea 292 * This function actually impliments the Eddystone Beacon service. It can be called with the help of the wrapper function
rgrover1 918:2b12b53101ea 293 * to load saved config params, or it can be called explicitly to reset the eddystone beacon to hardcoded values on each reset.
rgrover1 918:2b12b53101ea 294 *
rgrover1 918:2b12b53101ea 295 */
rgrover1 918:2b12b53101ea 296 void setupEddystoneAdvertisements() {
rgrover1 918:2b12b53101ea 297 DBG("Switching Config -> adv");
rgrover1 918:2b12b53101ea 298 // Save params to storage
rgrover1 918:2b12b53101ea 299 extern void saveURIBeaconConfigParams(const Params_t *paramsP); /* forward declaration; necessary to avoid a circular dependency. */
rgrover1 918:2b12b53101ea 300 saveURIBeaconConfigParams(&params);
rgrover1 918:2b12b53101ea 301 INFO("Saved Params to Memory.")
rgrover1 918:2b12b53101ea 302 // Setup Eddystone Service
rgrover1 918:2b12b53101ea 303 static EddystoneService eddyServ(ble, params.beaconPeriod, radioPowerLevels[params.txPowerMode]);
rgrover1 918:2b12b53101ea 304 // Set configured frames (TLM,UID,URI...etc)
rgrover1 918:2b12b53101ea 305 if (params.tlmEnabled) {
rgrover1 918:2b12b53101ea 306 eddyServ.setTLMFrameData(params.tlmVersion, params.tlmBeaconPeriod);
rgrover1 918:2b12b53101ea 307 }
rgrover1 918:2b12b53101ea 308 if (params.uriEnabled) {
rgrover1 918:2b12b53101ea 309 eddyServ.setURLFrameEncodedData(params.advPowerLevels[params.txPowerMode], (const char *) params.uriData, params.uriDataLength, params.uriBeaconPeriod);
rgrover1 918:2b12b53101ea 310 }
rgrover1 918:2b12b53101ea 311 if (params.uidEnabled) {
rgrover1 918:2b12b53101ea 312 eddyServ.setUIDFrameData(params.advPowerLevels[params.txPowerMode],
rgrover1 918:2b12b53101ea 313 (uint8_t *)params.uidNamespaceID,
rgrover1 918:2b12b53101ea 314 (uint8_t *)params.uidInstanceID,
rgrover1 918:2b12b53101ea 315 params.uidBeaconPeriod);
rgrover1 918:2b12b53101ea 316 }
rgrover1 918:2b12b53101ea 317 // Start Advertising the eddystone service.
rgrover1 918:2b12b53101ea 318 eddyServ.start();
rgrover1 918:2b12b53101ea 319 }
rgrover1 918:2b12b53101ea 320
rgrover1 918:2b12b53101ea 321 private:
rgrover1 918:2b12b53101ea 322 /*
rgrover1 918:2b12b53101ea 323 * This callback is invoked when a GATT client attempts to modify any of the
rgrover1 918:2b12b53101ea 324 * characteristics of this service. Attempts to do so are also applied to
rgrover1 918:2b12b53101ea 325 * the internal state of this service object.
rgrover1 918:2b12b53101ea 326 */
rgrover1 918:2b12b53101ea 327 void onDataWrittenCallback(const GattWriteCallbackParams *writeParams) {
rgrover1 918:2b12b53101ea 328 uint16_t handle = writeParams->handle;
rgrover1 918:2b12b53101ea 329
rgrover1 918:2b12b53101ea 330 if (handle == lockChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 331 // Validated earlier
rgrover1 918:2b12b53101ea 332 memcpy(params.lock, writeParams->data, sizeof(Lock_t));
rgrover1 918:2b12b53101ea 333 // Set the state to be locked by the lock code (note: zeros are a valid lock)
rgrover1 918:2b12b53101ea 334 params.lockedState = true;
rgrover1 918:2b12b53101ea 335 INFO("Device Locked");
rgrover1 918:2b12b53101ea 336 } else if (handle == unlockChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 337 // Validated earlier
rgrover1 918:2b12b53101ea 338 params.lockedState = false;
rgrover1 918:2b12b53101ea 339 INFO("Device Unlocked");
rgrover1 918:2b12b53101ea 340 } else if (handle == uriDataChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 341 params.uriDataLength = writeParams->len;
rgrover1 918:2b12b53101ea 342 memset(params.uriData, 0x00, URI_DATA_MAX); // clear URI string
rgrover1 918:2b12b53101ea 343 memcpy(params.uriData, writeParams->data, writeParams->len); // set URI string
rgrover1 918:2b12b53101ea 344 params.uriEnabled = true;
rgrover1 918:2b12b53101ea 345 INFO("URI = %s, URILen = %d", writeParams->data, writeParams->len);
rgrover1 918:2b12b53101ea 346 } else if (handle == flagsChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 347 params.flags = *(writeParams->data);
rgrover1 918:2b12b53101ea 348 INFO("flagsChar = 0x%x", params.flags);
rgrover1 918:2b12b53101ea 349 } else if (handle == advPowerLevelsChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 350 memcpy(params.advPowerLevels, writeParams->data, sizeof(PowerLevels_t));
rgrover1 918:2b12b53101ea 351 INFO("PowerLevelsChar = %4x", params.advPowerLevels);
rgrover1 918:2b12b53101ea 352 } else if (handle == txPowerModeChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 353 params.txPowerMode = *(writeParams->data);
rgrover1 918:2b12b53101ea 354 INFO("TxPowerModeChar = %d", params.txPowerMode);
rgrover1 918:2b12b53101ea 355 } else if (handle == beaconPeriodChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 356 params.beaconPeriod = *((uint16_t *)(writeParams->data));
rgrover1 918:2b12b53101ea 357 INFO("BeaconPeriod = %d", params.beaconPeriod);
rgrover1 918:2b12b53101ea 358
rgrover1 918:2b12b53101ea 359 /* Re-map beaconPeriod to within permissible bounds if necessary. */
rgrover1 918:2b12b53101ea 360 if (params.beaconPeriod != 0) {
rgrover1 918:2b12b53101ea 361 bool paramsUpdated = false;
rgrover1 918:2b12b53101ea 362 if (params.beaconPeriod < ble.getMinAdvertisingInterval()) {
rgrover1 918:2b12b53101ea 363 params.beaconPeriod = ble.getMinAdvertisingInterval();
rgrover1 918:2b12b53101ea 364 paramsUpdated = true;
rgrover1 918:2b12b53101ea 365 } else if (params.beaconPeriod > ble.getMaxAdvertisingInterval()) {
rgrover1 918:2b12b53101ea 366 params.beaconPeriod = ble.getMaxAdvertisingInterval();
rgrover1 918:2b12b53101ea 367 paramsUpdated = true;
rgrover1 918:2b12b53101ea 368 }
rgrover1 918:2b12b53101ea 369 if (paramsUpdated) {
rgrover1 918:2b12b53101ea 370 ble.updateCharacteristicValue(beaconPeriodChar.getValueHandle(), reinterpret_cast<uint8_t *>(&params.beaconPeriod), sizeof(uint16_t));
rgrover1 918:2b12b53101ea 371 }
rgrover1 918:2b12b53101ea 372 }
rgrover1 918:2b12b53101ea 373 } else if (handle == resetChar.getValueHandle()) {
rgrover1 918:2b12b53101ea 374 INFO("Reset triggered from Config Service, resetting to defaults");
rgrover1 918:2b12b53101ea 375 resetToDefaults();
rgrover1 918:2b12b53101ea 376 }
rgrover1 918:2b12b53101ea 377 updateCharacteristicValues();
rgrover1 918:2b12b53101ea 378 params.isConfigured = true; // some configuration data has been passed, on disconnect switch to advertising mode.
rgrover1 918:2b12b53101ea 379 }
rgrover1 918:2b12b53101ea 380
rgrover1 918:2b12b53101ea 381 /*
rgrover1 918:2b12b53101ea 382 * Reset the default values.
rgrover1 918:2b12b53101ea 383 */
rgrover1 918:2b12b53101ea 384 void resetToDefaults(void) {
rgrover1 918:2b12b53101ea 385 INFO("Resetting to defaults");
rgrover1 918:2b12b53101ea 386 // General
rgrover1 918:2b12b53101ea 387 params.lockedState = false;
rgrover1 918:2b12b53101ea 388 memset(params.lock, 0, sizeof(Lock_t));
rgrover1 918:2b12b53101ea 389 params.flags = 0x10;
rgrover1 918:2b12b53101ea 390 memcpy(params.advPowerLevels, defaultAdvPowerLevels, sizeof(PowerLevels_t));
rgrover1 918:2b12b53101ea 391 params.txPowerMode = TX_POWER_MODE_LOW;
rgrover1 918:2b12b53101ea 392 params.beaconPeriod = (uint16_t) defaultUriAdvPeriod * 1000;
rgrover1 918:2b12b53101ea 393
rgrover1 918:2b12b53101ea 394 // TLM Frame
rgrover1 918:2b12b53101ea 395 params.tlmVersion = defaultTlmVersion;
rgrover1 918:2b12b53101ea 396 params.tlmBeaconPeriod = defaultTlmAdvPeriod;
rgrover1 918:2b12b53101ea 397 params.tlmEnabled = tlmIsSet;
rgrover1 918:2b12b53101ea 398
rgrover1 918:2b12b53101ea 399 // URL Frame
rgrover1 918:2b12b53101ea 400 memcpy(params.uriData, defaultUriData, URI_DATA_MAX);
rgrover1 918:2b12b53101ea 401 params.uriDataLength = defaultUriDataLength;
rgrover1 918:2b12b53101ea 402 params.uriBeaconPeriod = defaultUriAdvPeriod;
rgrover1 918:2b12b53101ea 403 params.uriEnabled = urlIsSet;
rgrover1 918:2b12b53101ea 404
rgrover1 918:2b12b53101ea 405 // UID Frame
rgrover1 918:2b12b53101ea 406 memcpy(params.uidNamespaceID, defaultUidNamespaceID, UID_NAMESPACEID_SIZE);
rgrover1 918:2b12b53101ea 407 memcpy(params.uidInstanceID, defaultUidInstanceID, UID_INSTANCEID_SIZE);
rgrover1 918:2b12b53101ea 408 params.uidBeaconPeriod = defaultUidAdvPeriod;
rgrover1 918:2b12b53101ea 409 params.uidEnabled = uidIsSet;
rgrover1 918:2b12b53101ea 410
rgrover1 918:2b12b53101ea 411 updateCharacteristicValues();
rgrover1 918:2b12b53101ea 412 }
rgrover1 918:2b12b53101ea 413
rgrover1 918:2b12b53101ea 414 /*
rgrover1 918:2b12b53101ea 415 * Internal helper function used to update the GATT database following any
rgrover1 918:2b12b53101ea 416 * change to the internal state of the service object.
rgrover1 918:2b12b53101ea 417 */
rgrover1 918:2b12b53101ea 418 void updateCharacteristicValues(void) {
rgrover1 918:2b12b53101ea 419 ble.updateCharacteristicValue(lockedStateChar.getValueHandle(), &params.lockedState, 1);
rgrover1 918:2b12b53101ea 420 ble.updateCharacteristicValue(uriDataChar.getValueHandle(), params.uriData, params.uriDataLength);
rgrover1 918:2b12b53101ea 421 ble.updateCharacteristicValue(flagsChar.getValueHandle(), &params.flags, 1);
rgrover1 918:2b12b53101ea 422 ble.updateCharacteristicValue(beaconPeriodChar.getValueHandle(),
rgrover1 918:2b12b53101ea 423 reinterpret_cast<uint8_t *>(&params.beaconPeriod), sizeof(uint16_t));
rgrover1 918:2b12b53101ea 424 ble.updateCharacteristicValue(txPowerModeChar.getValueHandle(), &params.txPowerMode, 1);
rgrover1 918:2b12b53101ea 425 ble.updateCharacteristicValue(advPowerLevelsChar.getValueHandle(),
rgrover1 918:2b12b53101ea 426 reinterpret_cast<uint8_t *>(params.advPowerLevels), sizeof(PowerLevels_t));
rgrover1 918:2b12b53101ea 427 }
rgrover1 918:2b12b53101ea 428
rgrover1 918:2b12b53101ea 429 private:
rgrover1 918:2b12b53101ea 430 void lockAuthorizationCallback(GattWriteAuthCallbackParams *authParams) {
rgrover1 918:2b12b53101ea 431 if (params.lockedState) {
rgrover1 918:2b12b53101ea 432 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION;
rgrover1 918:2b12b53101ea 433 } else if (authParams->len != sizeof(Lock_t)) {
rgrover1 918:2b12b53101ea 434 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_ATT_VAL_LENGTH;
rgrover1 918:2b12b53101ea 435 } else if (authParams->offset != 0) {
rgrover1 918:2b12b53101ea 436 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_OFFSET;
rgrover1 918:2b12b53101ea 437 } else {
rgrover1 918:2b12b53101ea 438 authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS;
rgrover1 918:2b12b53101ea 439 }
rgrover1 918:2b12b53101ea 440 }
rgrover1 918:2b12b53101ea 441
rgrover1 918:2b12b53101ea 442 void unlockAuthorizationCallback(GattWriteAuthCallbackParams *authParams) {
rgrover1 918:2b12b53101ea 443 if ((!params.lockedState) && (authParams->len == sizeof(Lock_t))) {
rgrover1 918:2b12b53101ea 444 authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS;
rgrover1 918:2b12b53101ea 445 } else if (authParams->len != sizeof(Lock_t)) {
rgrover1 918:2b12b53101ea 446 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_ATT_VAL_LENGTH;
rgrover1 918:2b12b53101ea 447 } else if (authParams->offset != 0) {
rgrover1 918:2b12b53101ea 448 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_OFFSET;
rgrover1 918:2b12b53101ea 449 } else if (memcmp(authParams->data, params.lock, sizeof(Lock_t)) != 0) {
rgrover1 918:2b12b53101ea 450 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION;
rgrover1 918:2b12b53101ea 451 } else {
rgrover1 918:2b12b53101ea 452 authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS;
rgrover1 918:2b12b53101ea 453 }
rgrover1 918:2b12b53101ea 454 }
rgrover1 918:2b12b53101ea 455
rgrover1 918:2b12b53101ea 456 void uriDataWriteAuthorizationCallback(GattWriteAuthCallbackParams *authParams) {
rgrover1 918:2b12b53101ea 457 if (params.lockedState) {
rgrover1 918:2b12b53101ea 458 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION;
rgrover1 918:2b12b53101ea 459 } else if (authParams->offset != 0) {
rgrover1 918:2b12b53101ea 460 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_OFFSET;
rgrover1 918:2b12b53101ea 461 } else {
rgrover1 918:2b12b53101ea 462 authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS;
rgrover1 918:2b12b53101ea 463 }
rgrover1 918:2b12b53101ea 464 }
rgrover1 918:2b12b53101ea 465
rgrover1 918:2b12b53101ea 466 void powerModeAuthorizationCallback(GattWriteAuthCallbackParams *authParams) {
rgrover1 918:2b12b53101ea 467 if (params.lockedState) {
rgrover1 918:2b12b53101ea 468 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION;
rgrover1 918:2b12b53101ea 469 } else if (authParams->len != sizeof(uint8_t)) {
rgrover1 918:2b12b53101ea 470 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_ATT_VAL_LENGTH;
rgrover1 918:2b12b53101ea 471 } else if (authParams->offset != 0) {
rgrover1 918:2b12b53101ea 472 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_OFFSET;
rgrover1 918:2b12b53101ea 473 } else if (*((uint8_t *)authParams->data) >= NUM_POWER_MODES) {
rgrover1 918:2b12b53101ea 474 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_WRITE_NOT_PERMITTED;
rgrover1 918:2b12b53101ea 475 } else {
rgrover1 918:2b12b53101ea 476 authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS;
rgrover1 918:2b12b53101ea 477 }
rgrover1 918:2b12b53101ea 478 }
rgrover1 918:2b12b53101ea 479
rgrover1 918:2b12b53101ea 480 template <typename T>
rgrover1 918:2b12b53101ea 481 void basicAuthorizationCallback(GattWriteAuthCallbackParams *authParams) {
rgrover1 918:2b12b53101ea 482 if (params.lockedState) {
rgrover1 918:2b12b53101ea 483 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INSUF_AUTHORIZATION;
rgrover1 918:2b12b53101ea 484 } else if (authParams->len != sizeof(T)) {
rgrover1 918:2b12b53101ea 485 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_ATT_VAL_LENGTH;
rgrover1 918:2b12b53101ea 486 } else if (authParams->offset != 0) {
rgrover1 918:2b12b53101ea 487 authParams->authorizationReply = AUTH_CALLBACK_REPLY_ATTERR_INVALID_OFFSET;
rgrover1 918:2b12b53101ea 488 } else {
rgrover1 918:2b12b53101ea 489 authParams->authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS;
rgrover1 918:2b12b53101ea 490 }
rgrover1 918:2b12b53101ea 491 }
rgrover1 918:2b12b53101ea 492
rgrover1 918:2b12b53101ea 493 BLEDevice &ble;
rgrover1 918:2b12b53101ea 494 Params_t &params;
rgrover1 918:2b12b53101ea 495 Ticker timeSinceBootTick;
rgrover1 918:2b12b53101ea 496 Timeout switchFrame;
rgrover1 918:2b12b53101ea 497 // Default value that is restored on reset
rgrover1 918:2b12b53101ea 498 PowerLevels_t &defaultAdvPowerLevels; // this goes into the advertising frames (radio power measured at 1m from device)
rgrover1 918:2b12b53101ea 499 PowerLevels_t &radioPowerLevels; // this configures the power levels of the radio
rgrover1 918:2b12b53101ea 500 uint8_t lockedState;
rgrover1 918:2b12b53101ea 501 bool initSucceeded;
rgrover1 918:2b12b53101ea 502 uint8_t resetFlag;
rgrover1 918:2b12b53101ea 503 bool switchFlag;
rgrover1 918:2b12b53101ea 504
rgrover1 918:2b12b53101ea 505 //UID Default value that is restored on reset
rgrover1 918:2b12b53101ea 506 UIDNamespaceID_t defaultUidNamespaceID;
rgrover1 918:2b12b53101ea 507 UIDInstanceID_t defaultUidInstanceID;
rgrover1 918:2b12b53101ea 508 float defaultUidAdvPeriod;
rgrover1 918:2b12b53101ea 509 int8_t defaultUidPower;
rgrover1 918:2b12b53101ea 510 uint16_t uidRFU;
rgrover1 918:2b12b53101ea 511 bool uidIsSet;
rgrover1 918:2b12b53101ea 512
rgrover1 918:2b12b53101ea 513 //URI Default value that is restored on reset
rgrover1 918:2b12b53101ea 514 uint8_t defaultUriDataLength;
rgrover1 918:2b12b53101ea 515 UriData_t defaultUriData;
rgrover1 918:2b12b53101ea 516 int8_t defaultUrlPower;
rgrover1 918:2b12b53101ea 517 float defaultUriAdvPeriod;
rgrover1 918:2b12b53101ea 518 bool urlIsSet;
rgrover1 918:2b12b53101ea 519
rgrover1 918:2b12b53101ea 520 //TLM Default value that is restored on reset
rgrover1 918:2b12b53101ea 521 uint8_t defaultTlmVersion;
rgrover1 918:2b12b53101ea 522 float defaultTlmAdvPeriod;
rgrover1 918:2b12b53101ea 523 volatile uint16_t TlmBatteryVoltage;
rgrover1 918:2b12b53101ea 524 volatile uint16_t TlmBeaconTemp;
rgrover1 918:2b12b53101ea 525 volatile uint32_t TlmPduCount;
rgrover1 918:2b12b53101ea 526 volatile uint32_t TlmTimeSinceBoot;
rgrover1 918:2b12b53101ea 527 bool tlmIsSet;
rgrover1 918:2b12b53101ea 528
rgrover1 918:2b12b53101ea 529 ReadOnlyGattCharacteristic<uint8_t> lockedStateChar;
rgrover1 918:2b12b53101ea 530 WriteOnlyGattCharacteristic<Lock_t> lockChar;
rgrover1 918:2b12b53101ea 531 GattCharacteristic uriDataChar;
rgrover1 918:2b12b53101ea 532 WriteOnlyGattCharacteristic<Lock_t> unlockChar;
rgrover1 918:2b12b53101ea 533 ReadWriteGattCharacteristic<uint8_t> flagsChar;
rgrover1 918:2b12b53101ea 534 ReadWriteGattCharacteristic<PowerLevels_t> advPowerLevelsChar;
rgrover1 918:2b12b53101ea 535 ReadWriteGattCharacteristic<uint8_t> txPowerModeChar;
rgrover1 918:2b12b53101ea 536 ReadWriteGattCharacteristic<uint16_t> beaconPeriodChar;
rgrover1 918:2b12b53101ea 537 WriteOnlyGattCharacteristic<uint8_t> resetChar;
rgrover1 918:2b12b53101ea 538 };
rgrover1 918:2b12b53101ea 539
rgrover1 918:2b12b53101ea 540 #endif // SERVICES_EDDYSTONE_BEACON_CONFIG_SERVICE_H_