From f1a13d5949be7c754b12ea4fe43626cea832117a Mon Sep 17 00:00:00 2001 From: h2zero Date: Mon, 27 Jul 2020 21:38:22 -0600 Subject: [PATCH] Advertising: Add overloaded method for addData. * Implements addData(char * data, size_t length) as an alternative to passing a std::string. --- src/NimBLEAdvertising.cpp | 13 +++++++++++++ src/NimBLEAdvertising.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index fbe88ae..f626cc7 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -451,6 +451,19 @@ void NimBLEAdvertisementData::addData(const std::string &data) { } // addData +/** + * @brief Add data to the payload to be advertised. + * @param [in] data The data to be added to the payload. + * @param [in] length The size of data to be added to the payload. + */ +void NimBLEAdvertisementData::addData(char * data, size_t length){ + if ((m_payload.length() + length) > BLE_HS_ADV_MAX_SZ) { + return; + } + m_payload.append(data,length); +} // addData + + /** * @brief Set the appearance. * @param [in] appearance The appearance code value. diff --git a/src/NimBLEAdvertising.h b/src/NimBLEAdvertising.h index 4ac013a..ed0ffc1 100644 --- a/src/NimBLEAdvertising.h +++ b/src/NimBLEAdvertising.h @@ -57,6 +57,7 @@ public: void setServiceData(const NimBLEUUID &uuid, const std::string &data); void setShortName(const std::string &name); void addData(const std::string &data); // Add data to the payload. + void addData(char * data, size_t length); std::string getPayload(); // Retrieve the current advert payload. private: