Skip to content

Commit

Permalink
Merge pull request #183 from polldo/adv-data-retrieve
Browse files Browse the repository at this point in the history
Adv data retrieve
  • Loading branch information
facchinm authored May 13, 2022
2 parents 8f9e785 + e080601 commit f107880
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/BLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f107880

Please sign in to comment.