Skip to content

Commit e080601

Browse files
committed
Add retrieval of manufacturer data
1 parent bd492be commit e080601

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Diff for: src/BLEDevice.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,49 @@ int BLEDevice::advertisementData(uint8_t value[], int length) const
205205
return length;
206206
}
207207

208+
bool BLEDevice::hasManufacturerData() const
209+
{
210+
return (manufacturerDataLength() > 0);
211+
}
212+
213+
int BLEDevice::manufacturerDataLength() const
214+
{
215+
int length = 0;
216+
217+
for (int i = 0; i < _eirDataLength;) {
218+
int eirLength = _eirData[i++];
219+
int eirType = _eirData[i++];
220+
221+
if (eirType == 0xFF) {
222+
length = (eirLength - 1);
223+
break;
224+
}
225+
226+
i += (eirLength - 1);
227+
}
228+
229+
return length;
230+
}
231+
232+
int BLEDevice::manufacturerData(uint8_t value[], int length) const
233+
{
234+
for (int i = 0; i < _eirDataLength;) {
235+
int eirLength = _eirData[i++];
236+
int eirType = _eirData[i++];
237+
238+
if (eirType == 0xFF) {
239+
if (length > (eirLength - 1)) length = (eirLength - 1);
240+
241+
memcpy(value, &_eirData[i], length);
242+
break;
243+
}
244+
245+
i += (eirLength - 1);
246+
}
247+
248+
return length;
249+
}
250+
208251
int BLEDevice::rssi()
209252
{
210253
uint16_t handle = ATT.connectionHandle(_addressType, _address);

Diff for: src/BLEDevice.h

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class BLEDevice {
6363
int advertisementDataLength() const;
6464
int advertisementData(uint8_t value[], int length) const;
6565

66+
bool hasManufacturerData() const;
67+
int manufacturerDataLength() const;
68+
int manufacturerData(uint8_t value[], int length) const;
69+
6670
virtual int rssi();
6771

6872
bool connect();

0 commit comments

Comments
 (0)