mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-24 06:00:55 +01:00
* 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::setPreferredConnectionInterval` renamed to `NimBLEAdvertising::setPreferredParams` * `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.
This commit is contained in:
parent
34fb6b8b87
commit
d51da48ca8
2 changed files with 517 additions and 458 deletions
File diff suppressed because it is too large
Load diff
|
@ -42,80 +42,88 @@ class NimBLEAdvertising;
|
|||
typedef std::function<void(NimBLEAdvertising*)> advCompleteCB_t;
|
||||
|
||||
/**
|
||||
* @brief Advertisement data set by the programmer to be published by the %BLE server.
|
||||
* @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:
|
||||
void setAppearance(uint16_t appearance);
|
||||
void setCompleteServices(const NimBLEUUID& uuid);
|
||||
void setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
void setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
void setFlags(uint8_t);
|
||||
void setManufacturerData(const std::string& data);
|
||||
void setManufacturerData(const std::vector<uint8_t>& data);
|
||||
void setURI(const std::string& uri);
|
||||
void setName(const std::string& name, bool isComplete = true);
|
||||
void setPartialServices(const NimBLEUUID& uuid);
|
||||
void setPartialServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
void setPartialServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
void setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
||||
void setShortName(const std::string& name);
|
||||
void addData(const uint8_t* data, size_t length);
|
||||
void addData(const std::vector<uint8_t>& data);
|
||||
void addTxPower();
|
||||
void setPreferredParams(uint16_t min, uint16_t max);
|
||||
bool setAppearance(uint16_t appearance);
|
||||
bool setCompleteServices(const NimBLEUUID& uuid);
|
||||
bool setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool addServiceUUID(const char* serviceUUID);
|
||||
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool removeServices();
|
||||
bool setFlags(uint8_t);
|
||||
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 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 setShortName(const std::string& name);
|
||||
bool addTxPower();
|
||||
bool setPreferredParams(uint16_t minInterval, uint16_t maxInterval);
|
||||
bool addData(const uint8_t* data, size_t length);
|
||||
bool addData(const std::vector<uint8_t>& data);
|
||||
void clearData();
|
||||
|
||||
int getDataLocation(uint8_t type) const;
|
||||
std::vector<uint8_t> getPayload() const;
|
||||
|
||||
private:
|
||||
friend class NimBLEAdvertising;
|
||||
void setServices(bool complete, uint8_t size, const std::vector<NimBLEUUID>& v_uuid);
|
||||
std::vector<uint8_t> m_payload; // The payload of the advertisement.
|
||||
|
||||
bool setServices(bool complete, uint8_t size, const std::vector<NimBLEUUID>& v_uuid);
|
||||
std::vector<uint8_t> m_payload{};
|
||||
}; // NimBLEAdvertisementData
|
||||
|
||||
/**
|
||||
* @brief Perform and manage %BLE advertising.
|
||||
* @brief Perform and manage BLE advertising.
|
||||
*
|
||||
* A %BLE server will want to perform advertising in order to make itself known to %BLE clients.
|
||||
* A BLE server will want to perform advertising in order to make itself known to BLE clients.
|
||||
*/
|
||||
class NimBLEAdvertising {
|
||||
public:
|
||||
NimBLEAdvertising();
|
||||
void addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
void addServiceUUID(const char* serviceUUID);
|
||||
void removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool start(uint32_t duration = 0, const NimBLEAddress* dirAddr = nullptr);
|
||||
void setAdvertisingCompleteCallback(advCompleteCB_t callback);
|
||||
void removeServices();
|
||||
bool stop();
|
||||
void setAppearance(uint16_t appearance);
|
||||
void setName(const std::string& name);
|
||||
void setManufacturerData(const uint8_t* data, size_t length);
|
||||
void setManufacturerData(const std::string& data);
|
||||
void setManufacturerData(const std::vector<uint8_t>& data);
|
||||
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 setConnectableMode(uint8_t mode);
|
||||
void setDiscoverableMode(uint8_t mode);
|
||||
void setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data);
|
||||
bool setConnectableMode(uint8_t mode);
|
||||
bool setDiscoverableMode(uint8_t mode);
|
||||
bool reset();
|
||||
bool isAdvertising();
|
||||
bool setAdvertisementData(const NimBLEAdvertisementData& advertisementData);
|
||||
bool setScanResponseData(const NimBLEAdvertisementData& advertisementData);
|
||||
void setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly);
|
||||
void setScanResponse(bool enable);
|
||||
void setAdvertisingInterval(uint16_t interval);
|
||||
void setMaxInterval(uint16_t maxInterval);
|
||||
void setMinInterval(uint16_t minInterval);
|
||||
void setAdvertisementData(const NimBLEAdvertisementData& advertisementData);
|
||||
void setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly);
|
||||
void setScanResponseData(const NimBLEAdvertisementData& advertisementData);
|
||||
void setScanResponse(bool enable);
|
||||
void setPreferredConnectionInterval(uint16_t minInterval, uint16_t maxInterval);
|
||||
void setMinPreferred(uint16_t min);
|
||||
void setMaxPreferred(uint16_t max);
|
||||
void addTxPower();
|
||||
bool reset();
|
||||
bool isAdvertising();
|
||||
|
||||
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool addServiceUUID(const char* serviceUUID);
|
||||
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool removeServices();
|
||||
bool setAppearance(uint16_t appearance);
|
||||
bool setName(const std::string& name);
|
||||
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 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 setPreferredParams(uint16_t minInterval, uint16_t maxInterval);
|
||||
bool addTxPower();
|
||||
|
||||
private:
|
||||
friend class NimBLEDevice;
|
||||
|
@ -124,23 +132,14 @@ class NimBLEAdvertising {
|
|||
void onHostSync();
|
||||
static int handleGapEvent(ble_gap_event* event, void* arg);
|
||||
|
||||
ble_hs_adv_fields m_advData;
|
||||
ble_hs_adv_fields m_scanData;
|
||||
NimBLEAdvertisementData m_advData;
|
||||
NimBLEAdvertisementData m_scanData;
|
||||
ble_gap_adv_params m_advParams;
|
||||
std::vector<NimBLEUUID> m_serviceUUIDs;
|
||||
bool m_customAdvData;
|
||||
bool m_customScanResponseData;
|
||||
bool m_scanResp;
|
||||
bool m_advDataSet;
|
||||
advCompleteCB_t m_advCompCb;
|
||||
uint8_t m_slaveItvl[4];
|
||||
uint32_t m_duration;
|
||||
std::vector<uint8_t> m_svcData16;
|
||||
std::vector<uint8_t> m_svcData32;
|
||||
std::vector<uint8_t> m_svcData128;
|
||||
std::vector<uint8_t> m_name;
|
||||
std::vector<uint8_t> m_mfgData;
|
||||
std::vector<uint8_t> m_uri;
|
||||
bool m_scanResp : 1;
|
||||
bool m_advDataSet : 1;
|
||||
};
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV */
|
||||
|
|
Loading…
Reference in a new issue