Added bit ordering parameter to UUID construction.
parent
ea69dba564
commit
01eaeeeea2
|
@ -137,13 +137,13 @@ public:
|
|||
*/
|
||||
ble_error_t write(uint16_t length, const uint8_t *value) const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Same as above but register the callback wich will be called once the data has been written
|
||||
*/
|
||||
ble_error_t write(uint16_t length, const uint8_t *value, const GattClient::WriteCallback_t& onRead) const;
|
||||
|
||||
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
|
||||
uuid.setupLong(longUUID);
|
||||
void setupLongUUID(UUID::LongUUIDBytes_t longUUID, UUID::BitOrder_t order = UUID::MSB) {
|
||||
uuid.setupLong(longUUID, order);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -36,8 +36,8 @@ public:
|
|||
endHandle = endHandleIn;
|
||||
}
|
||||
|
||||
void setupLongUUID(UUID::LongUUIDBytes_t longUUID) {
|
||||
uuid.setupLong(longUUID);
|
||||
void setupLongUUID(UUID::LongUUIDBytes_t longUUID, UUID::BitOrder_t order = UUID::MSB) {
|
||||
uuid.setupLong(longUUID, order);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
56
ble/UUID.h
56
ble/UUID.h
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "blecommon.h"
|
||||
|
||||
static uint16_t char2int(char c) {
|
||||
static uint8_t char2int(char c) {
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
return c - '0';
|
||||
} else if ((c >= 'a') && (c <= 'f')) {
|
||||
|
@ -41,11 +41,18 @@ public:
|
|||
UUID_TYPE_LONG = 1 // Full 128-bit UUID.
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
MSB,
|
||||
LSB
|
||||
} BitOrder_t;
|
||||
|
||||
typedef uint16_t ShortUUIDBytes_t;
|
||||
|
||||
static const unsigned LENGTH_OF_LONG_UUID = 16;
|
||||
typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
|
||||
|
||||
static const unsigned MAX_UUID_STRING_LENGTH = LENGTH_OF_LONG_UUID * 2 + 4;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -65,10 +72,11 @@ public:
|
|||
bool nibble = false;
|
||||
uint8_t byte = 0;
|
||||
size_t baseIndex = 0;
|
||||
uint8_t tempUUID[LENGTH_OF_LONG_UUID];
|
||||
|
||||
// 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++) {
|
||||
// Ignore upto four hyphens.
|
||||
for (size_t index = 0; (index < MAX_UUID_STRING_LENGTH) && (baseIndex < LENGTH_OF_LONG_UUID); index++) {
|
||||
if (stringUUID[index] == '\0') {
|
||||
// error abort
|
||||
break;
|
||||
|
@ -80,14 +88,23 @@ public:
|
|||
byte |= char2int(stringUUID[index]);
|
||||
nibble = false;
|
||||
|
||||
// reverse endian
|
||||
baseUUID[LENGTH_OF_LONG_UUID - 1 - baseIndex++] = byte;
|
||||
// store copy
|
||||
tempUUID[baseIndex++] = byte;
|
||||
} else {
|
||||
// got first nibble
|
||||
byte = char2int(stringUUID[index]) << 4;
|
||||
nibble = true;
|
||||
}
|
||||
}
|
||||
|
||||
// populate internal variables if string was successfully parsed
|
||||
if (baseIndex == LENGTH_OF_LONG_UUID) {
|
||||
setupLong(tempUUID, UUID::MSB);
|
||||
} else {
|
||||
const uint8_t sig[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
|
||||
setupLong(sig, UUID::MSB);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,10 +114,12 @@ public:
|
|||
* different service or characteristics on the BLE device.
|
||||
*
|
||||
* @param longUUID
|
||||
* The 128-bit (16-byte) UUID value, LSB first (little-endian).
|
||||
* The 128-bit (16-byte) UUID value.
|
||||
* @param order
|
||||
* The bit order of the UUID, MSB by default.
|
||||
*/
|
||||
UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
|
||||
setupLong(longUUID);
|
||||
UUID(const LongUUIDBytes_t longUUID, BitOrder_t order = UUID::MSB) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
|
||||
setupLong(longUUID, order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,10 +165,17 @@ public:
|
|||
/**
|
||||
* Fill in a 128-bit UUID; this is useful when the UUID isn't known at the time of the object construction.
|
||||
*/
|
||||
void setupLong(const LongUUIDBytes_t longUUID) {
|
||||
void setupLong(const LongUUIDBytes_t longUUID, BitOrder_t order = UUID::MSB) {
|
||||
type = UUID_TYPE_LONG;
|
||||
memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
|
||||
shortUUID = (uint16_t)((longUUID[13] << 8) | (longUUID[12]));
|
||||
if (order == UUID::MSB) {
|
||||
// Switch endian. Input is big-endian, internal representation is little endian.
|
||||
for (size_t index = 0; index < LENGTH_OF_LONG_UUID; index++) {
|
||||
baseUUID[LENGTH_OF_LONG_UUID - 1 - index] = longUUID[index];
|
||||
}
|
||||
} else {
|
||||
memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
|
||||
}
|
||||
shortUUID = (uint16_t)((baseUUID[13] << 8) | (baseUUID[12]));
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -187,12 +213,8 @@ public:
|
|||
|
||||
private:
|
||||
UUID_Type_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG
|
||||
LongUUIDBytes_t baseUUID; /* The base of the long UUID (if
|
||||
* used). Note: bytes 12 and 13 (counting from LSB)
|
||||
* are zeroed out to allow comparison with other long
|
||||
* UUIDs, which differ only in the 16-bit relative
|
||||
* part.*/
|
||||
ShortUUIDBytes_t shortUUID; // 16 bit UUID (byte 2-3 using with base).
|
||||
LongUUIDBytes_t baseUUID; // The long UUID
|
||||
ShortUUIDBytes_t shortUUID; // 16 bit UUID
|
||||
};
|
||||
|
||||
#endif // ifndef __UUID_H__
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#include "ble/BLE.h"
|
||||
#include "ble/services/EddystoneService.h"
|
||||
|
||||
#define UUID_URI_BEACON(FIRST, SECOND) { \
|
||||
0xd8, 0x81, 0xc9, 0x1a, 0xb9, 0x99, 0x96, 0xab, \
|
||||
0xba, 0x40, 0x86, 0x87, SECOND, FIRST, 0x0c, 0xee \
|
||||
#define UUID_URI_BEACON(FIRST, SECOND) { \
|
||||
0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \
|
||||
0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \
|
||||
}
|
||||
|
||||
static const uint8_t UUID_URI_BEACON_SERVICE[] = UUID_URI_BEACON(0x20, 0x80);
|
||||
|
@ -271,7 +271,12 @@ public:
|
|||
|
||||
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
|
||||
|
||||
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, UUID_URI_BEACON_SERVICE, sizeof(UUID_URI_BEACON_SERVICE));
|
||||
// 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::GENERIC_TAG);
|
||||
ble.accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, reinterpret_cast<const uint8_t *>(&DEVICE_NAME), sizeof(DEVICE_NAME));
|
||||
ble.accumulateScanResponse(
|
||||
|
|
|
@ -34,6 +34,7 @@ extern const uint16_t UARTServiceTXCharacteristicShortUUID;
|
|||
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];
|
||||
|
|
|
@ -168,7 +168,12 @@ class URIBeaconConfigService {
|
|||
|
||||
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
|
||||
|
||||
ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, UUID_URI_BEACON_SERVICE, sizeof(UUID_URI_BEACON_SERVICE));
|
||||
// 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::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,
|
||||
|
|
|
@ -19,24 +19,24 @@
|
|||
#include "ble/services/DFUService.h"
|
||||
|
||||
const uint8_t DFUServiceBaseUUID[] = {
|
||||
0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
|
||||
0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00
|
||||
0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0xEF, 0xDE,
|
||||
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
|
||||
};
|
||||
const uint16_t DFUServiceShortUUID = 0x1530;
|
||||
const uint16_t DFUServiceControlCharacteristicShortUUID = 0x1531;
|
||||
const uint16_t DFUServicePacketCharacteristicShortUUID = 0x1532;
|
||||
|
||||
const uint8_t DFUServiceUUID[] = {
|
||||
0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
|
||||
0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServiceShortUUID & 0xFF), (uint8_t)(DFUServiceShortUUID >> 8), 0x00, 0x00
|
||||
0x00, 0x00, (uint8_t)(DFUServiceShortUUID >> 8), (uint8_t)(DFUServiceShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
|
||||
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
|
||||
};
|
||||
const uint8_t DFUServiceControlCharacteristicUUID[] = {
|
||||
0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
|
||||
0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), 0x00, 0x00
|
||||
0x00, 0x00, (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
|
||||
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
|
||||
};
|
||||
const uint8_t DFUServicePacketCharacteristicUUID[] = {
|
||||
0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
|
||||
0xDE, 0xEF, 0x12, 0x12, (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), 0x00, 0x00
|
||||
0x00, 0x00, (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
|
||||
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
|
||||
};
|
||||
|
||||
DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;
|
||||
|
|
|
@ -17,21 +17,25 @@
|
|||
#include "ble/services/UARTService.h"
|
||||
|
||||
const uint8_t UARTServiceBaseUUID[UUID::LENGTH_OF_LONG_UUID] = {
|
||||
0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0,
|
||||
0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E
|
||||
0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93,
|
||||
0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
|
||||
};
|
||||
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
|
||||
};
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#include "ble/services/URIBeaconConfigService.h"
|
||||
|
||||
#define UUID_URI_BEACON(FIRST, SECOND) { \
|
||||
0xd8, 0x81, 0xc9, 0x1a, 0xb9, 0x99, 0x96, 0xab, \
|
||||
0xba, 0x40, 0x86, 0x87, SECOND, FIRST, 0x0c, 0xee \
|
||||
0xee, 0x0c, FIRST, SECOND, 0x87, 0x86, 0x40, 0xba, \
|
||||
0xab, 0x96, 0x99, 0xb9, 0x1a, 0xc9, 0x81, 0xd8, \
|
||||
}
|
||||
|
||||
const uint8_t UUID_URI_BEACON_SERVICE[UUID::LENGTH_OF_LONG_UUID] = UUID_URI_BEACON(0x20, 0x80);
|
||||
|
|
Loading…
Reference in New Issue