File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,24 @@ std::string NimBLEAdvertisedDevice::getURI() {
203
203
return " " ;
204
204
} // getURI
205
205
206
+ /* *
207
+ * @brief Get the data from any type available in the advertisement
208
+ * @param [in] type The advertised data type BLE_HS_ADV_TYPE
209
+ * @return The data available under the type `type`
210
+ */
211
+ std::string NimBLEAdvertisedDevice::getPayloadByType (uint16_t type) {
212
+ size_t data_loc = 0 ;
213
+
214
+ if (findAdvField (type, 0 , &data_loc) > 0 ) {
215
+ ble_hs_adv_field *field = (ble_hs_adv_field *)&m_payload[data_loc];
216
+ if (field->length > 1 ) {
217
+ return std::string ((char *)field->value , field->length - 1 );
218
+ }
219
+ }
220
+
221
+ return " " ;
222
+ } // getPayloadByType
223
+
206
224
207
225
/* *
208
226
* @brief Get the advertised name.
@@ -556,6 +574,14 @@ bool NimBLEAdvertisedDevice::haveURI() {
556
574
return findAdvField (BLE_HS_ADV_TYPE_URI) > 0 ;
557
575
} // haveURI
558
576
577
+ /* *
578
+ * @brief Does this advertisement have a adv type `type`?
579
+ * @return True if there is a `type` present.
580
+ */
581
+ bool NimBLEAdvertisedDevice::haveType (uint16_t type) {
582
+ return findAdvField (type) > 0 ;
583
+ }
584
+
559
585
560
586
/* *
561
587
* @brief Does the advertisement contain a target address?
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ class NimBLEAdvertisedDevice {
53
53
uint8_t getManufacturerDataCount ();
54
54
std::string getManufacturerData (uint8_t index = 0 );
55
55
std::string getURI ();
56
+ std::string getPayloadByType (uint16_t type);
56
57
57
58
/* *
58
59
* @brief A template to convert the service data to <type\>.
@@ -134,6 +135,7 @@ class NimBLEAdvertisedDevice {
134
135
bool haveAdvInterval ();
135
136
bool haveTargetAddress ();
136
137
bool haveURI ();
138
+ bool haveType (uint16_t type);
137
139
std::string toString ();
138
140
bool isConnectable ();
139
141
bool isLegacyAdvertisement ();
You can’t perform that action at this time.
0 commit comments