Skip to content

Commit 970718f

Browse files
committed
Merge branch 'pr-183'
2 parents e3a2cb4 + 2f9c155 commit 970718f

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* https://github.com/arduino-libraries/ArduinoBLE/pull/110
1010
* https://github.com/arduino-libraries/ArduinoBLE/pull/134
1111
* https://github.com/arduino-libraries/ArduinoBLE/pull/156
12+
* https://github.com/arduino-libraries/ArduinoBLE/pull/183
1213
<!-- pull requests -->
1314

1415
You can consider this as an experimental version of the library, that you can use to test features contributed by the community that haven't been merged yet.

src/BLEDevice.cpp

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ bool BLEDevice::hasLocalName() const
8686
return (localName().length() > 0);
8787
}
8888

89-
bool BLEDevice::hasManufacturerData() const
90-
{
91-
return (manufacturerData().length() > 0);
92-
}
93-
9489
bool BLEDevice::hasAdvertisedServiceUuid() const
9590
{
9691
return hasAdvertisedServiceUuid(0);
@@ -209,15 +204,68 @@ String BLEDevice::advertisedServiceUuid(int index) const
209204
return serviceUuid;
210205
}
211206

212-
int BLEDevice::advertisementData(uint8_t value[], int length)
207+
bool BLEDevice::hasAdvertisementData() const
208+
{
209+
return (_eirDataLength > 0);
210+
}
211+
212+
int BLEDevice::advertisementDataLength() const
213+
{
214+
return _eirDataLength;
215+
}
216+
217+
int BLEDevice::advertisementData(uint8_t value[], int length) const
213218
{
214-
if (_eirDataLength > length) return 0; // Check that buffer size is sufficient
219+
if (length > _eirDataLength) length = _eirDataLength;
215220

216-
if (_eirDataLength) {
217-
memcpy(value, _eirData, _eirDataLength);
221+
if (length) {
222+
memcpy(value, _eirData, length);
218223
}
219224

220-
return _eirDataLength;
225+
return length;
226+
}
227+
228+
bool BLEDevice::hasManufacturerData() const
229+
{
230+
return (manufacturerDataLength() > 0);
231+
}
232+
233+
int BLEDevice::manufacturerDataLength() const
234+
{
235+
int length = 0;
236+
237+
for (int i = 0; i < _eirDataLength;) {
238+
int eirLength = _eirData[i++];
239+
int eirType = _eirData[i++];
240+
241+
if (eirType == 0xFF) {
242+
length = (eirLength - 1);
243+
break;
244+
}
245+
246+
i += (eirLength - 1);
247+
}
248+
249+
return length;
250+
}
251+
252+
int BLEDevice::manufacturerData(uint8_t value[], int length) const
253+
{
254+
for (int i = 0; i < _eirDataLength;) {
255+
int eirLength = _eirData[i++];
256+
int eirType = _eirData[i++];
257+
258+
if (eirType == 0xFF) {
259+
if (length > (eirLength - 1)) length = (eirLength - 1);
260+
261+
memcpy(value, &_eirData[i], length);
262+
break;
263+
}
264+
265+
i += (eirLength - 1);
266+
}
267+
268+
return length;
221269
}
222270

223271
int BLEDevice::rssi()

src/BLEDevice.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class BLEDevice {
5050
virtual String address() const;
5151

5252
bool hasLocalName() const;
53-
bool hasManufacturerData() const;
5453

5554
bool hasAdvertisedServiceUuid() const;
5655
bool hasAdvertisedServiceUuid(int index) const;
@@ -61,7 +60,13 @@ class BLEDevice {
6160
String advertisedServiceUuid() const;
6261
String advertisedServiceUuid(int index) const;
6362

64-
int advertisementData(uint8_t value[], int length);
63+
bool hasAdvertisementData() const;
64+
int advertisementDataLength() const;
65+
int advertisementData(uint8_t value[], int length) const;
66+
67+
bool hasManufacturerData() const;
68+
int manufacturerDataLength() const;
69+
int manufacturerData(uint8_t value[], int length) const;
6570

6671
virtual int rssi();
6772

0 commit comments

Comments
 (0)