A model of a BLE UUID.
More...
#include <BLEUUID.hpp>
|
| BLEUUID (std::string uuid) |
|
| BLEUUID (uint16_t uuid) |
| Create a UUID from the 16bit value. More...
|
|
| BLEUUID (uint32_t uuid) |
| Create a UUID from the 32bit value. More...
|
|
| BLEUUID (uint8_t *pData, size_t size, bool msbFirst) |
| Create a UUID from 16 bytes of memory. More...
|
|
uint8_t | bitSize () |
| Get the number of bits in this uuid. More...
|
|
bool | equals (BLEUUID uuid) |
| Compare a UUID against this UUID. More...
|
|
BLEUUID | to128 () |
| Convert a UUID to its 128 bit representation. More...
|
|
std::string | toString () |
| Get a string representation of the UUID. More...
|
|
bool | operator== (uint16_t other) const |
|
bool | operator== (uint32_t other) const |
|
|
uint16_t | len |
|
union { |
uint16_t raw16 |
|
uint32_t raw32 |
|
uint8_t raw128 [16] |
|
}; | |
|
◆ BLEUUID() [1/3]
BLEUUID::BLEUUID |
( |
uint16_t |
uuid | ) |
|
Create a UUID from the 16bit value.
- Parameters
-
[in] | uuid | The 16bit short form UUID. |
◆ BLEUUID() [2/3]
BLEUUID::BLEUUID |
( |
uint32_t |
uuid | ) |
|
Create a UUID from the 32bit value.
- Parameters
-
[in] | uuid | The 32bit short form UUID. |
◆ BLEUUID() [3/3]
BLEUUID::BLEUUID |
( |
uint8_t * |
pData, |
|
|
size_t |
size, |
|
|
bool |
msbFirst |
|
) |
| |
Create a UUID from 16 bytes of memory.
- Parameters
-
[in] | pData | The pointer to the start of the UUID. |
[in] | size | The size of the data. |
[in] | msbFirst | Is the MSB first in pData memory? |
133 _debug_print(TAG,
"ERROR: UUID length not 16 bytes");
138 memrcpy(this->raw128, pData, 16);
140 memcpy(this->raw128, pData, 16);
◆ bitSize()
uint8_t BLEUUID::bitSize |
( |
| ) |
|
Get the number of bits in this uuid.
- Returns
- The number of bits in the UUID. One of 16, 32 or 128.
180 if (!m_valueSet)
return 0;
189 _debug_print_d(TAG,
"Unknown UUID length", len);
◆ equals()
bool BLEUUID::equals |
( |
BLEUUID |
uuid | ) |
|
Compare a UUID against this UUID.
- Parameters
-
[in] | uuid | The UUID to compare against. |
- Returns
- True if the UUIDs are equal and false otherwise.
202 if (m_valueSet ==
false || uuid.m_valueSet ==
false) {
206 if (uuid.len != len) {
211 return uuid.raw16 == raw16;
215 return uuid.raw32 == raw32;
218 return memcmp(uuid.raw128, raw128, 16) == 0;
◆ fromString()
BLEUUID BLEUUID::fromString |
( |
std::string |
_uuid | ) |
|
|
static |
Create a BLEUUID from a string of the form: 0xNNNN 0xNNNNNNNN 0x<UUID> NNNN NNNNNNNN <UUID>
233 if (strstr(_uuid.c_str(),
"0x") !=
nullptr) {
236 uint8_t len = _uuid.length() - start;
239 uint16_t x = strtoul(_uuid.substr(start, len).c_str(), NULL, 16);
241 }
else if (len == 8) {
242 uint32_t x = strtoul(_uuid.substr(start, len).c_str(), NULL, 16);
244 }
else if (len == 36) {
◆ to128()
Convert a UUID to its 128 bit representation.
A UUID can be internally represented as 16bit, 32bit or the full 128bit. This method will convert 16 or 32 bit representations to the full 128bit.
261 if (!m_valueSet || this->len == 16) {
266 if (this->len == 2) {
267 uint16_t temp = this->raw16;
268 this->raw128[15] = 0;
269 this->raw128[14] = 0;
270 this->raw128[13] = (temp >> 8) & 0xff;
271 this->raw128[12] = temp & 0xff;
274 else if (this->len == 4) {
275 uint32_t temp = this->raw32;
276 this->raw128[15] = (temp >> 24) & 0xff;
277 this->raw128[14] = (temp >> 16) & 0xff;
278 this->raw128[13] = (temp >> 8) & 0xff;
279 this->raw128[12] = temp & 0xff;
283 this->raw128[11] = 0x00;
284 this->raw128[10] = 0x00;
286 this->raw128[9] = 0x10;
287 this->raw128[8] = 0x00;
289 this->raw128[7] = 0x80;
290 this->raw128[6] = 0x00;
292 this->raw128[5] = 0x00;
293 this->raw128[4] = 0x80;
294 this->raw128[3] = 0x5f;
295 this->raw128[2] = 0x9b;
296 this->raw128[1] = 0x34;
297 this->raw128[0] = 0xfb;
◆ toString()
std::string BLEUUID::toString |
( |
| ) |
|
Get a string representation of the UUID.
The format of a string is: 01234567 8901 2345 6789 012345678901 0000180d-0000-1000-8000-00805f9b34fb 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
- Returns
- A string representation of the UUID.
318 if (!m_valueSet)
return "<NULL>";
321 std::stringstream ss;
323 if (this->len == 2) {
329 "-0000-1000-8000-00805f9b34fb";
333 if (this->len == 4) {
338 "-0000-1000-8000-00805f9b34fb";
347 ss << std::hex << std::setfill(
'0') <<
348 std::setw(2) << (int)raw128[15] <<
349 std::setw(2) << (int)raw128[14] <<
350 std::setw(2) << (int)raw128[13] <<
351 std::setw(2) << (int)raw128[12] <<
"-" <<
352 std::setw(2) << (int)raw128[11] <<
353 std::setw(2) << (int)raw128[10] <<
"-" <<
354 std::setw(2) << (int)raw128[9] <<
355 std::setw(2) << (int)raw128[8] <<
"-" <<
356 std::setw(2) << (int)raw128[7] <<
357 std::setw(2) << (int)raw128[6] <<
"-" <<
358 std::setw(2) << (int)raw128[5] <<
359 std::setw(2) << (int)raw128[4] <<
360 std::setw(2) << (int)raw128[3] <<
361 std::setw(2) << (int)raw128[2] <<
362 std::setw(2) << (int)raw128[1] <<
363 std::setw(2) << (int)raw128[0];
The documentation for this class was generated from the following files:
- nola-sdk/include/BLEUUID.hpp
- src/net/BluetoothLE/BLEUUID.cpp