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

@@ -611,7 +611,7 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID &uuid) {
return m_servicesVector.back();
}
// If the request was successful but 16/32 bit service 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)
@@ -619,6 +619,15 @@ NimBLERemoteService* NimBLEClient::getService(const NimBLEUUID &uuid) {
NimBLEUUID uuid128(uuid);
uuid128.to128();
return getService(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 getService(uuid16);
}
}
}