diff --git a/src/BLEDevice.cpp b/src/BLEDevice.cpp index fa806104..5f64c1d6 100644 --- a/src/BLEDevice.cpp +++ b/src/BLEDevice.cpp @@ -184,6 +184,70 @@ String BLEDevice::advertisedServiceUuid(int index) const return serviceUuid; } +bool BLEDevice::hasAdvertisementData() const +{ + return (_eirDataLength > 0); +} + +int BLEDevice::advertisementDataLength() const +{ + return _eirDataLength; +} + +int BLEDevice::advertisementData(uint8_t value[], int length) const +{ + if (length > _eirDataLength) length = _eirDataLength; + + if (length) { + memcpy(value, _eirData, length); + } + + return length; +} + +bool BLEDevice::hasManufacturerData() const +{ + return (manufacturerDataLength() > 0); +} + +int BLEDevice::manufacturerDataLength() const +{ + int length = 0; + + for (int i = 0; i < _eirDataLength;) { + int eirLength = _eirData[i++]; + int eirType = _eirData[i++]; + + if (eirType == 0xFF) { + length = (eirLength - 1); + break; + } + + i += (eirLength - 1); + } + + return length; +} + +int BLEDevice::manufacturerData(uint8_t value[], int length) const +{ + for (int i = 0; i < _eirDataLength;) { + int eirLength = _eirData[i++]; + int eirType = _eirData[i++]; + + if (eirType == 0xFF) { + if (length > (eirLength - 1)) length = (eirLength - 1); + + memcpy(value, &_eirData[i], length); + break; + } + + i += (eirLength - 1); + } + + return length; +} + int BLEDevice::rssi() { uint16_t handle = ATT.connectionHandle(_addressType, _address); diff --git a/src/BLEDevice.h b/src/BLEDevice.h index cbe79c71..bf710744 100644 --- a/src/BLEDevice.h +++ b/src/BLEDevice.h @@ -59,6 +59,14 @@ class BLEDevice { String advertisedServiceUuid() const; String advertisedServiceUuid(int index) const; + bool hasAdvertisementData() const; + int advertisementDataLength() const; + int advertisementData(uint8_t value[], int length) const; + + bool hasManufacturerData() const; + int manufacturerDataLength() const; + int manufacturerData(uint8_t value[], int length) const; + virtual int rssi(); bool connect(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy