Skip to content

Commit

Permalink
Add overloaded setManufacturerData to allow vector of uint8_t (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
eighty2fifty1 authored May 28, 2023
1 parent bb8b670 commit 53cb3ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/NimBLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ void NimBLEAdvertising::setManufacturerData(const std::string &data) {
} // setManufacturerData


/**
* @brief Set the advertised manufacturer data.
* @param [in] data The data to advertise.
*/
void NimBLEAdvertising::setManufacturerData(const std::vector<uint8_t> &data) {
m_mfgData = data;
m_advData.mfg_data = &m_mfgData[0];
m_advData.mfg_data_len = m_mfgData.size();
m_advDataSet = false;
} // setManufacturerData


/**
* @brief Set the advertised URI.
* @param [in] uri The URI to advertise.
Expand Down Expand Up @@ -831,6 +843,18 @@ void NimBLEAdvertisementData::setManufacturerData(const std::string &data) {
} // setManufacturerData


/**
* @brief Set manufacturer specific data.
* @param [in] data The manufacturer data to advertise.
*/
void NimBLEAdvertisementData::setManufacturerData(const std::vector<uint8_t> &data) {
char cdata[2];
cdata[0] = data.size() + 1;
cdata[1] = BLE_HS_ADV_TYPE_MFG_DATA ; // 0xff
addData(std::string(cdata, 2) + std::string((char*)&data[0], data.size()));
} // setManufacturerData


/**
* @brief Set the URI to advertise.
* @param [in] uri The uri to advertise.
Expand Down
2 changes: 2 additions & 0 deletions src/NimBLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class NimBLEAdvertisementData {
void setCompleteServices32(const std::vector<NimBLEUUID> &v_uuid);
void setFlags(uint8_t);
void setManufacturerData(const std::string &data);
void setManufacturerData(const std::vector<uint8_t> &data);
void setURI(const std::string &uri);
void setName(const std::string &name);
void setPartialServices(const NimBLEUUID &uuid);
Expand Down Expand Up @@ -96,6 +97,7 @@ class NimBLEAdvertising {
void setAppearance(uint16_t appearance);
void setName(const std::string &name);
void setManufacturerData(const std::string &data);
void setManufacturerData(const std::vector<uint8_t> &data);
void setURI(const std::string &uri);
void setServiceData(const NimBLEUUID &uuid, const std::string &data);
void setAdvertisementType(uint8_t adv_type);
Expand Down

0 comments on commit 53cb3ce

Please sign in to comment.