@@ -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-
9489bool 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
223271int BLEDevice::rssi ()
0 commit comments