Skip to content

Adv data retrieve #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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