UUID constructors should zero out relative part of baseUUID
parent
6e1746fdba
commit
abed1b0557
58
UUID.cpp
58
UUID.cpp
|
@ -20,21 +20,6 @@
|
|||
|
||||
#include "UUID.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates an empty 128-bit UUID
|
||||
|
||||
@note This UUID must be assigned a valid value via the 'update'
|
||||
function before it can be safely used!
|
||||
*/
|
||||
/**************************************************************************/
|
||||
UUID::UUID(void) : type(UUID_TYPE_SHORT),
|
||||
base(),
|
||||
value(0)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new 128-bit UUID
|
||||
|
@ -79,22 +64,33 @@ UUID::UUID(void) : type(UUID_TYPE_SHORT),
|
|||
@endcode
|
||||
*/
|
||||
/**************************************************************************/
|
||||
UUID::UUID(const uint8_t uuid_base[LENGTH_OF_LONG_UUID]) :
|
||||
UUID::UUID(const uint8_t longUUID[LENGTH_OF_LONG_UUID]) :
|
||||
type(UUID_TYPE_SHORT),
|
||||
base(),
|
||||
baseUUID(),
|
||||
value(0)
|
||||
{
|
||||
memcpy(base, uuid_base, LENGTH_OF_LONG_UUID);
|
||||
value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
|
||||
memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
|
||||
value = (uint16_t)((longUUID[3] << 8) | (longUUID[2]));/* NEEDS REVIEW */
|
||||
|
||||
/* Check if this is a short of a long UUID */
|
||||
if (uuid_base[0] + uuid_base[1] +
|
||||
uuid_base[4] + uuid_base[5] + uuid_base[6] + uuid_base[7] +
|
||||
uuid_base[8] + uuid_base[9] + uuid_base[10] + uuid_base[11] +
|
||||
uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0) {
|
||||
type = UUID_TYPE_SHORT;
|
||||
} else {
|
||||
type = UUID_TYPE_LONG;
|
||||
unsigned index;
|
||||
for (index = 0; index < LENGTH_OF_LONG_UUID; index++) {
|
||||
if ((index == 2) || (index == 3)) {
|
||||
continue; /* we should not consider bytes 2 and 3 because that's
|
||||
* where the 16-bit relative UUID is placed. */
|
||||
}
|
||||
|
||||
if (baseUUID[index] != 0) {
|
||||
type = UUID_TYPE_LONG;
|
||||
|
||||
/* NEEDS REVIEW */
|
||||
/* zero out the 16-bit part in the base; this will help equate long
|
||||
* UUIDs when they differ only in this 16-bit relative part.*/
|
||||
baseUUID[2] = 0;
|
||||
baseUUID[3] = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,11 +102,13 @@ UUID::UUID(const uint8_t uuid_base[LENGTH_OF_LONG_UUID]) :
|
|||
The 16-bit BLE UUID value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
UUID::UUID(const uint16_t ble_uuid) : type(UUID_TYPE_SHORT),
|
||||
base(),
|
||||
value(ble_uuid)
|
||||
UUID::UUID(const uint16_t shortUUID) : type(UUID_TYPE_SHORT),
|
||||
baseUUID(),
|
||||
value(shortUUID)
|
||||
{
|
||||
memcpy(base + 2, (uint8_t *)&ble_uuid, 2);
|
||||
/* NEEDS REVIEW */
|
||||
baseUUID[2] = (shortUUID >> 8);
|
||||
baseUUID[3] = (shortUUID & 0xff);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
|
13
UUID.h
13
UUID.h
|
@ -31,9 +31,8 @@ public:
|
|||
static const unsigned LENGTH_OF_LONG_UUID = 16;
|
||||
|
||||
public:
|
||||
UUID(void);
|
||||
UUID(uint8_t const[LENGTH_OF_LONG_UUID]);
|
||||
UUID(uint16_t const);
|
||||
UUID(const uint8_t longUUID[LENGTH_OF_LONG_UUID]);
|
||||
UUID(uint16_t shortUUID);
|
||||
virtual ~UUID(void);
|
||||
|
||||
public:
|
||||
|
@ -41,7 +40,7 @@ public:
|
|||
return type;
|
||||
}
|
||||
const uint8_t* getBaseUUID(void) const {
|
||||
return base;
|
||||
return baseUUID;
|
||||
}
|
||||
uint16_t get16BitUUID(void) const {
|
||||
return value;
|
||||
|
@ -49,7 +48,11 @@ public:
|
|||
|
||||
private:
|
||||
uint8_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG
|
||||
uint8_t base[LENGTH_OF_LONG_UUID]; // in case of custom
|
||||
uint8_t baseUUID[LENGTH_OF_LONG_UUID]; /* 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.*/
|
||||
uint16_t value; // 16 bit uuid (byte 2-3 using with base)
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue