mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 05:00:55 +01:00
Fix UUID comparison for 16bit + base UUID's
* Add more information to UUID debug messages.
This commit is contained in:
parent
ebd7598c49
commit
27fc792952
4 changed files with 39 additions and 6 deletions
|
@ -38,7 +38,7 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
||||||
NimBLERemoteCharacteristic::NimBLERemoteCharacteristic(NimBLERemoteService *pRemoteService,
|
NimBLERemoteCharacteristic::NimBLERemoteCharacteristic(NimBLERemoteService *pRemoteService,
|
||||||
const struct ble_gatt_chr *chr)
|
const struct ble_gatt_chr *chr)
|
||||||
{
|
{
|
||||||
|
NIMBLE_LOGD(LOG_TAG, ">> NimBLERemoteCharacteristic()");
|
||||||
switch (chr->uuid.u.type) {
|
switch (chr->uuid.u.type) {
|
||||||
case BLE_UUID_TYPE_16:
|
case BLE_UUID_TYPE_16:
|
||||||
m_uuid = NimBLEUUID(chr->uuid.u16.value);
|
m_uuid = NimBLEUUID(chr->uuid.u16.value);
|
||||||
|
@ -50,7 +50,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
||||||
m_uuid = NimBLEUUID(const_cast<ble_uuid128_t*>(&chr->uuid.u128));
|
m_uuid = NimBLEUUID(const_cast<ble_uuid128_t*>(&chr->uuid.u128));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_uuid = nullptr;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +60,8 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic";
|
||||||
m_notifyCallback = nullptr;
|
m_notifyCallback = nullptr;
|
||||||
m_timestamp = 0;
|
m_timestamp = 0;
|
||||||
m_valMux = portMUX_INITIALIZER_UNLOCKED;
|
m_valMux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
|
||||||
|
NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteCharacteristic(): %s", m_uuid.toString().c_str());
|
||||||
} // NimBLERemoteCharacteristic
|
} // NimBLERemoteCharacteristic
|
||||||
|
|
||||||
|
|
||||||
|
@ -511,7 +512,7 @@ int NimBLERemoteCharacteristic::onReadCB(uint16_t conn_handle,
|
||||||
*/
|
*/
|
||||||
bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyCallback, bool response) {
|
bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyCallback, bool response) {
|
||||||
NIMBLE_LOGD(LOG_TAG, ">> setNotify(): %s, %02x", toString().c_str(), val);
|
NIMBLE_LOGD(LOG_TAG, ">> setNotify(): %s, %02x", toString().c_str(), val);
|
||||||
|
|
||||||
m_notifyCallback = notifyCallback;
|
m_notifyCallback = notifyCallback;
|
||||||
|
|
||||||
NimBLERemoteDescriptor* desc = getDescriptor(NimBLEUUID((uint16_t)0x2902));
|
NimBLERemoteDescriptor* desc = getDescriptor(NimBLEUUID((uint16_t)0x2902));
|
||||||
|
|
|
@ -31,6 +31,7 @@ static const char* LOG_TAG = "NimBLERemoteDescriptor";
|
||||||
NimBLERemoteDescriptor::NimBLERemoteDescriptor(NimBLERemoteCharacteristic* pRemoteCharacteristic,
|
NimBLERemoteDescriptor::NimBLERemoteDescriptor(NimBLERemoteCharacteristic* pRemoteCharacteristic,
|
||||||
const struct ble_gatt_dsc *dsc)
|
const struct ble_gatt_dsc *dsc)
|
||||||
{
|
{
|
||||||
|
NIMBLE_LOGD(LOG_TAG, ">> NimBLERemoteDescriptor()");
|
||||||
switch (dsc->uuid.u.type) {
|
switch (dsc->uuid.u.type) {
|
||||||
case BLE_UUID_TYPE_16:
|
case BLE_UUID_TYPE_16:
|
||||||
m_uuid = NimBLEUUID(dsc->uuid.u16.value);
|
m_uuid = NimBLEUUID(dsc->uuid.u16.value);
|
||||||
|
@ -42,12 +43,13 @@ NimBLERemoteDescriptor::NimBLERemoteDescriptor(NimBLERemoteCharacteristic* pRemo
|
||||||
m_uuid = NimBLEUUID(const_cast<ble_uuid128_t*>(&dsc->uuid.u128));
|
m_uuid = NimBLEUUID(const_cast<ble_uuid128_t*>(&dsc->uuid.u128));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_uuid = nullptr;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_handle = dsc->handle;
|
m_handle = dsc->handle;
|
||||||
m_pRemoteCharacteristic = pRemoteCharacteristic;
|
m_pRemoteCharacteristic = pRemoteCharacteristic;
|
||||||
|
|
||||||
|
NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteDescriptor(): %s", m_uuid.toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,11 @@ NimBLERemoteService::NimBLERemoteService(NimBLEClient* pClient, const struct ble
|
||||||
m_uuid = NimBLEUUID(const_cast<ble_uuid128_t*>(&service->uuid.u128));
|
m_uuid = NimBLEUUID(const_cast<ble_uuid128_t*>(&service->uuid.u128));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m_uuid = nullptr;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_startHandle = service->start_handle;
|
m_startHandle = service->start_handle;
|
||||||
m_endHandle = service->end_handle;
|
m_endHandle = service->end_handle;
|
||||||
NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteService()");
|
NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteService(): %s", m_uuid.toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -264,6 +264,37 @@ std::string NimBLEUUID::toString() const {
|
||||||
*/
|
*/
|
||||||
bool NimBLEUUID::operator ==(const NimBLEUUID & rhs) const {
|
bool NimBLEUUID::operator ==(const NimBLEUUID & rhs) const {
|
||||||
if(m_valueSet && rhs.m_valueSet) {
|
if(m_valueSet && rhs.m_valueSet) {
|
||||||
|
NIMBLE_LOGD(LOG_TAG,"Comparing UUIDs; type %u to %u; UUID %s to %s",
|
||||||
|
m_uuid.u.type, rhs.m_uuid.u.type,
|
||||||
|
this->toString().c_str(), rhs.toString().c_str());
|
||||||
|
|
||||||
|
if(m_uuid.u.type != rhs.m_uuid.u.type) {
|
||||||
|
uint8_t uuidBase[16] = {
|
||||||
|
0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
|
||||||
|
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
if(m_uuid.u.type == BLE_UUID_TYPE_128){
|
||||||
|
if(rhs.m_uuid.u.type == BLE_UUID_TYPE_16){
|
||||||
|
memcpy(uuidBase+12, &rhs.m_uuid.u16.value, 2);
|
||||||
|
} else if (rhs.m_uuid.u.type == BLE_UUID_TYPE_32){
|
||||||
|
memcpy(uuidBase+12, &rhs.m_uuid.u32.value, 4);
|
||||||
|
}
|
||||||
|
return memcmp(m_uuid.u128.value,uuidBase,16) == 0;
|
||||||
|
|
||||||
|
} else if(rhs.m_uuid.u.type == BLE_UUID_TYPE_128) {
|
||||||
|
if(m_uuid.u.type == BLE_UUID_TYPE_16){
|
||||||
|
memcpy(uuidBase+12, &m_uuid.u16.value, 2);
|
||||||
|
} else if (m_uuid.u.type == BLE_UUID_TYPE_32){
|
||||||
|
memcpy(uuidBase+12, &m_uuid.u32.value, 4);
|
||||||
|
}
|
||||||
|
return memcmp(rhs.m_uuid.u128.value,uuidBase,16) == 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ble_uuid_cmp(&m_uuid.u, &rhs.m_uuid.u) == 0;
|
return ble_uuid_cmp(&m_uuid.u, &rhs.m_uuid.u) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue