From fab7106bce62c96f0bd7a0c4e1548633f62c42dd Mon Sep 17 00:00:00 2001 From: h2zero Date: Tue, 19 Nov 2024 15:36:17 -0700 Subject: [PATCH] Add overload for `NimBLEAdvertising::setManufacturerData`. Adds an overload for `NimBLEAdvertising::setManufacturerData` that takes a `const uint8_t*` and , size_t` paramter. --- src/NimBLEAdvertising.cpp | 18 ++++++++++++------ src/NimBLEAdvertising.h | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index 8bffa3e..26077d2 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -151,23 +151,29 @@ void NimBLEAdvertising::setName(const std::string& name) { /** * @brief Set the advertised manufacturer data. * @param [in] data The data to advertise. + * @param [in] length The length of the data. */ -void NimBLEAdvertising::setManufacturerData(const std::string& data) { - std::vector(data.begin(), data.end()).swap(m_mfgData); +void NimBLEAdvertising::setManufacturerData(const uint8_t* data, size_t length) { + std::vector(data, data + length).swap(m_mfgData); m_advData.mfg_data = &m_mfgData[0]; m_advData.mfg_data_len = m_mfgData.size(); m_advDataSet = false; } // setManufacturerData +/** + * @brief Set the advertised manufacturer data. + * @param [in] data The data to advertise. + */ +void NimBLEAdvertising::setManufacturerData(const std::string& data) { + setManufacturerData(reinterpret_cast(data.data()), data.length()); +} // setManufacturerData + /** * @brief Set the advertised manufacturer data. * @param [in] data The data to advertise. */ void NimBLEAdvertising::setManufacturerData(const std::vector& data) { - std::vector(data.begin(), data.end()).swap(m_mfgData); - m_advData.mfg_data = &m_mfgData[0]; - m_advData.mfg_data_len = m_mfgData.size(); - m_advDataSet = false; + setManufacturerData(&data[0], data.size()); } // setManufacturerData /** diff --git a/src/NimBLEAdvertising.h b/src/NimBLEAdvertising.h index b0b6a5c..a84c84d 100644 --- a/src/NimBLEAdvertising.h +++ b/src/NimBLEAdvertising.h @@ -94,6 +94,7 @@ class NimBLEAdvertising { bool stop(); void setAppearance(uint16_t appearance); 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::vector& data); void setURI(const std::string& uri);