esp-nimble-cpp 2.0.2
Loading...
Searching...
No Matches
NimBLEAdvertisementData.h
1/*
2 * Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_ADVERTISEMENT_DATA_H_
19#define NIMBLE_CPP_ADVERTISEMENT_DATA_H_
20
21#include "nimconfig.h"
22#if (defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) && !CONFIG_BT_NIMBLE_EXT_ADV) || \
23 defined(_DOXYGEN_)
24
25# include <cstdint>
26# include <string>
27# include <vector>
28
29class NimBLEUUID;
34 // Only a subset of the possible BLE architected advertisement fields are currently exposed. Others will
35 // be exposed on demand/request or as time permits.
36 //
37 public:
38 bool addData(const uint8_t* data, size_t length);
39 bool addData(const std::vector<uint8_t>& data);
40 bool setAppearance(uint16_t appearance);
41 bool setFlags(uint8_t);
42 bool addTxPower();
43 bool setPreferredParams(uint16_t minInterval, uint16_t maxInterval);
44 bool addServiceUUID(const NimBLEUUID& serviceUUID);
45 bool addServiceUUID(const char* serviceUUID);
46 bool removeServiceUUID(const NimBLEUUID& serviceUUID);
47 bool removeServiceUUID(const char* serviceUUID);
48 bool removeServices();
49 bool setManufacturerData(const uint8_t* data, size_t length);
50 bool setManufacturerData(const std::string& data);
51 bool setManufacturerData(const std::vector<uint8_t>& data);
52 bool setURI(const std::string& uri);
53 bool setName(const std::string& name, bool isComplete = true);
54 bool setShortName(const std::string& name);
55 bool setCompleteServices(const NimBLEUUID& uuid);
56 bool setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
57 bool setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
58 bool setPartialServices(const NimBLEUUID& uuid);
59 bool setPartialServices16(const std::vector<NimBLEUUID>& uuids);
60 bool setPartialServices32(const std::vector<NimBLEUUID>& uuids);
61 bool setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length);
62 bool setServiceData(const NimBLEUUID& uuid, const std::string& data);
63 bool setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data);
64 bool removeData(uint8_t type);
65 void clearData();
66 int getDataLocation(uint8_t type) const;
67
68 std::string toString() const;
69 std::vector<uint8_t> getPayload() const;
70
71 private:
72 friend class NimBLEAdvertising;
73
74 bool setServices(bool complete, uint8_t size, const std::vector<NimBLEUUID>& v_uuid);
75 std::vector<uint8_t> m_payload{};
76}; // NimBLEAdvertisementData
77
78#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV
79#endif // NIMBLE_CPP_ADVERTISEMENT_DATA_H_
Advertisement data set by the programmer to be published by the BLE server.
Definition NimBLEAdvertisementData.h:33
bool setFlags(uint8_t)
Set the advertisement flags.
Definition NimBLEAdvertisementData.cpp:86
bool setServiceData(const NimBLEUUID &uuid, const uint8_t *data, size_t length)
Set the service data advertised for the UUID.
Definition NimBLEAdvertisementData.cpp:458
bool setPartialServices(const NimBLEUUID &uuid)
Set a single service to advertise as a partial list of services.
Definition NimBLEAdvertisementData.cpp:381
bool setManufacturerData(const uint8_t *data, size_t length)
Set manufacturer specific data.
Definition NimBLEAdvertisementData.cpp:268
std::vector< uint8_t > getPayload() const
Retrieve the payload that is to be advertised.
Definition NimBLEAdvertisementData.cpp:554
bool setShortName(const std::string &name)
Set the short name.
Definition NimBLEAdvertisementData.cpp:345
bool addTxPower()
Adds Tx power level to the advertisement data.
Definition NimBLEAdvertisementData.cpp:108
int getDataLocation(uint8_t type) const
Get the location of the data in the payload.
Definition NimBLEAdvertisementData.cpp:521
bool setAppearance(uint16_t appearance)
Set the appearance.
Definition NimBLEAdvertisementData.cpp:65
bool addData(const uint8_t *data, size_t length)
Add data to the payload to be advertised.
Definition NimBLEAdvertisementData.cpp:41
std::string toString() const
Get the string representation of the advertisement data.
Definition NimBLEAdvertisementData.cpp:569
bool setPartialServices32(const std::vector< NimBLEUUID > &uuids)
Set the partial list of services to advertise.
Definition NimBLEAdvertisementData.cpp:399
bool setURI(const std::string &uri)
Set the URI to advertise.
Definition NimBLEAdvertisementData.cpp:304
bool setCompleteServices16(const std::vector< NimBLEUUID > &uuids)
Set the complete list of 16 bit services to advertise.
Definition NimBLEAdvertisementData.cpp:363
bool setPartialServices16(const std::vector< NimBLEUUID > &uuids)
Set the partial list of services to advertise.
Definition NimBLEAdvertisementData.cpp:390
bool setCompleteServices(const NimBLEUUID &uuid)
Set a single service to advertise as a complete list of services.
Definition NimBLEAdvertisementData.cpp:354
void clearData()
Clear the advertisement data for reuse.
Definition NimBLEAdvertisementData.cpp:561
bool addServiceUUID(const NimBLEUUID &serviceUUID)
Add a service uuid to exposed list of services.
Definition NimBLEAdvertisementData.cpp:148
bool setPreferredParams(uint16_t minInterval, uint16_t maxInterval)
Set the preferred min and max connection intervals to advertise.
Definition NimBLEAdvertisementData.cpp:127
bool removeData(uint8_t type)
Remove data from the advertisement data.
Definition NimBLEAdvertisementData.cpp:537
bool removeServiceUUID(const NimBLEUUID &serviceUUID)
Remove a service UUID from the advertisement.
Definition NimBLEAdvertisementData.cpp:203
bool setName(const std::string &name, bool isComplete=true)
Set the complete name of this device.
Definition NimBLEAdvertisementData.cpp:326
bool setCompleteServices32(const std::vector< NimBLEUUID > &uuids)
Set the complete list of 32 bit services to advertise.
Definition NimBLEAdvertisementData.cpp:372
bool removeServices()
Remove all service UUIDs from the advertisement.
Definition NimBLEAdvertisementData.cpp:258
Perform and manage BLE advertising.
Definition NimBLEAdvertising.h:52
A model of a BLE UUID.
Definition NimBLEUUID.h:41