Skip to content

Commit 53cb3ce

Browse files
Add overloaded setManufacturerData to allow vector of uint8_t (#529)
1 parent bb8b670 commit 53cb3ce

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/NimBLEAdvertising.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ void NimBLEAdvertising::setManufacturerData(const std::string &data) {
156156
} // setManufacturerData
157157

158158

159+
/**
160+
* @brief Set the advertised manufacturer data.
161+
* @param [in] data The data to advertise.
162+
*/
163+
void NimBLEAdvertising::setManufacturerData(const std::vector<uint8_t> &data) {
164+
m_mfgData = data;
165+
m_advData.mfg_data = &m_mfgData[0];
166+
m_advData.mfg_data_len = m_mfgData.size();
167+
m_advDataSet = false;
168+
} // setManufacturerData
169+
170+
159171
/**
160172
* @brief Set the advertised URI.
161173
* @param [in] uri The URI to advertise.
@@ -831,6 +843,18 @@ void NimBLEAdvertisementData::setManufacturerData(const std::string &data) {
831843
} // setManufacturerData
832844

833845

846+
/**
847+
* @brief Set manufacturer specific data.
848+
* @param [in] data The manufacturer data to advertise.
849+
*/
850+
void NimBLEAdvertisementData::setManufacturerData(const std::vector<uint8_t> &data) {
851+
char cdata[2];
852+
cdata[0] = data.size() + 1;
853+
cdata[1] = BLE_HS_ADV_TYPE_MFG_DATA ; // 0xff
854+
addData(std::string(cdata, 2) + std::string((char*)&data[0], data.size()));
855+
} // setManufacturerData
856+
857+
834858
/**
835859
* @brief Set the URI to advertise.
836860
* @param [in] uri The uri to advertise.

src/NimBLEAdvertising.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class NimBLEAdvertisementData {
5959
void setCompleteServices32(const std::vector<NimBLEUUID> &v_uuid);
6060
void setFlags(uint8_t);
6161
void setManufacturerData(const std::string &data);
62+
void setManufacturerData(const std::vector<uint8_t> &data);
6263
void setURI(const std::string &uri);
6364
void setName(const std::string &name);
6465
void setPartialServices(const NimBLEUUID &uuid);
@@ -96,6 +97,7 @@ class NimBLEAdvertising {
9697
void setAppearance(uint16_t appearance);
9798
void setName(const std::string &name);
9899
void setManufacturerData(const std::string &data);
100+
void setManufacturerData(const std::vector<uint8_t> &data);
99101
void setURI(const std::string &uri);
100102
void setServiceData(const NimBLEUUID &uuid, const std::string &data);
101103
void setAdvertisementType(uint8_t adv_type);

0 commit comments

Comments
 (0)