Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index parameter for multiple manufacturer data sets. #506

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/NimBLEAdvertisedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,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);
Expand All @@ -156,6 +158,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.
Expand Down
3 changes: 2 additions & 1 deletion src/NimBLEAdvertisedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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();

/**
Expand Down