Button initiated config service

Dependencies:   BLE_API_EddystoneConfigService_2 mbed nRF51822

Fork of BLE_EddystoneBeaconConfigService_3 by URIBeacon

Committer:
scottjenson
Date:
Mon Oct 12 21:18:21 2015 +0000
Revision:
68:f7f7ec038494
Parent:
67:345bc62c748d
support for button initiated config (for nRFgo usb board and Seeed)

Who changed what in which revision?

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