mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2026-01-26 17:12:31 +01:00
Retrieve attributes with 16bit uuid if 128bit fails.
When retrieving attribute handles using the 128bit base version of a 16 bit UUID some devices will report "not found". This will attempt to convert the UUID to the 16bit version and try again. * Adds `to16()` method to NimBLEUUID.
This commit is contained in:
@@ -235,8 +235,8 @@ const ble_uuid_any_t* NimBLEUUID::getNative() const {
|
||||
|
||||
/**
|
||||
* @brief Convert a UUID to its 128 bit representation.
|
||||
* @details 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.
|
||||
* @details 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.
|
||||
* @return The NimBLEUUID converted to 128bit.
|
||||
*/
|
||||
const NimBLEUUID &NimBLEUUID::to128() {
|
||||
@@ -257,6 +257,29 @@ const NimBLEUUID &NimBLEUUID::to128() {
|
||||
} // to128
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convert 128 bit UUID to its 16 bit representation.
|
||||
* @details 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.
|
||||
* @return The NimBLEUUID converted to 16bit if successful, otherwise the original uuid.
|
||||
*/
|
||||
const NimBLEUUID& NimBLEUUID::to16() {
|
||||
if (!m_valueSet || m_uuid.u.type == BLE_UUID_TYPE_16) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (m_uuid.u.type == BLE_UUID_TYPE_128) {
|
||||
uint8_t base128[] = {0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00,
|
||||
0x00, 0x80, 0x00, 0x10, 0x00, 0x00};
|
||||
if (memcmp(m_uuid.u128.value, base128, sizeof(base128)) == 0 ) {
|
||||
*this = NimBLEUUID(*(uint16_t*)(m_uuid.u128.value + 12));
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get a string representation of the UUID.
|
||||
* @details
|
||||
|
||||
Reference in New Issue
Block a user