From 4e6793f602ee5e8f2017ab0ef7e8792632950bd2 Mon Sep 17 00:00:00 2001 From: h2zero <32826625+h2zero@users.noreply.github.com> Date: Thu, 6 Apr 2023 14:32:50 -0600 Subject: [PATCH] Add index parameter for multiple manufacturer data sets. (#506) Adds an index parameter to NimBLEAdvertisedDevice::getManufacturerData to allow for selecting from multiple instances in the advertisements. Adds NimBLEAdvertisedDevice::getManufacturerDataCount to get the number of manufacturer data sets present in the advertised data. --- src/NimBLEAdvertisedDevice.cpp | 17 ++++++++++++++--- src/NimBLEAdvertisedDevice.h | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/NimBLEAdvertisedDevice.cpp b/src/NimBLEAdvertisedDevice.cpp index 550d8d37..0c38ca42 100644 --- a/src/NimBLEAdvertisedDevice.cpp +++ b/src/NimBLEAdvertisedDevice.cpp @@ -159,12 +159,14 @@ uint16_t NimBLEAdvertisedDevice::getMaxInterval() { /** * @brief Get the manufacturer data. - * @return The manufacturer data of the advertised device. + * @param [in] index The index of the of the manufacturer data set to get. + * @return The manufacturer data. */ -std::string NimBLEAdvertisedDevice::getManufacturerData() { +std::string NimBLEAdvertisedDevice::getManufacturerData(uint8_t index) { size_t data_loc = 0; + index++; - if(findAdvField(BLE_HS_ADV_TYPE_MFG_DATA, 0, &data_loc) > 0) { + if(findAdvField(BLE_HS_ADV_TYPE_MFG_DATA, index, &data_loc) > 0) { ble_hs_adv_field *field = (ble_hs_adv_field *)&m_payload[data_loc]; if(field->length > 1) { return std::string((char*)field->value, field->length - 1); @@ -175,6 +177,15 @@ std::string NimBLEAdvertisedDevice::getManufacturerData() { } // getManufacturerData +/** + * @brief Get the count of manufacturer data sets. + * @return The number of manufacturer data sets. + */ +uint8_t NimBLEAdvertisedDevice::getManufacturerDataCount() { + return findAdvField(BLE_HS_ADV_TYPE_MFG_DATA); +} // getManufacturerDataCount + + /** * @brief Get the URI from the advertisement. * @return The URI data. diff --git a/src/NimBLEAdvertisedDevice.h b/src/NimBLEAdvertisedDevice.h index 8b921d77..cb232086 100644 --- a/src/NimBLEAdvertisedDevice.h +++ b/src/NimBLEAdvertisedDevice.h @@ -50,7 +50,8 @@ class NimBLEAdvertisedDevice { uint16_t getAdvInterval(); uint16_t getMinInterval(); uint16_t getMaxInterval(); - std::string getManufacturerData(); + uint8_t getManufacturerDataCount(); + std::string getManufacturerData(uint8_t index = 0); std::string getURI(); /**