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;
|
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 {
|
class NimBLEAdvertisementData {
|
||||||
// Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will
|
// Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will
|
||||||
// be exposed on demand/request or as time permits.
|
// be exposed on demand/request or as time permits.
|
||||||
//
|
//
|
||||||
public:
|
public:
|
||||||
void setAppearance(uint16_t appearance);
|
bool setAppearance(uint16_t appearance);
|
||||||
void setCompleteServices(const NimBLEUUID& uuid);
|
bool setCompleteServices(const NimBLEUUID& uuid);
|
||||||
void setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
bool setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
||||||
void setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
bool setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
||||||
void setFlags(uint8_t);
|
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||||
void setManufacturerData(const std::string& data);
|
bool addServiceUUID(const char* serviceUUID);
|
||||||
void setManufacturerData(const std::vector<uint8_t>& data);
|
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||||
void setURI(const std::string& uri);
|
bool removeServices();
|
||||||
void setName(const std::string& name, bool isComplete = true);
|
bool setFlags(uint8_t);
|
||||||
void setPartialServices(const NimBLEUUID& uuid);
|
bool setManufacturerData(const uint8_t* data, size_t length);
|
||||||
void setPartialServices16(const std::vector<NimBLEUUID>& uuids);
|
bool setManufacturerData(const std::string& data);
|
||||||
void setPartialServices32(const std::vector<NimBLEUUID>& uuids);
|
bool setManufacturerData(const std::vector<uint8_t>& data);
|
||||||
void setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
bool setURI(const std::string& uri);
|
||||||
void setShortName(const std::string& name);
|
bool setName(const std::string& name, bool isComplete = true);
|
||||||
void addData(const uint8_t* data, size_t length);
|
bool setPartialServices(const NimBLEUUID& uuid);
|
||||||
void addData(const std::vector<uint8_t>& data);
|
bool setPartialServices16(const std::vector<NimBLEUUID>& uuids);
|
||||||
void addTxPower();
|
bool setPartialServices32(const std::vector<NimBLEUUID>& uuids);
|
||||||
void setPreferredParams(uint16_t min, uint16_t max);
|
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();
|
void clearData();
|
||||||
|
|
||||||
|
int getDataLocation(uint8_t type) const;
|
||||||
std::vector<uint8_t> getPayload() const;
|
std::vector<uint8_t> getPayload() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class NimBLEAdvertising;
|
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
|
}; // 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 {
|
class NimBLEAdvertising {
|
||||||
public:
|
public:
|
||||||
NimBLEAdvertising();
|
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);
|
bool start(uint32_t duration = 0, const NimBLEAddress* dirAddr = nullptr);
|
||||||
void setAdvertisingCompleteCallback(advCompleteCB_t callback);
|
void setAdvertisingCompleteCallback(advCompleteCB_t callback);
|
||||||
void removeServices();
|
|
||||||
bool stop();
|
bool stop();
|
||||||
void setAppearance(uint16_t appearance);
|
bool setConnectableMode(uint8_t mode);
|
||||||
void setName(const std::string& name);
|
bool setDiscoverableMode(uint8_t mode);
|
||||||
void setManufacturerData(const uint8_t* data, size_t length);
|
bool reset();
|
||||||
void setManufacturerData(const std::string& data);
|
bool isAdvertising();
|
||||||
void setManufacturerData(const std::vector<uint8_t>& data);
|
bool setAdvertisementData(const NimBLEAdvertisementData& advertisementData);
|
||||||
void setURI(const std::string& uri);
|
bool setScanResponseData(const NimBLEAdvertisementData& advertisementData);
|
||||||
void setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length);
|
void setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly);
|
||||||
void setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
void setScanResponse(bool enable);
|
||||||
void setConnectableMode(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);
|
||||||
void setAdvertisementData(const NimBLEAdvertisementData& advertisementData);
|
|
||||||
void setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly);
|
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||||
void setScanResponseData(const NimBLEAdvertisementData& advertisementData);
|
bool addServiceUUID(const char* serviceUUID);
|
||||||
void setScanResponse(bool enable);
|
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||||
void setPreferredConnectionInterval(uint16_t minInterval, uint16_t maxInterval);
|
bool removeServices();
|
||||||
void setMinPreferred(uint16_t min);
|
bool setAppearance(uint16_t appearance);
|
||||||
void setMaxPreferred(uint16_t max);
|
bool setName(const std::string& name);
|
||||||
void addTxPower();
|
bool setManufacturerData(const uint8_t* data, size_t length);
|
||||||
bool reset();
|
bool setManufacturerData(const std::string& data);
|
||||||
bool isAdvertising();
|
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:
|
private:
|
||||||
friend class NimBLEDevice;
|
friend class NimBLEDevice;
|
||||||
|
@ -124,23 +132,14 @@ class NimBLEAdvertising {
|
||||||
void onHostSync();
|
void onHostSync();
|
||||||
static int handleGapEvent(ble_gap_event* event, void* arg);
|
static int handleGapEvent(ble_gap_event* event, void* arg);
|
||||||
|
|
||||||
ble_hs_adv_fields m_advData;
|
NimBLEAdvertisementData m_advData;
|
||||||
ble_hs_adv_fields m_scanData;
|
NimBLEAdvertisementData m_scanData;
|
||||||
ble_gap_adv_params m_advParams;
|
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;
|
advCompleteCB_t m_advCompCb;
|
||||||
uint8_t m_slaveItvl[4];
|
uint8_t m_slaveItvl[4];
|
||||||
uint32_t m_duration;
|
uint32_t m_duration;
|
||||||
std::vector<uint8_t> m_svcData16;
|
bool m_scanResp : 1;
|
||||||
std::vector<uint8_t> m_svcData32;
|
bool m_advDataSet : 1;
|
||||||
std::vector<uint8_t> m_svcData128;
|
|
||||||
std::vector<uint8_t> m_name;
|
|
||||||
std::vector<uint8_t> m_mfgData;
|
|
||||||
std::vector<uint8_t> m_uri;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV */
|
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV */
|
||||||
|
|
Loading…
Reference in a new issue