mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 21:20:55 +01:00
Add overloads for NimBLEAdvertising::setServiceData
* Added `NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length)` overload. * Added `NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data)` overload.
This commit is contained in:
parent
fab7106bce
commit
34cbf45f1f
2 changed files with 30 additions and 7 deletions
|
@ -191,31 +191,32 @@ void NimBLEAdvertising::setURI(const std::string& uri) {
|
||||||
* @brief Set the service data advertised for the UUID.
|
* @brief Set the service data advertised for the UUID.
|
||||||
* @param [in] uuid The UUID the service data belongs to.
|
* @param [in] uuid The UUID the service data belongs to.
|
||||||
* @param [in] data The data to advertise.
|
* @param [in] data The data to advertise.
|
||||||
|
* @param [in] length The length of the data.
|
||||||
* @note If data length is 0 the service data will not be advertised.
|
* @note If data length is 0 the service data will not be advertised.
|
||||||
*/
|
*/
|
||||||
void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::string& data) {
|
void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length) {
|
||||||
switch (uuid.bitSize()) {
|
switch (uuid.bitSize()) {
|
||||||
case 16: {
|
case 16: {
|
||||||
std::vector<uint8_t>(uuid.getValue(), uuid.getValue() + 2).swap(m_svcData16);
|
std::vector<uint8_t>(uuid.getValue(), uuid.getValue() + 2).swap(m_svcData16);
|
||||||
m_svcData16.insert(m_svcData16.end(), data.begin(), data.end());
|
m_svcData16.insert(m_svcData16.end(), data, data + length);
|
||||||
m_advData.svc_data_uuid16 = &m_svcData16[0];
|
m_advData.svc_data_uuid16 = &m_svcData16[0];
|
||||||
m_advData.svc_data_uuid16_len = (data.length() > 0) ? m_svcData16.size() : 0;
|
m_advData.svc_data_uuid16_len = (length > 0) ? m_svcData16.size() : 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 32: {
|
case 32: {
|
||||||
std::vector<uint8_t>(uuid.getValue(), uuid.getValue() + 4).swap(m_svcData32);
|
std::vector<uint8_t>(uuid.getValue(), uuid.getValue() + 4).swap(m_svcData32);
|
||||||
m_svcData32.insert(m_svcData32.end(), data.begin(), data.end());
|
m_svcData32.insert(m_svcData32.end(), data, data + length);
|
||||||
m_advData.svc_data_uuid32 = &m_svcData32[0];
|
m_advData.svc_data_uuid32 = &m_svcData32[0];
|
||||||
m_advData.svc_data_uuid32_len = (data.length() > 0) ? m_svcData32.size() : 0;
|
m_advData.svc_data_uuid32_len = (length > 0) ? m_svcData32.size() : 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 128: {
|
case 128: {
|
||||||
std::vector<uint8_t>(uuid.getValue(), uuid.getValue() + 16).swap(m_svcData128);
|
std::vector<uint8_t>(uuid.getValue(), uuid.getValue() + 16).swap(m_svcData128);
|
||||||
m_svcData128.insert(m_svcData128.end(), data.begin(), data.end());
|
m_svcData128.insert(m_svcData128.end(), data, data + length);
|
||||||
m_advData.svc_data_uuid128 = &m_svcData128[0];
|
m_advData.svc_data_uuid128 = &m_svcData128[0];
|
||||||
m_advData.svc_data_uuid128_len = (data.length() > 0) ? m_svcData128.size() : 0;
|
m_advData.svc_data_uuid128_len = (length > 0) ? m_svcData128.size() : 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +227,26 @@ void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::string
|
||||||
m_advDataSet = false;
|
m_advDataSet = false;
|
||||||
} // setServiceData
|
} // setServiceData
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the service data advertised for the UUID.
|
||||||
|
* @param [in] uuid The UUID the service data belongs to.
|
||||||
|
* @param [in] data The data to advertise.
|
||||||
|
* @note If data length is 0 the service data will not be advertised.
|
||||||
|
*/
|
||||||
|
void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data) {
|
||||||
|
setServiceData(uuid, data.data(), data.size());
|
||||||
|
} // setServiceData
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the service data advertised for the UUID.
|
||||||
|
* @param [in] uuid The UUID the service data belongs to.
|
||||||
|
* @param [in] data The data to advertise.
|
||||||
|
* @note If data length is 0 the service data will not be advertised.
|
||||||
|
*/
|
||||||
|
void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::string& data) {
|
||||||
|
setServiceData(uuid, reinterpret_cast<const uint8_t*>(data.data()), data.length());
|
||||||
|
} // setServiceData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the type of connectable mode to advertise.
|
* @brief Set the type of connectable mode to advertise.
|
||||||
* @param [in] mode The connectable mode:
|
* @param [in] mode The connectable mode:
|
||||||
|
|
|
@ -98,9 +98,11 @@ class NimBLEAdvertising {
|
||||||
void setManufacturerData(const std::string& data);
|
void setManufacturerData(const std::string& data);
|
||||||
void setManufacturerData(const std::vector<uint8_t>& data);
|
void setManufacturerData(const std::vector<uint8_t>& data);
|
||||||
void setURI(const std::string& uri);
|
void setURI(const std::string& uri);
|
||||||
|
void setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length);
|
||||||
void setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
void setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
||||||
void setConnectableMode(uint8_t mode);
|
void setConnectableMode(uint8_t mode);
|
||||||
void setDiscoverableMode(uint8_t mode);
|
void setDiscoverableMode(uint8_t mode);
|
||||||
|
void setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data);
|
||||||
void setAdvertisingInterval(uint16_t interval);
|
void setAdvertisingInterval(uint16_t interval);
|
||||||
void setMaxInterval(uint16_t maxInterval);
|
void setMaxInterval(uint16_t maxInterval);
|
||||||
void setMinInterval(uint16_t minInterval);
|
void setMinInterval(uint16_t minInterval);
|
||||||
|
|
Loading…
Reference in a new issue