From 2b7a8b67aef227bfdb4c8da4178bd1aa48961f79 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 26e5553..10ccaf6 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 e3cd540..ca03dd0 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);