Bike service

Fork of BLE_API by Bluetooth Low Energy

Committer:
vcoubard
Date:
Mon Jan 11 08:51:32 2016 +0000
Revision:
1053:ec4a5b9b254e
Synchronized with git rev 13bf70b6
Author: Rohit Grover
Release 2.1.5
=============

A minor release to separate the concept of minlen and len in
GattCharacteristic. Also contains some improvements to documentation.

Who changed what in which revision?

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