Skip to content

Commit 3976074

Browse files
committed
Advertising: Add overloaded method for addData.
* Implements addData(char * data, size_t length) as an alternative to passing a std::string.
1 parent 780b935 commit 3976074

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/NimBLEAdvertising.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,19 @@ void NimBLEAdvertisementData::addData(const std::string &data) {
451451
} // addData
452452

453453

454+
/**
455+
* @brief Add data to the payload to be advertised.
456+
* @param [in] data The data to be added to the payload.
457+
* @param [in] length The size of data to be added to the payload.
458+
*/
459+
void NimBLEAdvertisementData::addData(char * data, size_t length){
460+
if ((m_payload.length() + length) > BLE_HS_ADV_MAX_SZ) {
461+
return;
462+
}
463+
m_payload.append(data,length);
464+
} // addData
465+
466+
454467
/**
455468
* @brief Set the appearance.
456469
* @param [in] appearance The appearance code value.

src/NimBLEAdvertising.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class NimBLEAdvertisementData {
5757
void setServiceData(const NimBLEUUID &uuid, const std::string &data);
5858
void setShortName(const std::string &name);
5959
void addData(const std::string &data); // Add data to the payload.
60+
void addData(char * data, size_t length);
6061
std::string getPayload(); // Retrieve the current advert payload.
6162

6263
private:

0 commit comments

Comments
 (0)