High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Tue Sep 29 09:54:18 2015 +0100
Revision:
830:a6ef72e0697a
Child:
831:47413688398a
Synchronized with git rev 1811f210
Author: Austin Blackstone
updated eddystone service and added config service.

Who changed what in which revision?

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