Advertising: Add overloaded method for addData.

* Implements addData(char * data, size_t length) as an alternative to passing a std::string.
This commit is contained in:
h2zero 2020-07-27 21:38:22 -06:00
parent 4723b1cc53
commit f1a13d5949
2 changed files with 14 additions and 0 deletions

View file

@ -451,6 +451,19 @@ void NimBLEAdvertisementData::addData(const std::string &data) {
} // addData } // 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. * @brief Set the appearance.
* @param [in] appearance The appearance code value. * @param [in] appearance The appearance code value.

View file

@ -57,6 +57,7 @@ public:
void setServiceData(const NimBLEUUID &uuid, const std::string &data); void setServiceData(const NimBLEUUID &uuid, const std::string &data);
void setShortName(const std::string &name); void setShortName(const std::string &name);
void addData(const std::string &data); // Add data to the payload. 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. std::string getPayload(); // Retrieve the current advert payload.
private: private: