add "LE Device Address" 0x1B to advertising data types
Fork of BLE_API by
Revision 1022:306c409f6c09, committed 2015-12-10
- Comitter:
- rgrover1
- Date:
- Thu Dec 10 09:15:02 2015 +0000
- Parent:
- 1021:4dc141889504
- Child:
- 1023:a072b59caddb
- Commit message:
- Synchronized with git rev ea69dba5
Author: Marcus Chang
Reversed internal representation of long UUID in the UUID class to little endian to be consistent with the short UUID.
Changed in this revision
--- a/ble/UUID.h Thu Dec 10 09:15:02 2015 +0000 +++ b/ble/UUID.h Thu Dec 10 09:15:02 2015 +0000 @@ -22,6 +22,18 @@ #include "blecommon.h" +static uint16_t char2int(char c) { + if ((c >= '0') && (c <= '9')) { + return c - '0'; + } else if ((c >= 'a') && (c <= 'f')) { + return c - 'a' + 10; + } else if ((c >= 'A') && (c <= 'F')) { + return c - 'A' + 10; + } else { + return 0; + } +} + class UUID { public: enum UUID_Type_t { @@ -35,6 +47,49 @@ typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]; public: + + /** + * Creates a new 128-bit UUID. + * + * @note The UUID is a unique 128-bit (16 byte) ID used to identify + * different service or characteristics on the BLE device. + * + * @param stringUUID + * The 128-bit (16-byte) UUID as a human readable const-string. + * Format: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX + * Upper and lower case supported. Hyphens are optional, but only + * upto four of them. The UUID is stored internally as a 16 byte + * array, LSB (little endian), which is opposite from the string. + */ + UUID(const char* stringUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) { + bool nibble = false; + uint8_t byte = 0; + size_t baseIndex = 0; + + // Iterate through string, abort if NULL is encountered prematurely. + // Ignore upto four hyphens. Reverse endian when storing internally. + for (size_t index = 0; (index < 36) && (baseIndex < LENGTH_OF_LONG_UUID); index++) { + if (stringUUID[index] == '\0') { + // error abort + break; + } else if (stringUUID[index] == '-') { + // ignore hyphen + continue; + } else if (nibble) { + // got second nibble + byte |= char2int(stringUUID[index]); + nibble = false; + + // reverse endian + baseUUID[LENGTH_OF_LONG_UUID - 1 - baseIndex++] = byte; + } else { + // got first nibble + byte = char2int(stringUUID[index]) << 4; + nibble = true; + } + } + } + /** * Creates a new 128-bit UUID. * @@ -42,7 +97,7 @@ * different service or characteristics on the BLE device. * * @param longUUID - * The 128-bit (16-byte) UUID value, MSB first (big-endian). + * The 128-bit (16-byte) UUID value, LSB first (little-endian). */ UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) { setupLong(longUUID); @@ -94,7 +149,7 @@ void setupLong(const LongUUIDBytes_t longUUID) { type = UUID_TYPE_LONG; memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID); - shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3])); + shortUUID = (uint16_t)((longUUID[13] << 8) | (longUUID[12])); } public:
--- a/ble/services/EddystoneConfigService.h Thu Dec 10 09:15:02 2015 +0000 +++ b/ble/services/EddystoneConfigService.h Thu Dec 10 09:15:02 2015 +0000 @@ -23,9 +23,9 @@ #include "ble/BLE.h" #include "ble/services/EddystoneService.h" -#define UUID_URI_BEACON(FIRST, SECOND) { \ - 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ - 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ +#define UUID_URI_BEACON(FIRST, SECOND) { \ + 0xd8, 0x81, 0xc9, 0x1a, 0xb9, 0x99, 0x96, 0xab, \ + 0xba, 0x40, 0x86, 0x87, SECOND, FIRST, 0x0c, 0xee \ } static const uint8_t UUID_URI_BEACON_SERVICE[] = UUID_URI_BEACON(0x20, 0x80); @@ -271,12 +271,7 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - // UUID is in a different order in the ADV frame (!) - uint8_t reversedServiceUUID[sizeof(UUID_URI_BEACON_SERVICE)]; - for (unsigned int i = 0; i < sizeof(UUID_URI_BEACON_SERVICE); i++) { - reversedServiceUUID[i] = UUID_URI_BEACON_SERVICE[sizeof(UUID_URI_BEACON_SERVICE) - i - 1]; - } - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, reversedServiceUUID, sizeof(reversedServiceUUID)); + ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, UUID_URI_BEACON_SERVICE, sizeof(UUID_URI_BEACON_SERVICE)); ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_TAG); ble.accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, reinterpret_cast<const uint8_t *>(&DEVICE_NAME), sizeof(DEVICE_NAME)); ble.accumulateScanResponse(
--- a/ble/services/UARTService.h Thu Dec 10 09:15:02 2015 +0000 +++ b/ble/services/UARTService.h Thu Dec 10 09:15:02 2015 +0000 @@ -34,7 +34,6 @@ extern const uint16_t UARTServiceRXCharacteristicShortUUID; extern const uint8_t UARTServiceUUID[UUID::LENGTH_OF_LONG_UUID]; -extern const uint8_t UARTServiceUUID_reversed[UUID::LENGTH_OF_LONG_UUID]; extern const uint8_t UARTServiceTXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID]; extern const uint8_t UARTServiceRXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID];
--- a/ble/services/URIBeaconConfigService.h Thu Dec 10 09:15:02 2015 +0000 +++ b/ble/services/URIBeaconConfigService.h Thu Dec 10 09:15:02 2015 +0000 @@ -168,12 +168,7 @@ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - // UUID is in different order in the ADV frame (!) - uint8_t reversedServiceUUID[sizeof(UUID_URI_BEACON_SERVICE)]; - for (unsigned int i = 0; i < sizeof(UUID_URI_BEACON_SERVICE); i++) { - reversedServiceUUID[i] = UUID_URI_BEACON_SERVICE[sizeof(UUID_URI_BEACON_SERVICE) - i - 1]; - } - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, reversedServiceUUID, sizeof(reversedServiceUUID)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, UUID_URI_BEACON_SERVICE, sizeof(UUID_URI_BEACON_SERVICE)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_TAG); ble.gap().accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, reinterpret_cast<const uint8_t *>(&DEVICE_NAME), sizeof(DEVICE_NAME)); ble.gap().accumulateScanResponse(GapAdvertisingData::TX_POWER_LEVEL,
--- a/source/services/DFUService.cpp Thu Dec 10 09:15:02 2015 +0000 +++ b/source/services/DFUService.cpp Thu Dec 10 09:15:02 2015 +0000 @@ -19,24 +19,24 @@ #include "ble/services/DFUService.h" const uint8_t DFUServiceBaseUUID[] = { - 0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0xEF, 0xDE, - 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00 }; const uint16_t DFUServiceShortUUID = 0x1530; const uint16_t DFUServiceControlCharacteristicShortUUID = 0x1531; const uint16_t DFUServicePacketCharacteristicShortUUID = 0x1532; const uint8_t DFUServiceUUID[] = { - 0x00, 0x00, (uint8_t)(DFUServiceShortUUID >> 8), (uint8_t)(DFUServiceShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE, - 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServiceShortUUID & 0xFF), (uint8_t)(DFUServiceShortUUID >> 8), 0x00, 0x00 }; const uint8_t DFUServiceControlCharacteristicUUID[] = { - 0x00, 0x00, (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE, - 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), 0x00, 0x00 }; const uint8_t DFUServicePacketCharacteristicUUID[] = { - 0x00, 0x00, (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE, - 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), 0x00, 0x00 }; DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;
--- a/source/services/UARTService.cpp Thu Dec 10 09:15:02 2015 +0000 +++ b/source/services/UARTService.cpp Thu Dec 10 09:15:02 2015 +0000 @@ -17,25 +17,21 @@ #include "ble/services/UARTService.h" const uint8_t UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID] = { - 0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93, - 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, + 0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, + 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E }; const uint16_t UARTServiceShortUUID = 0x0001; const uint16_t UARTServiceTXCharacteristicShortUUID = 0x0002; const uint16_t UARTServiceRXCharacteristicShortUUID = 0x0003; const uint8_t UARTServiceUUID[UUID::LENGTH_OF_LONG_UUID] = { - 0x6E, 0x40, (uint8_t)(UARTServiceShortUUID >> 8), (uint8_t)(UARTServiceShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93, - 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, -}; -const uint8_t UARTServiceUUID_reversed[UUID::LENGTH_OF_LONG_UUID] = { 0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceShortUUID & 0xFF), (uint8_t)(UARTServiceShortUUID >> 8), 0x40, 0x6E }; const uint8_t UARTServiceTXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID] = { - 0x6E, 0x40, (uint8_t)(UARTServiceTXCharacteristicShortUUID >> 8), (uint8_t)(UARTServiceTXCharacteristicShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, + 0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceTXCharacteristicShortUUID & 0xFF), (uint8_t)(UARTServiceTXCharacteristicShortUUID >> 8), 0x40, 0x6E }; const uint8_t UARTServiceRXCharacteristicUUID[UUID::LENGTH_OF_LONG_UUID] = { - 0x6E, 0x40, (uint8_t)(UARTServiceRXCharacteristicShortUUID >> 8), (uint8_t)(UARTServiceRXCharacteristicShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, + 0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceRXCharacteristicShortUUID & 0xFF), (uint8_t)(UARTServiceRXCharacteristicShortUUID >> 8), 0x40, 0x6E }; \ No newline at end of file
--- a/source/services/URIBeaconConfigService.cpp Thu Dec 10 09:15:02 2015 +0000 +++ b/source/services/URIBeaconConfigService.cpp Thu Dec 10 09:15:02 2015 +0000 @@ -17,8 +17,8 @@ #include "ble/services/URIBeaconConfigService.h" #define UUID_URI_BEACON(FIRST, SECOND) { \ - 0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \ - 0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \ + 0xd8, 0x81, 0xc9, 0x1a, 0xb9, 0x99, 0x96, 0xab, \ + 0xba, 0x40, 0x86, 0x87, SECOND, FIRST, 0x0c, 0xee \ } const uint8_t UUID_URI_BEACON_SERVICE[UUID::LENGTH_OF_LONG_UUID] = UUID_URI_BEACON(0x20, 0x80);