esp-nimble-cpp  1.4.0
NimBLEUUID Class Reference

A model of a BLE UUID. More...

Public Member Functions

 NimBLEUUID (const std::string &uuid)
 Create a UUID from a string. More...
 
 NimBLEUUID (uint16_t uuid)
 Create a UUID from the 16bit value. More...
 
 NimBLEUUID (uint32_t uuid)
 Create a UUID from the 32bit value. More...
 
 NimBLEUUID (const ble_uuid128_t *uuid)
 Create a UUID from the native UUID. More...
 
 NimBLEUUID (const uint8_t *pData, size_t size, bool msbFirst)
 Create a UUID from 2, 4, 16 bytes of memory. More...
 
 NimBLEUUID (uint32_t first, uint16_t second, uint16_t third, uint64_t fourth)
 Create a UUID from the 128bit value using hex parts instead of string, instead of NimBLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes NimBLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6) More...
 
 NimBLEUUID ()
 Creates an empty UUID.
 
uint8_t bitSize () const
 Get the number of bits in this uuid. More...
 
bool equals (const NimBLEUUID &uuid) const
 Compare a UUID against this UUID. More...
 
const ble_uuid_any_t * getNative () const
 Get the native UUID value. More...
 
const NimBLEUUIDto128 ()
 Convert a UUID to its 128 bit representation. More...
 
const NimBLEUUIDto16 ()
 Convert 128 bit UUID to its 16 bit representation. More...
 
std::string toString () const
 Get a string representation of the UUID. More...
 
bool operator== (const NimBLEUUID &rhs) const
 Convenience operator to check if this UUID is equal to another.
 
bool operator!= (const NimBLEUUID &rhs) const
 Convenience operator to check if this UUID is not equal to another.
 
 operator std::string () const
 Convenience operator to convert this UUID to string representation. More...
 

Static Public Member Functions

static NimBLEUUID fromString (const std::string &uuid)
 

Detailed Description

A model of a BLE UUID.

Constructor & Destructor Documentation

◆ NimBLEUUID() [1/6]

NimBLEUUID::NimBLEUUID ( const std::string &  value)

Create a UUID from a string.

Create a UUID from a string. There will be two possible stories here. Either the string represents a binary data field or the string represents a hex encoding of a UUID. For the hex encoding, here is an example:

"beb5483e-36e1-4688-b7f5-ea07361b26a8"
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
12345678-90ab-cdef-1234-567890abcdef

This has a length of 36 characters. We need to parse this into 16 bytes.

Parameters
[in]valueThe string to build a UUID from.

◆ NimBLEUUID() [2/6]

NimBLEUUID::NimBLEUUID ( uint16_t  uuid)

Create a UUID from the 16bit value.

Parameters
[in]uuidThe 16bit short form UUID.

◆ NimBLEUUID() [3/6]

NimBLEUUID::NimBLEUUID ( uint32_t  uuid)

Create a UUID from the 32bit value.

Parameters
[in]uuidThe 32bit short form UUID.

◆ NimBLEUUID() [4/6]

NimBLEUUID::NimBLEUUID ( const ble_uuid128_t *  uuid)

Create a UUID from the native UUID.

Parameters
[in]uuidThe native UUID.

◆ NimBLEUUID() [5/6]

NimBLEUUID::NimBLEUUID ( const uint8_t *  pData,
size_t  size,
bool  msbFirst 
)

Create a UUID from 2, 4, 16 bytes of memory.

Parameters
[in]pDataThe pointer to the start of the UUID.
[in]sizeThe size of the data.
[in]msbFirstIs the MSB first in pData memory?

◆ NimBLEUUID() [6/6]

NimBLEUUID::NimBLEUUID ( uint32_t  first,
uint16_t  second,
uint16_t  third,
uint64_t  fourth 
)

Create a UUID from the 128bit value using hex parts instead of string, instead of NimBLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes NimBLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)

Parameters
[in]firstThe first 32bit of the UUID.
[in]secondThe next 16bit of the UUID.
[in]thirdThe next 16bit of the UUID.
[in]fourthThe last 64bit of the UUID, combining the last 2 parts of the string equivalent

Member Function Documentation

◆ bitSize()

uint8_t NimBLEUUID::bitSize ( ) const

Get the number of bits in this uuid.

Returns
The number of bits in the UUID. One of 16, 32 or 128.

◆ equals()

bool NimBLEUUID::equals ( const NimBLEUUID uuid) const

Compare a UUID against this UUID.

Parameters
[in]uuidThe UUID to compare against.
Returns
True if the UUIDs are equal and false otherwise.

◆ fromString()

NimBLEUUID NimBLEUUID::fromString ( const std::string &  uuid)
static

Create a NimBLEUUID from a string of the form: 0xNNNN 0xNNNNNNNN 0x<UUID> NNNN NNNNNNNN <UUID>

Parameters
[in]uuidThe string to create the UUID from.

◆ getNative()

const ble_uuid_any_t * NimBLEUUID::getNative ( ) const

Get the native UUID value.

Returns
The native UUID value or nullptr if not set.

◆ operator std::string()

NimBLEUUID::operator std::string ( ) const

Convenience operator to convert this UUID to string representation.

This allows passing NimBLEUUID to functions that accept std::string and/or or it's methods as a parameter.

◆ to128()

const NimBLEUUID & NimBLEUUID::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 32bit representations to the full 128bit.

Returns
The NimBLEUUID converted to 128bit.

◆ to16()

const NimBLEUUID & NimBLEUUID::to16 ( )

Convert 128 bit UUID to its 16 bit representation.

A UUID can be internally represented as 16bit, 32bit or the full 128bit. This method will convert a 128bit uuid to 16bit if it contains the ble base uuid.

Returns
The NimBLEUUID converted to 16bit if successful, otherwise the original uuid.

◆ toString()

std::string NimBLEUUID::toString ( void  ) const

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.
Deprecated:
Use std::string() operator instead.