Skip to content

Commit

Permalink
Add retrieval of manufacturer data
Browse files Browse the repository at this point in the history
  • Loading branch information
polldo committed May 27, 2021
1 parent bd492be commit e080601
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,49 @@ int BLEDevice::advertisementData(uint8_t value[], int length) const
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
4 changes: 4 additions & 0 deletions src/BLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class BLEDevice {
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 e080601

Please sign in to comment.