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:
h2zero
2022-01-18 14:48:07 -07:00
parent 6b858a0efd
commit 2386a8a68a
5 changed files with 56 additions and 5 deletions

View File

@@ -109,7 +109,7 @@ NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEU
return m_characteristicVector.back();
}
// If the request was successful but 16/32 bit characteristic not found
// If the request was successful but 16/32 bit uuid not found
// try again with the 128 bit uuid.
if(uuid.bitSize() == BLE_UUID_TYPE_16 ||
uuid.bitSize() == BLE_UUID_TYPE_32)
@@ -117,6 +117,15 @@ NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEU
NimBLEUUID uuid128(uuid);
uuid128.to128();
return getCharacteristic(uuid128);
} else {
// If the request was successful but the 128 bit uuid not found
// try again with the 16 bit uuid.
NimBLEUUID uuid16(uuid);
uuid16.to16();
// if the uuid was 128 bit but not of the BLE base type this check will fail
if (uuid16.bitSize() == BLE_UUID_TYPE_16) {
return getCharacteristic(uuid16);
}
}
}