Add overload for NimBLEAdvertising::setManufacturerData.

Adds an overload for `NimBLEAdvertising::setManufacturerData` that takes a `const uint8_t*` and , size_t` paramter.
This commit is contained in:
h2zero 2024-11-19 15:36:17 -07:00
parent 1102bb71aa
commit a7bd440cba
2 changed files with 13 additions and 6 deletions

View file

@ -151,23 +151,29 @@ void NimBLEAdvertising::setName(const std::string& name) {
/** /**
* @brief Set the advertised manufacturer data. * @brief Set the advertised manufacturer data.
* @param [in] data The data to advertise. * @param [in] data The data to advertise.
* @param [in] length The length of the data.
*/ */
void NimBLEAdvertising::setManufacturerData(const std::string& data) { void NimBLEAdvertising::setManufacturerData(const uint8_t* data, size_t length) {
std::vector<uint8_t>(data.begin(), data.end()).swap(m_mfgData); std::vector<uint8_t>(data, data + length).swap(m_mfgData);
m_advData.mfg_data = &m_mfgData[0]; m_advData.mfg_data = &m_mfgData[0];
m_advData.mfg_data_len = m_mfgData.size(); m_advData.mfg_data_len = m_mfgData.size();
m_advDataSet = false; m_advDataSet = false;
} // setManufacturerData } // setManufacturerData
/**
* @brief Set the advertised manufacturer data.
* @param [in] data The data to advertise.
*/
void NimBLEAdvertising::setManufacturerData(const std::string& data) {
setManufacturerData(reinterpret_cast<const uint8_t*>(data.data()), data.length());
} // setManufacturerData
/** /**
* @brief Set the advertised manufacturer data. * @brief Set the advertised manufacturer data.
* @param [in] data The data to advertise. * @param [in] data The data to advertise.
*/ */
void NimBLEAdvertising::setManufacturerData(const std::vector<uint8_t>& data) { void NimBLEAdvertising::setManufacturerData(const std::vector<uint8_t>& data) {
std::vector<uint8_t>(data.begin(), data.end()).swap(m_mfgData); setManufacturerData(&data[0], data.size());
m_advData.mfg_data = &m_mfgData[0];
m_advData.mfg_data_len = m_mfgData.size();
m_advDataSet = false;
} // setManufacturerData } // setManufacturerData
/** /**

View file

@ -94,6 +94,7 @@ class NimBLEAdvertising {
bool stop(); bool stop();
void setAppearance(uint16_t appearance); void setAppearance(uint16_t appearance);
void setName(const std::string& name); void setName(const std::string& name);
void setManufacturerData(const uint8_t* data, size_t length);
void setManufacturerData(const std::string& data); void setManufacturerData(const std::string& data);
void setManufacturerData(const std::vector<uint8_t>& data); void setManufacturerData(const std::vector<uint8_t>& data);
void setURI(const std::string& uri); void setURI(const std::string& uri);