@@ -115,6 +115,15 @@ std::string BLEAdvertisedDevice::getServiceData() {
115
115
} // getServiceData
116
116
117
117
118
+ /* *
119
+ * @brief Get the service data UUID.
120
+ * @return The service data UUID.
121
+ */
122
+ BLEUUID BLEAdvertisedDevice::getServiceDataUUID () {
123
+ return m_serviceDataUUID;
124
+ } // getServiceDataUUID
125
+
126
+
118
127
/* *
119
128
* @brief Get the Service UUID.
120
129
* @return The Service UUID of the advertised device.
@@ -294,11 +303,45 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload) {
294
303
break ;
295
304
} // ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE
296
305
297
- case ESP_BLE_AD_TYPE_SERVICE_DATA: { // Adv Data Type: 0x16 (Service Data)
298
- setServiceData (std::string (reinterpret_cast <char *>(payload), length));
306
+ case ESP_BLE_AD_TYPE_SERVICE_DATA: { // Adv Data Type: 0x16 (Service Data) - 2 byte UUID
307
+ if (length < 2 ) {
308
+ ESP_LOGE (LOG_TAG, " Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA" );
309
+ break ;
310
+ }
311
+ uint16_t uuid = *(uint16_t *)payload;
312
+ setServiceDataUUID (BLEUUID (uuid));
313
+ if (length > 2 ) {
314
+ setServiceData (std::string (reinterpret_cast <char *>(payload+2 ), length-2 ));
315
+ }
299
316
break ;
300
317
} // ESP_BLE_AD_TYPE_SERVICE_DATA
301
318
319
+ case ESP_BLE_AD_TYPE_32SERVICE_DATA: { // Adv Data Type: 0x20 (Service Data) - 4 byte UUID
320
+ if (length < 4 ) {
321
+ ESP_LOGE (LOG_TAG, " Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA" );
322
+ break ;
323
+ }
324
+ uint32_t uuid = *(uint32_t *)payload;
325
+ setServiceDataUUID (BLEUUID (uuid));
326
+ if (length > 4 ) {
327
+ setServiceData (std::string (reinterpret_cast <char *>(payload+4 ), length-4 ));
328
+ }
329
+ break ;
330
+ } // ESP_BLE_AD_TYPE_32SERVICE_DATA
331
+
332
+ case ESP_BLE_AD_TYPE_128SERVICE_DATA: { // Adv Data Type: 0x21 (Service Data) - 16 byte UUID
333
+ if (length < 16 ) {
334
+ ESP_LOGE (LOG_TAG, " Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA" );
335
+ break ;
336
+ }
337
+
338
+ setServiceDataUUID (BLEUUID (payload, (size_t )16 , false ));
339
+ if (length > 16 ) {
340
+ setServiceData (std::string (reinterpret_cast <char *>(payload+16 ), length-16 ));
341
+ }
342
+ break ;
343
+ } // ESP_BLE_AD_TYPE_32SERVICE_DATA
344
+
302
345
default : {
303
346
ESP_LOGD (LOG_TAG, " Unhandled type: adType: %d - 0x%.2x" , ad_type, ad_type);
304
347
break ;
@@ -418,6 +461,16 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
418
461
} // setServiceData
419
462
420
463
464
+ /* *
465
+ * @brief Set the ServiceDataUUID value.
466
+ * @param [in] data ServiceDataUUID value.
467
+ */
468
+ void BLEAdvertisedDevice::setServiceDataUUID (BLEUUID uuid) {
469
+ m_haveServiceData = true ; // Set the flag that indicates we have service data.
470
+ m_serviceDataUUID = uuid;
471
+ } // setServiceDataUUID
472
+
473
+
421
474
/* *
422
475
* @brief Set the power level for this device.
423
476
* @param [in] txPower The discovered power level.
@@ -453,5 +506,8 @@ std::string BLEAdvertisedDevice::toString() {
453
506
return ss.str ();
454
507
} // toString
455
508
509
+
510
+
511
+
456
512
#endif /* CONFIG_BT_ENABLED */
457
513
0 commit comments