mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-18 09:10:47 +01:00
4980e6a10a
* General code cleanup. * `NimBLEAdvertisementData` moved to it's own .h and .cpp files. * Added new method, `NimBLEAdvertising::setPreferredParams` that takes the min and max preferred connection parameters as an alternative for `setMinPreferred` and `setMaxPreferred`. * Added new method, `NimBLEAdvertising::setAdvertisingInterval` Sets the advertisement interval for min and max to the same value instead of calling `setMinInterval` and `setMaxInterval` separately if there is not value difference. * `NimBLEAdvertisementData` payload is now stored in `std::vector<uint8_t>` instead of `std::string`. * `NimBLEAdvertisementData::getPayload` now returns `std::vector<uint8_t>` instead of `std::string`. * `NimBLEAdvertisementData::addData` now takes either a `std::vector<uint8_t>` or `uint8_t* + length` instead of `std::string` or `char + length`. * `NimBLEAdvertisementData::setName` now takes an optional `bool` parameter to indicate if the name is complete or incomplete, default = complete. * `NimBLEAdvertising::start` No longer takes a callback pointer parameter, instead the new method `NimBLEAdvertising::setAdvertisingCompleteCallback` should be used. * `NimBLEAdvertising::setAdvertisementType` has been renamed to `NimBLEAdvertising::setConnectableMode` to better reflect it's function. * `NimBLEAdvertising::setScanResponse` has been renamed to `NimBLEAdvertising::enableScanResponse` to better reflect it's function. * Scan response is no longer enabled by default. * Added new method, `NimBLEAdvertising::setDiscoverableMode` to allow applications to control the discoverability of the advertiser. * Advertising the name and TX power of the device will no longer happen by default and should be set manually by the application. * Added overload for `NimBLEAdvertising::setManufacturerData` that takes a `const uint8_t*` and , size_t` paramter. * Added overload for `NimBLEAdvertising::setServiceData` that takes `const NimBLEUUID& uuid`, ` const uint8_t* data`, ` size_t length` as parameters. * Added overload for `NimBLEAdvertising::setServiceData` that takes `const NimBLEUUID& uuid`, `const std::vector<uint8_t>&` as parameters. * All `NimBLEAdvertisementData` functions that change data values now return `bool`, true = success. * All `NimBLEAdvertising` functions that change data values now return `bool`, true = success. * `NimBLEAdvertising::setMinPreferred` and `NimBLEAdvertising::setMaxPreferred` have been removed, use `NimBLEAdvertising::setPreferredParams` instead. * All advertising data is now stored in instances of `NimBLEAdvertisingData` and vectors removed from `NimBLEAdvertising`. * `NimBLEAdvertising::setAdvertisementData` and `NimBLEAdvertising::setScanResponseData` now return `bool`, true = success. * Added new method, `NimBLEAdvertisementData::removeData`, which takes a parameter `uint8_t type`, the data type to remove. * Added new method, `NimBLEAdvertisementData::toString`, which will print the data in hex. * Added new method, `NimBLEAdvertising::getAdvertisementData`, which returns a reference to the currently set advertisement data. * Added new method, `NimBLEAdvertising::getScanData`, which returns a reference to the currently set scan response data. * Added overloads for `NimBLEAdvertising::removeServiceUUID` and `NimBLEAdvertisementData::removeServiceUUID` to accept a `const char*` * Added new method, `NimBLEAdvertising::clearData`, which will clear the advertisement and scan response data.
70 lines
2.7 KiB
C++
70 lines
2.7 KiB
C++
/*
|
|
* NimBLEAdvertisementData.h
|
|
*
|
|
* Created: on November 24, 2024
|
|
* Author H2zero
|
|
*
|
|
*/
|
|
|
|
#ifndef NIMBLE_CPP_ADVERTISEMENT_DATA_H_
|
|
#define NIMBLE_CPP_ADVERTISEMENT_DATA_H_
|
|
|
|
#include "nimconfig.h"
|
|
#if (defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) && !CONFIG_BT_NIMBLE_EXT_ADV) || \
|
|
defined(_DOXYGEN_)
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class NimBLEUUID;
|
|
/**
|
|
* @brief Advertisement data set by the programmer to be published by the BLE server.
|
|
*/
|
|
class NimBLEAdvertisementData {
|
|
// Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will
|
|
// be exposed on demand/request or as time permits.
|
|
//
|
|
public:
|
|
bool addData(const uint8_t* data, size_t length);
|
|
bool addData(const std::vector<uint8_t>& data);
|
|
bool setAppearance(uint16_t appearance);
|
|
bool setFlags(uint8_t);
|
|
bool addTxPower();
|
|
bool setPreferredParams(uint16_t minInterval, uint16_t maxInterval);
|
|
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
|
bool addServiceUUID(const char* serviceUUID);
|
|
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
|
bool removeServiceUUID(const char* serviceUUID);
|
|
bool removeServices();
|
|
bool setManufacturerData(const uint8_t* data, size_t length);
|
|
bool setManufacturerData(const std::string& data);
|
|
bool setManufacturerData(const std::vector<uint8_t>& data);
|
|
bool setURI(const std::string& uri);
|
|
bool setName(const std::string& name, bool isComplete = true);
|
|
bool setShortName(const std::string& name);
|
|
bool setCompleteServices(const NimBLEUUID& uuid);
|
|
bool setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
|
bool setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
|
bool setPartialServices(const NimBLEUUID& uuid);
|
|
bool setPartialServices16(const std::vector<NimBLEUUID>& uuids);
|
|
bool setPartialServices32(const std::vector<NimBLEUUID>& uuids);
|
|
bool setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length);
|
|
bool setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
|
bool setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data);
|
|
bool removeData(uint8_t type);
|
|
void clearData();
|
|
int getDataLocation(uint8_t type) const;
|
|
|
|
std::string toString() const;
|
|
std::vector<uint8_t> getPayload() const;
|
|
|
|
private:
|
|
friend class NimBLEAdvertising;
|
|
|
|
bool setServices(bool complete, uint8_t size, const std::vector<NimBLEUUID>& v_uuid);
|
|
std::vector<uint8_t> m_payload{};
|
|
}; // NimBLEAdvertisementData
|
|
|
|
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV
|
|
#endif // NIMBLE_CPP_ADVERTISEMENT_DATA_H_
|