From 6e85b53f92a4e9292601b04475cfd081f1865221 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:19:53 +0000 Subject: [PATCH 01/28] Uri Data must be between 0 and 18 bytes https://github.com/mbedmicro/BLE_API/issues/6 --- services/URIBeacon2Service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index bf5926b..074009f 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -342,7 +342,7 @@ private: } private: - static const size_t MAX_SIZEOF_SERVICE_DATA_PAYLOAD = 27; + static const size_t MAX_SIZEOF_SERVICE_DATA_PAYLOAD = 18; /* Uri Data must be between 0 and 18 bytes in length. */ static const size_t MAX_SIZE_URI_DATA_CHAR_VALUE = 48; private: From 25eebd68eff11b94913d03472682d01a4063d193 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:37:08 +0000 Subject: [PATCH 02/28] rename to effectiveTxPower --- services/URIBeacon2Service.h | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 074009f..06fc1af 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -64,7 +64,7 @@ public: uriDataLength(0), uriData(), flags(flagsIn), - effectivePower(effectiveTxPowerIn), + effectiveTxPower(effectiveTxPowerIn), powerLevels(), beaconPeriod(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(beaconPeriodIn)), lockedStateChar(lockedStateCharUUID, reinterpret_cast(&lockedState), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), @@ -92,10 +92,10 @@ public: configure(); if (initSucceeded) { /* Preserve the originals to be able to reset() upon request. */ - memcpy(originalURIData, uriDataIn, MAX_SIZE_URI_DATA_CHAR_VALUE); - originalFlags = flagsIn; - originalEffectiveTxPower = effectiveTxPowerIn; - originalBeaconPeriod = beaconPeriodIn; + memcpy(defaultURIData, uriDataIn, MAX_SIZE_URI_DATA_CHAR_VALUE); + defaultFlags = flagsIn; + defaultEffectiveTxPower = effectiveTxPowerIn; + defaultBeaconPeriod = beaconPeriodIn; } GattCharacteristic *charTable[] = {&lockedStateChar, &uriDataChar, &flagsChar, &txPowerLevelsChar, &beaconPeriodChar, &resetChar}; @@ -147,7 +147,7 @@ public: * Set the effective power mode from one of the values in the powerLevels tables. */ void useTxPowerMode(TXPowerModes_t mode) { - effectivePower = powerLevels[mode]; + effectiveTxPower = powerLevels[mode]; configure(); } @@ -172,7 +172,7 @@ private: serviceDataPayload[payloadIndex++] = BEACON_UUID[0]; serviceDataPayload[payloadIndex++] = BEACON_UUID[1]; serviceDataPayload[payloadIndex++] = flags; - serviceDataPayload[payloadIndex++] = effectivePower; + serviceDataPayload[payloadIndex++] = effectiveTxPower; const char *urlData = reinterpret_cast(uriData); size_t sizeofURLData = uriDataLength; @@ -183,7 +183,7 @@ private: ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceDataPayload, encodedBytes + 4); ble.setAdvertisingInterval(beaconPeriod); - ble.setTxPower(effectivePower); + ble.setTxPower(effectiveTxPower); } size_t encodeURISchemePrefix(const char *&urldata, size_t &sizeofURLData) { @@ -309,18 +309,18 @@ private: beaconPeriod = *((uint16_t *)(params->data)); } } else if (params->charHandle == resetChar.getValueAttribute().getHandle()) { - resetOriginals(); + resetDefaults(); } configure(); ble.setAdvertisingPayload(); } - void resetOriginals(void) { - memcpy(uriData, originalURIData, MAX_SIZE_URI_DATA_CHAR_VALUE); + void resetDefaults(void) { + memcpy(uriData, defaultURIData, MAX_SIZE_URI_DATA_CHAR_VALUE); memset(powerLevels, 0, sizeof(powerLevels)); - flags = originalFlags; - effectivePower = originalEffectiveTxPower; - beaconPeriod = originalBeaconPeriod; + flags = defaultFlags; + effectiveTxPower = defaultEffectiveTxPower; + beaconPeriod = defaultBeaconPeriod; ble.updateCharacteristicValue(uriDataChar.getValueAttribute().getHandle(), uriData, uriDataLength); ble.updateCharacteristicValue(flagsChar.getValueAttribute().getHandle(), &flags, 1 /* size */); @@ -356,15 +356,15 @@ private: uint16_t uriDataLength; uint8_t uriData[MAX_SIZE_URI_DATA_CHAR_VALUE]; uint8_t flags; - int8_t effectivePower; + int8_t effectiveTxPower; int8_t powerLevels[NUM_POWER_MODES]; uint16_t beaconPeriod; bool resetFlag; - uint8_t originalURIData[MAX_SIZE_URI_DATA_CHAR_VALUE]; - uint8_t originalFlags; - int8_t originalEffectiveTxPower; - uint16_t originalBeaconPeriod; + uint8_t defaultURIData[MAX_SIZE_URI_DATA_CHAR_VALUE]; + uint8_t defaultFlags; + int8_t defaultEffectiveTxPower; + uint16_t defaultBeaconPeriod; GattCharacteristic lockedStateChar; GattCharacteristic uriDataChar; From eaf31a3941253a6f439b259a93e4826797706f99 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:38:10 +0000 Subject: [PATCH 03/28] beaconPeriod should be converted to adv_duration_units only before calling setAdvertisingInterval() --- services/URIBeacon2Service.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 06fc1af..c782f9d 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -66,7 +66,7 @@ public: flags(flagsIn), effectiveTxPower(effectiveTxPowerIn), powerLevels(), - beaconPeriod(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(beaconPeriodIn)), + beaconPeriod(beaconPeriodIn), lockedStateChar(lockedStateCharUUID, reinterpret_cast(&lockedState), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), uriDataChar(uriDataCharUUID, uriData, @@ -182,7 +182,7 @@ private: ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceDataPayload, encodedBytes + 4); - ble.setAdvertisingInterval(beaconPeriod); + ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(beaconPeriod)); ble.setTxPower(effectiveTxPower); } From fe765b0191f867e6846206d53d9077abe9c2db4b Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:38:29 +0000 Subject: [PATCH 04/28] remove block comment for onDataWritten. --- services/URIBeacon2Service.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index c782f9d..005bd9b 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -264,11 +264,6 @@ private: return encodedBytes; } - /** - * This callback allows the DFU service to receive the initial trigger to - * handover control to the bootloader; but first the application is given a - * chance to clean up. - */ virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) { if (params->charHandle == uriDataChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the uriData characteristic. */ From e5bd170d5d511689e20dc7480d2b7b64bce3af70 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:39:03 +0000 Subject: [PATCH 05/28] drop virtual from onDataWritten() --- services/URIBeacon2Service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 005bd9b..dc2db11 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -264,7 +264,7 @@ private: return encodedBytes; } - virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) { + void onDataWritten(const GattCharacteristicWriteCBParams *params) { if (params->charHandle == uriDataChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the uriData characteristic. */ /* Restore GATT database with previous value. */ From dc40eb8113994add4614c6625b49f9433a2c7f92 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:41:56 +0000 Subject: [PATCH 06/28] Add a comment for MAX_SIZE_URI_DATA_CHAR_VALUE --- services/URIBeacon2Service.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index dc2db11..3cbb2f0 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -338,7 +338,8 @@ private: private: static const size_t MAX_SIZEOF_SERVICE_DATA_PAYLOAD = 18; /* Uri Data must be between 0 and 18 bytes in length. */ - static const size_t MAX_SIZE_URI_DATA_CHAR_VALUE = 48; + static const size_t MAX_SIZE_URI_DATA_CHAR_VALUE = 48; /* This is chosen arbitrarily. It should be large enough + * to hold any reasonable uncompressed URI. */ private: BLEDevice &ble; From da859491138bda24548d544007c5c49b545052c1 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:42:13 +0000 Subject: [PATCH 07/28] add saveDefaults() --- services/URIBeacon2Service.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 3cbb2f0..7c157bc 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -91,11 +91,7 @@ public: configure(); if (initSucceeded) { - /* Preserve the originals to be able to reset() upon request. */ - memcpy(defaultURIData, uriDataIn, MAX_SIZE_URI_DATA_CHAR_VALUE); - defaultFlags = flagsIn; - defaultEffectiveTxPower = effectiveTxPowerIn; - defaultBeaconPeriod = beaconPeriodIn; + saveDefaults(); } GattCharacteristic *charTable[] = {&lockedStateChar, &uriDataChar, &flagsChar, &txPowerLevelsChar, &beaconPeriodChar, &resetChar}; @@ -310,6 +306,14 @@ private: ble.setAdvertisingPayload(); } + /* Preserve the defaults to be able to reset() upon request. */ + void saveDefaults(void) { + memcpy(defaultURIData, uriData, MAX_SIZE_URI_DATA_CHAR_VALUE); + defaultFlags = flags; + defaultEffectiveTxPower = effectiveTxPower; + defaultBeaconPeriod = beaconPeriod; + } + void resetDefaults(void) { memcpy(uriData, defaultURIData, MAX_SIZE_URI_DATA_CHAR_VALUE); memset(powerLevels, 0, sizeof(powerLevels)); From c9fbe1f4bab78c502cd932d3571788919c72503c Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:45:18 +0000 Subject: [PATCH 08/28] white space diffs. (uncrustified) --- services/URIBeacon2Service.h | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 7c157bc..367cade 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -19,9 +19,9 @@ #include "BLEDevice.h" -#define UUID_INITIALIZER_LIST(FIRST, SECOND) { \ - 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ - 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ +#define UUID_INITIALIZER_LIST(FIRST, SECOND) { \ + 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ + 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ } const uint8_t URIBeacon2ControlServiceUUID[] = UUID_INITIALIZER_LIST(0x20, 0x80); const uint8_t lockedStateCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x81); @@ -164,15 +164,15 @@ private: void configure(void) { const uint8_t BEACON_UUID[] = {0xD8, 0xFE}; - payloadIndex = 0; + payloadIndex = 0; serviceDataPayload[payloadIndex++] = BEACON_UUID[0]; serviceDataPayload[payloadIndex++] = BEACON_UUID[1]; serviceDataPayload[payloadIndex++] = flags; serviceDataPayload[payloadIndex++] = effectiveTxPower; - const char *urlData = reinterpret_cast(uriData); - size_t sizeofURLData = uriDataLength; - size_t encodedBytes = encodeURISchemePrefix(urlData, sizeofURLData) + encodeURI(urlData, sizeofURLData); + const char *urlData = reinterpret_cast(uriData); + size_t sizeofURLData = uriDataLength; + size_t encodedBytes = encodeURISchemePrefix(urlData, sizeofURLData) + encodeURI(urlData, sizeofURLData); ble.clearAdvertisingPayload(); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, BEACON_UUID, sizeof(BEACON_UUID)); @@ -191,15 +191,15 @@ private: "urn:uuid:" }; - size_t encodedBytes = 0; + size_t encodedBytes = 0; const size_t NUM_PREFIXES = sizeof(prefixes) / sizeof(char *); for (unsigned i = 0; i < NUM_PREFIXES; i++) { size_t prefixLen = strlen(prefixes[i]); if (strncmp(urldata, prefixes[i], prefixLen) == 0) { serviceDataPayload[payloadIndex++] = i; - encodedBytes = 1; + encodedBytes = 1; - urldata += prefixLen; + urldata += prefixLen; sizeofURLData -= prefixLen; break; } @@ -346,32 +346,32 @@ private: * to hold any reasonable uncompressed URI. */ private: - BLEDevice &ble; + BLEDevice &ble; - size_t payloadIndex; - uint8_t serviceDataPayload[MAX_SIZEOF_SERVICE_DATA_PAYLOAD]; - bool initSucceeded; + size_t payloadIndex; + uint8_t serviceDataPayload[MAX_SIZEOF_SERVICE_DATA_PAYLOAD]; + bool initSucceeded; - bool lockedState; - uint16_t uriDataLength; - uint8_t uriData[MAX_SIZE_URI_DATA_CHAR_VALUE]; - uint8_t flags; - int8_t effectiveTxPower; - int8_t powerLevels[NUM_POWER_MODES]; - uint16_t beaconPeriod; - bool resetFlag; + bool lockedState; + uint16_t uriDataLength; + uint8_t uriData[MAX_SIZE_URI_DATA_CHAR_VALUE]; + uint8_t flags; + int8_t effectiveTxPower; + int8_t powerLevels[NUM_POWER_MODES]; + uint16_t beaconPeriod; + bool resetFlag; - uint8_t defaultURIData[MAX_SIZE_URI_DATA_CHAR_VALUE]; - uint8_t defaultFlags; - int8_t defaultEffectiveTxPower; - uint16_t defaultBeaconPeriod; + uint8_t defaultURIData[MAX_SIZE_URI_DATA_CHAR_VALUE]; + uint8_t defaultFlags; + int8_t defaultEffectiveTxPower; + uint16_t defaultBeaconPeriod; - GattCharacteristic lockedStateChar; - GattCharacteristic uriDataChar; - GattCharacteristic flagsChar; - GattCharacteristic txPowerLevelsChar; - GattCharacteristic beaconPeriodChar; - GattCharacteristic resetChar; + GattCharacteristic lockedStateChar; + GattCharacteristic uriDataChar; + GattCharacteristic flagsChar; + GattCharacteristic txPowerLevelsChar; + GattCharacteristic beaconPeriodChar; + GattCharacteristic resetChar; }; #endif /* #ifndef __BLE_URI_BEACON_2_SERVICE_H__*/ From 94cb946fc87b58083d7e0ffd0145d00071ae4dc2 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:50:20 +0000 Subject: [PATCH 09/28] raname to URIBeaconConfigService. --- services/URIBeacon2Service.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 367cade..577ffc5 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __BLE_URI_BEACON_2_SERVICE_H__ -#define __BLE_URI_BEACON_2_SERVICE_H__ +#ifndef __BLE_URI_BEACON_CONFIG_SERVICE_H__ +#define __BLE_URI_BEACON_CONFIG_SERVICE_H__ #include "BLEDevice.h" @@ -31,7 +31,7 @@ const uint8_t txPowerLevelsCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x86) const uint8_t beaconPeriodCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x88); const uint8_t resetCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x89); -class URIBeacon2Service { +class URIBeaconConfigService { public: enum TXPowerModes_t { TX_POWER_MODE_LOWEST = 0, @@ -55,7 +55,7 @@ public: * transmitted. A value of zero disables UriBeacon * transmissions. */ - URIBeacon2Service(BLEDevice &bleIn, const char *uriDataIn, uint8_t flagsIn = 0, int8_t effectiveTxPowerIn = 0, uint16_t beaconPeriodIn = 1000) : + URIBeaconConfigService(BLEDevice &bleIn, const char *uriDataIn, uint8_t flagsIn = 0, int8_t effectiveTxPowerIn = 0, uint16_t beaconPeriodIn = 1000) : ble(bleIn), payloadIndex(0), serviceDataPayload(), @@ -98,7 +98,7 @@ public: GattService beaconControlService(URIBeacon2ControlServiceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); ble.addService(beaconControlService); - ble.onDataWritten(this, &URIBeacon2Service::onDataWritten); + ble.onDataWritten(this, &URIBeaconConfigService::onDataWritten); } bool configuredSuccessfully(void) const { @@ -374,4 +374,4 @@ private: GattCharacteristic resetChar; }; -#endif /* #ifndef __BLE_URI_BEACON_2_SERVICE_H__*/ +#endif /* #ifndef __BLE_URI_BEACON_CONFIG_SERVICE_H__*/ From 4163b0d2d435775818973a17ced617b149ac8c95 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:50:43 +0000 Subject: [PATCH 10/28] fix minor typo in a comment. --- services/URIBeacon2Service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/URIBeacon2Service.h b/services/URIBeacon2Service.h index 577ffc5..1e0b6fd 100644 --- a/services/URIBeacon2Service.h +++ b/services/URIBeacon2Service.h @@ -44,7 +44,7 @@ public: /** * @param[ref] ble * BLEDevice object for the underlying controller. - * @param[in] urldata + * @param[in] uridata * URI as a null-terminated string. * @param[in] flagsIn * UriBeacon Flags. From 3f856e0c4e982700f805172cace30f4d0fe67034 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 08:51:10 +0000 Subject: [PATCH 11/28] rename to URIBeaconConfig.h --- services/{URIBeacon2Service.h => URIBeaconConfigService.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename services/{URIBeacon2Service.h => URIBeaconConfigService.h} (100%) diff --git a/services/URIBeacon2Service.h b/services/URIBeaconConfigService.h similarity index 100% rename from services/URIBeacon2Service.h rename to services/URIBeaconConfigService.h From 076ade55a416675dd6b9d9c9bffb76d74b0220d1 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 09:16:26 +0000 Subject: [PATCH 12/28] rename configure() to configureGAP(); and remove duplication of this call from resetDefaults(). --- services/URIBeaconConfigService.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 1e0b6fd..257f499 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -89,7 +89,7 @@ public: } strcpy(reinterpret_cast(uriData), uriDataIn); - configure(); + configureGAP(); if (initSucceeded) { saveDefaults(); } @@ -129,7 +129,7 @@ public: */ void setFlags(uint8_t flagsIn) { flags = flagsIn; - configure(); + configureGAP(); } /** @@ -144,7 +144,7 @@ public: */ void useTxPowerMode(TXPowerModes_t mode) { effectiveTxPower = powerLevels[mode]; - configure(); + configureGAP(); } /** @@ -154,14 +154,14 @@ public: */ void setBeaconPeriod(uint16_t beaconPeriodIn) { beaconPeriod = beaconPeriodIn; - configure(); + configureGAP(); } private: /** * Setup the advertisement payload and GAP settings. */ - void configure(void) { + void configureGAP(void) { const uint8_t BEACON_UUID[] = {0xD8, 0xFE}; payloadIndex = 0; @@ -302,7 +302,7 @@ private: } else if (params->charHandle == resetChar.getValueAttribute().getHandle()) { resetDefaults(); } - configure(); + configureGAP(); ble.setAdvertisingPayload(); } @@ -324,8 +324,6 @@ private: ble.updateCharacteristicValue(uriDataChar.getValueAttribute().getHandle(), uriData, uriDataLength); ble.updateCharacteristicValue(flagsChar.getValueAttribute().getHandle(), &flags, 1 /* size */); ble.updateCharacteristicValue(beaconPeriodChar.getValueAttribute().getHandle(), reinterpret_cast(&beaconPeriod), sizeof(uint16_t)); - - configure(); } private: From bb041bbb108e10481e5165bef91f5d90174b7584 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 09:34:00 +0000 Subject: [PATCH 13/28] add helper functions to update characteristics. --- services/URIBeaconConfigService.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 257f499..307ae83 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -130,6 +130,7 @@ public: void setFlags(uint8_t flagsIn) { flags = flagsIn; configureGAP(); + updateFlagsCharacteristic(); } /** @@ -155,6 +156,7 @@ public: void setBeaconPeriod(uint16_t beaconPeriodIn) { beaconPeriod = beaconPeriodIn; configureGAP(); + updateBeaconPeriodCharacteristic(); } private: @@ -264,7 +266,7 @@ private: if (params->charHandle == uriDataChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the uriData characteristic. */ /* Restore GATT database with previous value. */ - ble.updateCharacteristicValue(uriDataChar.getValueAttribute().getHandle(), uriData, uriDataLength); + updateURIDataCharacteristic(); return; } @@ -278,7 +280,7 @@ private: } else if (params->charHandle == flagsChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the characteristic. */ /* Restore GATT database with previous value. */ - ble.updateCharacteristicValue(flagsChar.getValueAttribute().getHandle(), &flags, 1 /* size */); + updateFlagsCharacteristic(); return; } else { flags = *(params->data); @@ -294,7 +296,7 @@ private: } else if (params->charHandle == beaconPeriodChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the characteristic. */ /* Restore GATT database with previous value. */ - ble.updateCharacteristicValue(beaconPeriodChar.getValueAttribute().getHandle(), reinterpret_cast(&beaconPeriod), sizeof(uint16_t)); + updateBeaconPeriodCharacteristic(); return; } else { beaconPeriod = *((uint16_t *)(params->data)); @@ -321,8 +323,24 @@ private: effectiveTxPower = defaultEffectiveTxPower; beaconPeriod = defaultBeaconPeriod; + updateGATT(); + } + + void updateGATT(void) { + updateURIDataCharacteristic(); + updateFlagsCharacteristic(); + updateBeaconPeriodCharacteristic(); + } + + void updateURIDataCharacteristic(void) { ble.updateCharacteristicValue(uriDataChar.getValueAttribute().getHandle(), uriData, uriDataLength); + } + + void updateFlagsCharacteristic(void) { ble.updateCharacteristicValue(flagsChar.getValueAttribute().getHandle(), &flags, 1 /* size */); + } + + void updateBeaconPeriodCharacteristic(void) { ble.updateCharacteristicValue(beaconPeriodChar.getValueAttribute().getHandle(), reinterpret_cast(&beaconPeriod), sizeof(uint16_t)); } From 19f5054adfa73f777df60ddd42297833a1a04e83 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 10:57:36 +0000 Subject: [PATCH 14/28] no need to save defaults; they are implicit. --- services/URIBeaconConfigService.h | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 307ae83..19eb5ed 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -90,9 +90,6 @@ public: strcpy(reinterpret_cast(uriData), uriDataIn); configureGAP(); - if (initSucceeded) { - saveDefaults(); - } GattCharacteristic *charTable[] = {&lockedStateChar, &uriDataChar, &flagsChar, &txPowerLevelsChar, &beaconPeriodChar, &resetChar}; GattService beaconControlService(URIBeacon2ControlServiceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); @@ -308,20 +305,13 @@ private: ble.setAdvertisingPayload(); } - /* Preserve the defaults to be able to reset() upon request. */ - void saveDefaults(void) { - memcpy(defaultURIData, uriData, MAX_SIZE_URI_DATA_CHAR_VALUE); - defaultFlags = flags; - defaultEffectiveTxPower = effectiveTxPower; - defaultBeaconPeriod = beaconPeriod; - } - void resetDefaults(void) { - memcpy(uriData, defaultURIData, MAX_SIZE_URI_DATA_CHAR_VALUE); + memset(uriData, 0, MAX_SIZE_URI_DATA_CHAR_VALUE); + uriDataLength = 0; memset(powerLevels, 0, sizeof(powerLevels)); - flags = defaultFlags; - effectiveTxPower = defaultEffectiveTxPower; - beaconPeriod = defaultBeaconPeriod; + flags = 0; + effectiveTxPower = 0; + beaconPeriod = 0; updateGATT(); } @@ -377,11 +367,6 @@ private: uint16_t beaconPeriod; bool resetFlag; - uint8_t defaultURIData[MAX_SIZE_URI_DATA_CHAR_VALUE]; - uint8_t defaultFlags; - int8_t defaultEffectiveTxPower; - uint16_t defaultBeaconPeriod; - GattCharacteristic lockedStateChar; GattCharacteristic uriDataChar; GattCharacteristic flagsChar; From 0c38a1e8ef00c3c7e44759db3923675dba998e68 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 11:01:20 +0000 Subject: [PATCH 15/28] fast path for encodeURISchemePrefix() if sizeofURLData is 0 --- services/URIBeaconConfigService.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 19eb5ed..04f71f1 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -182,6 +182,10 @@ private: } size_t encodeURISchemePrefix(const char *&urldata, size_t &sizeofURLData) { + if (!sizeofURLData) { + return 0; + } + const char *prefixes[] = { "http://www.", "https://www.", From bca072e3ac69a1005810a9e28fe172d8e6a34b60 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 11:07:30 +0000 Subject: [PATCH 16/28] add updateLockedStateCharacteristic() --- services/URIBeaconConfigService.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 04f71f1..947cc13 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -316,16 +316,22 @@ private: flags = 0; effectiveTxPower = 0; beaconPeriod = 0; + lockedState = false; updateGATT(); } void updateGATT(void) { + updateLockedStateCharacteristic(); updateURIDataCharacteristic(); updateFlagsCharacteristic(); updateBeaconPeriodCharacteristic(); } + void updateLockedStateCharacteristic(void) { + ble.updateCharacteristicValue(lockedStateChar.getValueAttribute().getHandle(), reinterpret_cast(&lockedState), sizeof(lockedState)); + } + void updateURIDataCharacteristic(void) { ble.updateCharacteristicValue(uriDataChar.getValueAttribute().getHandle(), uriData, uriDataLength); } From 8491673e7d078e32ecdcb0ab0668c83f7d7caab3 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 11:14:37 +0000 Subject: [PATCH 17/28] fixed characteristic properties to match spec. --- services/URIBeaconConfigService.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 947cc13..d006361 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -68,11 +68,8 @@ public: powerLevels(), beaconPeriod(beaconPeriodIn), lockedStateChar(lockedStateCharUUID, reinterpret_cast(&lockedState), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), - uriDataChar(uriDataCharUUID, - uriData, - MAX_SIZE_URI_DATA_CHAR_VALUE, - MAX_SIZE_URI_DATA_CHAR_VALUE, - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE), + uriDataChar(uriDataCharUUID, uriData, MAX_SIZE_URI_DATA_CHAR_VALUE, MAX_SIZE_URI_DATA_CHAR_VALUE, + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), flagsChar(flagsCharUUID, &flags, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), txPowerLevelsChar(txPowerLevelsCharUUID, reinterpret_cast(powerLevels), @@ -81,8 +78,7 @@ public: GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), beaconPeriodChar(beaconPeriodCharUUID, reinterpret_cast(&beaconPeriod), 2, 2, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), - resetChar(resetCharUUID, reinterpret_cast(&resetFlag), 1, 1, - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE) + resetChar(resetCharUUID, reinterpret_cast(&resetFlag), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) { if ((uriDataIn == NULL) || ((uriDataLength = strlen(uriDataIn)) == 0) || (uriDataLength > MAX_SIZE_URI_DATA_CHAR_VALUE)) { return; From 9168068e568915b24e05c4a6bcfe499e8d34b492 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 11:19:57 +0000 Subject: [PATCH 18/28] re-organized code within resetDefaults() --- services/URIBeaconConfigService.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index d006361..6508492 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -306,13 +306,13 @@ private: } void resetDefaults(void) { - memset(uriData, 0, MAX_SIZE_URI_DATA_CHAR_VALUE); + lockedState = false; uriDataLength = 0; - memset(powerLevels, 0, sizeof(powerLevels)); + memset(uriData, 0, MAX_SIZE_URI_DATA_CHAR_VALUE); flags = 0; effectiveTxPower = 0; + memset(powerLevels, 0, sizeof(powerLevels)); beaconPeriod = 0; - lockedState = false; updateGATT(); } From d3cc9ed912f5acc1b55e901c16149ddb0fedbcbb Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 12:47:31 +0000 Subject: [PATCH 19/28] white space diffs. --- services/URIBeaconConfigService.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 6508492..81b4e6e 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -55,7 +55,11 @@ public: * transmitted. A value of zero disables UriBeacon * transmissions. */ - URIBeaconConfigService(BLEDevice &bleIn, const char *uriDataIn, uint8_t flagsIn = 0, int8_t effectiveTxPowerIn = 0, uint16_t beaconPeriodIn = 1000) : + URIBeaconConfigService(BLEDevice &bleIn, + const char *uriDataIn, + uint8_t flagsIn = 0, + int8_t effectiveTxPowerIn = 0, + uint16_t beaconPeriodIn = 1000) : ble(bleIn), payloadIndex(0), serviceDataPayload(), From 13ed67ec1ecfb5d884b052803418cf5aee4170b3 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 12:50:17 +0000 Subject: [PATCH 20/28] add txPowerMode characteristic. --- services/URIBeaconConfigService.h | 46 ++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 81b4e6e..4ac85d8 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -28,6 +28,7 @@ const uint8_t lockedStateCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x81) const uint8_t uriDataCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x84); const uint8_t flagsCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x85); const uint8_t txPowerLevelsCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x86); +const uint8_t txPowerModeCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x87); const uint8_t beaconPeriodCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x88); const uint8_t resetCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x89); @@ -48,18 +49,21 @@ public: * URI as a null-terminated string. * @param[in] flagsIn * UriBeacon Flags. - * @param[in] effectiveTxPowerIn - * UriBeacon Tx Power Level in dBm. + * @param[in] powerLevels[] + * Table of UriBeacon Tx Power Levels in dBm. + * @param[in] powerMode + * Currently effective power mode. * @param[in] beaconPeriodIn * The period in milliseconds that a UriBeacon packet is * transmitted. A value of zero disables UriBeacon * transmissions. */ - URIBeaconConfigService(BLEDevice &bleIn, - const char *uriDataIn, - uint8_t flagsIn = 0, - int8_t effectiveTxPowerIn = 0, - uint16_t beaconPeriodIn = 1000) : + URIBeaconConfigService(BLEDevice &bleIn, + const char *uriDataIn, + uint8_t flagsIn = 0, + const int8_t powerLevelsIn[NUM_POWER_MODES] = NULL, + TXPowerModes_t powerModeIn = TX_POWER_MODE_LOW, + uint16_t beaconPeriodIn = 1000) : ble(bleIn), payloadIndex(0), serviceDataPayload(), @@ -68,7 +72,6 @@ public: uriDataLength(0), uriData(), flags(flagsIn), - effectiveTxPower(effectiveTxPowerIn), powerLevels(), beaconPeriod(beaconPeriodIn), lockedStateChar(lockedStateCharUUID, reinterpret_cast(&lockedState), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), @@ -80,6 +83,8 @@ public: NUM_POWER_MODES * sizeof(int8_t), NUM_POWER_MODES * sizeof(int8_t), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), + txPowerModeChar(txPowerModeCharUUID, reinterpret_cast(&txPowerMode), sizeof(uint8_t), sizeof(uint8_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), beaconPeriodChar(beaconPeriodCharUUID, reinterpret_cast(&beaconPeriod), 2, 2, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), resetChar(resetCharUUID, reinterpret_cast(&resetFlag), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) @@ -89,6 +94,11 @@ public: } strcpy(reinterpret_cast(uriData), uriDataIn); + if (powerModeIn != NULL) { + memcpy(powerLevels, powerLevelsIn, sizeof(powerLevels)); + updateTxPowerLevelsCharacteristic(); + } + configureGAP(); GattCharacteristic *charTable[] = {&lockedStateChar, &uriDataChar, &flagsChar, &txPowerLevelsChar, &beaconPeriodChar, &resetChar}; @@ -141,8 +151,9 @@ public: * Set the effective power mode from one of the values in the powerLevels tables. */ void useTxPowerMode(TXPowerModes_t mode) { - effectiveTxPower = powerLevels[mode]; + txPowerMode = mode; configureGAP(); + updateTxPowerModeCharacteristic(); } /** @@ -167,7 +178,7 @@ private: serviceDataPayload[payloadIndex++] = BEACON_UUID[0]; serviceDataPayload[payloadIndex++] = BEACON_UUID[1]; serviceDataPayload[payloadIndex++] = flags; - serviceDataPayload[payloadIndex++] = effectiveTxPower; + serviceDataPayload[payloadIndex++] = powerLevels[txPowerMode]; const char *urlData = reinterpret_cast(uriData); size_t sizeofURLData = uriDataLength; @@ -178,7 +189,7 @@ private: ble.accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, serviceDataPayload, encodedBytes + 4); ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(beaconPeriod)); - ble.setTxPower(effectiveTxPower); + ble.setTxPower(powerLevels[txPowerMode]); } size_t encodeURISchemePrefix(const char *&urldata, size_t &sizeofURLData) { @@ -314,8 +325,8 @@ private: uriDataLength = 0; memset(uriData, 0, MAX_SIZE_URI_DATA_CHAR_VALUE); flags = 0; - effectiveTxPower = 0; memset(powerLevels, 0, sizeof(powerLevels)); + txPowerMode = TX_POWER_MODE_LOW; beaconPeriod = 0; updateGATT(); @@ -344,6 +355,14 @@ private: ble.updateCharacteristicValue(beaconPeriodChar.getValueAttribute().getHandle(), reinterpret_cast(&beaconPeriod), sizeof(uint16_t)); } + void updateTxPowerModeCharacteristic(void) { + + } + + void updateTxPowerLevelsCharacteristic(void) { + ble.updateCharacteristicValue(txPowerLevelsChar.getValueAttribute().getHandle(), reinterpret_cast(powerLevels), NUM_POWER_MODES * sizeof(int8_t)); + } + private: /** * For debugging only. @@ -372,8 +391,8 @@ private: uint16_t uriDataLength; uint8_t uriData[MAX_SIZE_URI_DATA_CHAR_VALUE]; uint8_t flags; - int8_t effectiveTxPower; int8_t powerLevels[NUM_POWER_MODES]; + TXPowerModes_t txPowerMode; uint16_t beaconPeriod; bool resetFlag; @@ -381,6 +400,7 @@ private: GattCharacteristic uriDataChar; GattCharacteristic flagsChar; GattCharacteristic txPowerLevelsChar; + GattCharacteristic txPowerModeChar; GattCharacteristic beaconPeriodChar; GattCharacteristic resetChar; }; From 78696699c8c6c36da76135530d33c665d0fbd12d Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 13:33:43 +0000 Subject: [PATCH 21/28] add API to setup TxPowerLevels --- services/URIBeaconConfigService.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 4ac85d8..bdd8f8a 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -141,16 +141,17 @@ public: } /** - * Update the txPower for a particular mode in the powerLevels table. + * Update the txPowerLevels table. */ - void setTxPowerLevel(TXPowerModes_t mode, int8_t txPowerIn) { - powerLevels[mode] = txPowerIn; + void setTxPowerLevels(const int8_t powerLevelsIn[NUM_POWER_MODES]) { + memcpy(powerLevels, powerLevelsIn, sizeof(powerLevels)); + updateTxPowerLevelsCharacteristic(); } /** * Set the effective power mode from one of the values in the powerLevels tables. */ - void useTxPowerMode(TXPowerModes_t mode) { + void setTxPowerMode(TXPowerModes_t mode) { txPowerMode = mode; configureGAP(); updateTxPowerModeCharacteristic(); From 93af1ec2894ea5cc810efce7e109623635af9b10 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 13:34:19 +0000 Subject: [PATCH 22/28] updateGATT() should update TxPower related characteristics. --- services/URIBeaconConfigService.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index bdd8f8a..6f6e9cb 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -338,6 +338,8 @@ private: updateURIDataCharacteristic(); updateFlagsCharacteristic(); updateBeaconPeriodCharacteristic(); + updateTxPowerLevelsCharacteristic(); + updateTxPowerModeCharacteristic(); } void updateLockedStateCharacteristic(void) { @@ -357,7 +359,7 @@ private: } void updateTxPowerModeCharacteristic(void) { - + ble.updateCharacteristicValue(txPowerModeChar.getValueAttribute().getHandle(), reinterpret_cast(&txPowerMode), sizeof(uint8_t)); } void updateTxPowerLevelsCharacteristic(void) { From 9ea6d8b6c176dcb87579fcf90bc247fe0ca3c156 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 13:39:19 +0000 Subject: [PATCH 23/28] allow update to txPowerMode from onDataWritten() --- services/URIBeaconConfigService.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 6f6e9cb..52f6195 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -301,11 +301,19 @@ private: } else if (params->charHandle == txPowerLevelsChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the characteristic. */ /* Restore GATT database with previous value. */ - ble.updateCharacteristicValue(txPowerLevelsChar.getValueAttribute().getHandle(), reinterpret_cast(powerLevels), NUM_POWER_MODES * sizeof(int8_t)); + updateTxPowerLevelsCharacteristic(); return; } else { memcpy(powerLevels, params->data, NUM_POWER_MODES * sizeof(int8_t)); } + } else if (params->charHandle == txPowerModeChar.getValueAttribute().getHandle()) { + if (lockedState) { /* When locked, the device isn't allowed to update the characteristic. */ + /* Restore GATT database with previous value. */ + updateTxPowerModeCharacteristic(); + return; + } else { + txPowerMode = *reinterpret_cast(params->data); + } } else if (params->charHandle == beaconPeriodChar.getValueAttribute().getHandle()) { if (lockedState) { /* When locked, the device isn't allowed to update the characteristic. */ /* Restore GATT database with previous value. */ From 62e9ce268bff13cd1d61a212e79742ce4be29deb Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 13:42:46 +0000 Subject: [PATCH 24/28] white space diffs. --- services/URIBeaconConfigService.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 52f6195..dfc9acc 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -60,10 +60,10 @@ public: */ URIBeaconConfigService(BLEDevice &bleIn, const char *uriDataIn, - uint8_t flagsIn = 0, + uint8_t flagsIn = 0, const int8_t powerLevelsIn[NUM_POWER_MODES] = NULL, - TXPowerModes_t powerModeIn = TX_POWER_MODE_LOW, - uint16_t beaconPeriodIn = 1000) : + TXPowerModes_t powerModeIn = TX_POWER_MODE_LOW, + uint16_t beaconPeriodIn = 1000) : ble(bleIn), payloadIndex(0), serviceDataPayload(), From eaa62b877ba51310613bc3addbc1c1a26b5e24af Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 13:43:28 +0000 Subject: [PATCH 25/28] should still call configureGAP after updating powerLevels. --- services/URIBeaconConfigService.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index dfc9acc..76da787 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -145,6 +145,7 @@ public: */ void setTxPowerLevels(const int8_t powerLevelsIn[NUM_POWER_MODES]) { memcpy(powerLevels, powerLevelsIn, sizeof(powerLevels)); + configureGAP(); updateTxPowerLevelsCharacteristic(); } From b940e50a3414ae7ebfa1c0f0a86548b049db8dfe Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 13:49:07 +0000 Subject: [PATCH 26/28] simplify construction of TxPowerLevelsChar --- services/URIBeaconConfigService.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 76da787..6e83c83 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -78,10 +78,7 @@ public: uriDataChar(uriDataCharUUID, uriData, MAX_SIZE_URI_DATA_CHAR_VALUE, MAX_SIZE_URI_DATA_CHAR_VALUE, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), flagsChar(flagsCharUUID, &flags, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), - txPowerLevelsChar(txPowerLevelsCharUUID, - reinterpret_cast(powerLevels), - NUM_POWER_MODES * sizeof(int8_t), - NUM_POWER_MODES * sizeof(int8_t), + txPowerLevelsChar(txPowerLevelsCharUUID, reinterpret_cast(powerLevels), sizeof(powerLevels), sizeof(powerLevels), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), txPowerModeChar(txPowerModeCharUUID, reinterpret_cast(&txPowerMode), sizeof(uint8_t), sizeof(uint8_t), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), From 88d278cc71c89577a84019c315222bda17f4342a Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 14:03:52 +0000 Subject: [PATCH 27/28] make UUID consts static so that the header file can be included from multiple compilation units. --- services/URIBeaconConfigService.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 6e83c83..05d1b75 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -19,18 +19,18 @@ #include "BLEDevice.h" -#define UUID_INITIALIZER_LIST(FIRST, SECOND) { \ - 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ - 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ +#define URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(FIRST, SECOND) { \ + 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ + 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ } -const uint8_t URIBeacon2ControlServiceUUID[] = UUID_INITIALIZER_LIST(0x20, 0x80); -const uint8_t lockedStateCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x81); -const uint8_t uriDataCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x84); -const uint8_t flagsCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x85); -const uint8_t txPowerLevelsCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x86); -const uint8_t txPowerModeCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x87); -const uint8_t beaconPeriodCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x88); -const uint8_t resetCharUUID[] = UUID_INITIALIZER_LIST(0x20, 0x89); +static const uint8_t URIBeacon2ControlServiceUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x80); +static const uint8_t lockedStateCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x81); +static const uint8_t uriDataCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x84); +static const uint8_t flagsCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x85); +static const uint8_t txPowerLevelsCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x86); +static const uint8_t txPowerModeCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x87); +static const uint8_t beaconPeriodCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x88); +static const uint8_t resetCharUUID[] = URI_BEACON_CONFIG_UUID_INITIALIZER_LIST(0x20, 0x89); class URIBeaconConfigService { public: @@ -76,7 +76,7 @@ public: beaconPeriod(beaconPeriodIn), lockedStateChar(lockedStateCharUUID, reinterpret_cast(&lockedState), 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ), uriDataChar(uriDataCharUUID, uriData, MAX_SIZE_URI_DATA_CHAR_VALUE, MAX_SIZE_URI_DATA_CHAR_VALUE, - GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), flagsChar(flagsCharUUID, &flags, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), txPowerLevelsChar(txPowerLevelsCharUUID, reinterpret_cast(powerLevels), sizeof(powerLevels), sizeof(powerLevels), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE), From 1150cca72096f98e366fa6fdb44a1f436f56fe34 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Mon, 1 Dec 2014 14:25:53 +0000 Subject: [PATCH 28/28] oops caught a typo. --- services/URIBeaconConfigService.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/URIBeaconConfigService.h b/services/URIBeaconConfigService.h index 05d1b75..01dff98 100644 --- a/services/URIBeaconConfigService.h +++ b/services/URIBeaconConfigService.h @@ -91,7 +91,7 @@ public: } strcpy(reinterpret_cast(uriData), uriDataIn); - if (powerModeIn != NULL) { + if (powerLevelsIn != NULL) { memcpy(powerLevels, powerLevelsIn, sizeof(powerLevels)); updateTxPowerLevelsCharacteristic(); }