Skip to content

Commit 18acb0e

Browse files
committed
Merge header files
1 parent 8704947 commit 18acb0e

28 files changed

+2133
-101
lines changed

libraries/BLE/src/BLE2901.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
#include "BLEDescriptor.h"
2828

29-
[[deprecated("This class is deprecated and will be removed in a future release. Use BLEDescriptor instead.")]]
30-
class BLE2901 : public BLEDescriptor {
29+
class [[deprecated("Use BLEDescriptor instead.")]] BLE2901 : public BLEDescriptor {
3130
public:
3231
BLE2901();
3332
void setDescription(String desc);

libraries/BLE/src/BLE2904.h

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
/*
2-
* BLE2904.h
2+
* Copyright 2020-2024 Ryan Powell <[email protected]> and
3+
* esp-nimble-cpp, NimBLE-Arduino contributors.
34
*
4-
* Created on: Dec 23, 2017
5-
* Author: kolban
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.
616
*/
717

818
#ifndef COMPONENTS_CPP_UTILS_BLE2904_H_
@@ -11,17 +21,16 @@
1121
#if SOC_BLE_SUPPORTED
1222

1323
#include "sdkconfig.h"
14-
#if defined(CONFIG_BLUEDROID_ENABLED)
24+
#if defined(CONFIG_BLUEDROID_ENABLED) || (defined(CONFIG_NIMBLE_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL))
1525

1626
#include "BLEDescriptor.h"
1727

1828
struct BLE2904_Data {
19-
uint8_t m_format;
20-
int8_t m_exponent;
21-
uint16_t m_unit; // See https://www.bluetooth.com/specifications/assigned-numbers/units
22-
uint8_t m_namespace;
23-
uint16_t m_description;
24-
29+
uint8_t m_format{0};
30+
int8_t m_exponent{0};
31+
uint16_t m_unit{0x2700}; // Unitless; See https://www.bluetooth.com/specifications/assigned-numbers/units
32+
uint8_t m_namespace{1}; // 1 = Bluetooth SIG Assigned Numbers
33+
uint16_t m_description{0}; // unknown description
2534
} __attribute__((packed));
2635

2736
/**
@@ -34,7 +43,11 @@ struct BLE2904_Data {
3443
*/
3544
class BLE2904 : public BLEDescriptor {
3645
public:
46+
#if defined(CONFIG_BLUEDROID_ENABLED)
3747
BLE2904();
48+
#else
49+
BLE2904(BLECharacteristic *pChr = nullptr);
50+
#endif
3851
static const uint8_t FORMAT_BOOLEAN = 1;
3952
static const uint8_t FORMAT_UINT2 = 2;
4053
static const uint8_t FORMAT_UINT4 = 3;
@@ -62,6 +75,7 @@ class BLE2904 : public BLEDescriptor {
6275
static const uint8_t FORMAT_UTF8 = 25;
6376
static const uint8_t FORMAT_UTF16 = 26;
6477
static const uint8_t FORMAT_OPAQUE = 27;
78+
static const uint8_t FORMAT_MEDASN1 = 28;
6579

6680
void setDescription(uint16_t);
6781
void setExponent(int8_t exponent);
@@ -70,9 +84,10 @@ class BLE2904 : public BLEDescriptor {
7084
void setUnit(uint16_t unit);
7185

7286
private:
73-
BLE2904_Data m_data;
87+
friend class BLECharacteristic;
88+
BLE2904_Data m_data{};
7489
}; // BLE2904
7590

76-
#endif /* CONFIG_BLUEDROID_ENABLED */
91+
#endif /* CONFIG_BLUEDROID_ENABLED || (CONFIG_NIMBLE_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) */
7792
#endif /* SOC_BLE_SUPPORTED */
7893
#endif /* COMPONENTS_CPP_UTILS_BLE2904_H_ */

libraries/BLE/src/BLEAddress.h

+67-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
/*
2-
* BLEAddress.h
2+
* Copyright 2020-2024 Ryan Powell <[email protected]> and
3+
* esp-nimble-cpp, NimBLE-Arduino contributors.
34
*
4-
* Created on: Jul 2, 2017
5-
* Author: kolban
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.
616
*/
717

818
#ifndef COMPONENTS_CPP_UTILS_BLEADDRESS_H_
@@ -12,7 +22,59 @@
1222
#if SOC_BLE_SUPPORTED
1323

1424
#include "sdkconfig.h"
15-
#if defined(CONFIG_BLUEDROID_ENABLED)
25+
#if defined(CONFIG_NIMBLE_ENABLED)
26+
27+
#include "nimble/ble.h"
28+
29+
/**** FIX COMPILATION ****/
30+
#undef min
31+
#undef max
32+
/**************************/
33+
34+
#include <string>
35+
36+
/**
37+
* @brief A BLE device address.
38+
*
39+
* Every BLE device has a unique address which can be used to identify it and form connections.
40+
*/
41+
class BLEAddress : private ble_addr_t {
42+
public:
43+
/**
44+
* @brief Create a blank address, i.e. 00:00:00:00:00:00, type 0.
45+
*/
46+
BLEAddress() = default;
47+
BLEAddress(const ble_addr_t address);
48+
BLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type);
49+
BLEAddress(const std::string &stringAddress, uint8_t type);
50+
BLEAddress(const uint64_t &address, uint8_t type);
51+
52+
bool isRpa() const;
53+
bool isNrpa() const;
54+
bool isStatic() const;
55+
bool isPublic() const;
56+
bool isNull() const;
57+
bool equals(const BLEAddress &otherAddress) const;
58+
const ble_addr_t *getBase() const;
59+
std::string toString() const;
60+
uint8_t getType() const;
61+
const uint8_t *getVal() const;
62+
const BLEAddress &reverseByteOrder();
63+
bool operator==(const BLEAddress &rhs) const;
64+
bool operator!=(const BLEAddress &rhs) const;
65+
operator std::string() const;
66+
operator uint64_t() const;
67+
};
68+
69+
#elif defined(CONFIG_BLUEDROID_ENABLED)
70+
71+
/*
72+
* BLEAddress.h
73+
*
74+
* Created on: Jul 2, 2017
75+
* Author: kolban
76+
*/
77+
1678
#include <esp_gap_ble_api.h> // ESP32 BLE
1779
#include <string>
1880

@@ -40,5 +102,6 @@ class BLEAddress {
40102
};
41103

42104
#endif /* CONFIG_BLUEDROID_ENABLED */
105+
43106
#endif /* SOC_BLE_SUPPORTED */
44107
#endif /* COMPONENTS_CPP_UTILS_BLEADDRESS_H_ */

libraries/BLE/src/BLEAdvertisedDevice.h

+175-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
/*
2-
* BLEAdvertisedDevice.h
2+
* Copyright 2020-2024 Ryan Powell <[email protected]> and
3+
* esp-nimble-cpp, NimBLE-Arduino contributors.
34
*
4-
* Created on: Jul 3, 2017
5-
* Author: kolban
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.
616
*/
717

818
#ifndef COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_
@@ -11,7 +21,167 @@
1121
#if SOC_BLE_SUPPORTED
1222

1323
#include "sdkconfig.h"
14-
#if defined(CONFIG_BLUEDROID_ENABLED)
24+
#if defined(CONFIG_NIMBLE_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_OBSERVER)
25+
26+
#include "BLEAddress.h"
27+
#include "BLEScan.h"
28+
#include "BLEUUID.h"
29+
30+
#include "host/ble_hs_adv.h"
31+
#include "host/ble_gap.h"
32+
33+
#include <vector>
34+
35+
class BLEScan;
36+
/**
37+
* @brief A representation of a %BLE advertised device found by a scan.
38+
*
39+
* When we perform a %BLE scan, the result will be a set of devices that are advertising. This
40+
* class provides a model of a detected device.
41+
*/
42+
class BLEAdvertisedDevice {
43+
public:
44+
BLEAdvertisedDevice() = default;
45+
46+
uint8_t getAdvType() const;
47+
uint8_t getAdvFlags() const;
48+
uint16_t getAppearance() const;
49+
uint16_t getAdvInterval() const;
50+
uint16_t getMinInterval() const;
51+
uint16_t getMaxInterval() const;
52+
uint8_t getManufacturerDataCount() const;
53+
const BLEAddress &getAddress() const;
54+
std::string getManufacturerData(uint8_t index = 0) const;
55+
std::string getURI() const;
56+
std::string getPayloadByType(uint16_t type, uint8_t index = 0) const;
57+
std::string getName() const;
58+
int8_t getRSSI() const;
59+
BLEScan *getScan() const;
60+
uint8_t getServiceDataCount() const;
61+
std::string getServiceData(uint8_t index = 0) const;
62+
std::string getServiceData(const BLEUUID &uuid) const;
63+
BLEUUID getServiceDataUUID(uint8_t index = 0) const;
64+
BLEUUID getServiceUUID(uint8_t index = 0) const;
65+
uint8_t getServiceUUIDCount() const;
66+
BLEAddress getTargetAddress(uint8_t index = 0) const;
67+
uint8_t getTargetAddressCount() const;
68+
int8_t getTXPower() const;
69+
uint8_t getAdvLength() const;
70+
uint8_t getAddressType() const;
71+
bool isAdvertisingService(const BLEUUID &uuid) const;
72+
bool haveAppearance() const;
73+
bool haveManufacturerData() const;
74+
bool haveName() const;
75+
bool haveServiceData() const;
76+
bool haveServiceUUID() const;
77+
bool haveTXPower() const;
78+
bool haveConnParams() const;
79+
bool haveAdvInterval() const;
80+
bool haveTargetAddress() const;
81+
bool haveURI() const;
82+
bool haveType(uint16_t type) const;
83+
std::string toString() const;
84+
bool isConnectable() const;
85+
bool isScannable() const;
86+
bool isLegacyAdvertisement() const;
87+
#if CONFIG_BT_NIMBLE_EXT_ADV
88+
uint8_t getSetId() const;
89+
uint8_t getPrimaryPhy() const;
90+
uint8_t getSecondaryPhy() const;
91+
uint16_t getPeriodicInterval() const;
92+
#endif
93+
94+
const std::vector<uint8_t> &getPayload() const;
95+
const std::vector<uint8_t>::const_iterator begin() const;
96+
const std::vector<uint8_t>::const_iterator end() const;
97+
98+
/**
99+
* @brief A template to convert the service data to <type\>.
100+
* @tparam T The type to convert the data to.
101+
* @param [in] skipSizeCheck If true it will skip checking if the data size is less than <tt>sizeof(<type\>)</tt>.
102+
* @return The data converted to <type\> or NULL if skipSizeCheck is false and the data is
103+
* less than <tt>sizeof(<type\>)</tt>.
104+
* @details <b>Use:</b> <tt>getManufacturerData<type>(skipSizeCheck);</tt>
105+
*/
106+
template<typename T> T getManufacturerData(bool skipSizeCheck = false) const {
107+
std::string data = getManufacturerData();
108+
if (!skipSizeCheck && data.size() < sizeof(T)) {
109+
return T();
110+
}
111+
const char *pData = data.data();
112+
return *((T *)pData);
113+
}
114+
115+
/**
116+
* @brief A template to convert the service data to <tt><type\></tt>.
117+
* @tparam T The type to convert the data to.
118+
* @param [in] index The vector index of the service data requested.
119+
* @param [in] skipSizeCheck If true it will skip checking if the data size is less than <tt>sizeof(<type\>)</tt>.
120+
* @return The data converted to <type\> or NULL if skipSizeCheck is false and the data is
121+
* less than <tt>sizeof(<type\>)</tt>.
122+
* @details <b>Use:</b> <tt>getServiceData<type>(skipSizeCheck);</tt>
123+
*/
124+
template<typename T> T getServiceData(uint8_t index = 0, bool skipSizeCheck = false) const {
125+
std::string data = getServiceData(index);
126+
if (!skipSizeCheck && data.size() < sizeof(T)) {
127+
return T();
128+
}
129+
const char *pData = data.data();
130+
return *((T *)pData);
131+
}
132+
133+
/**
134+
* @brief A template to convert the service data to <tt><type\></tt>.
135+
* @tparam T The type to convert the data to.
136+
* @param [in] uuid The uuid of the service data requested.
137+
* @param [in] skipSizeCheck If true it will skip checking if the data size is less than <tt>sizeof(<type\>)</tt>.
138+
* @return The data converted to <type\> or NULL if skipSizeCheck is false and the data is
139+
* less than <tt>sizeof(<type\>)</tt>.
140+
* @details <b>Use:</b> <tt>getServiceData<type>(skipSizeCheck);</tt>
141+
*/
142+
template<typename T> T getServiceData(const BLEUUID &uuid, bool skipSizeCheck = false) const {
143+
std::string data = getServiceData(uuid);
144+
if (!skipSizeCheck && data.size() < sizeof(T)) {
145+
return T();
146+
}
147+
const char *pData = data.data();
148+
return *((T *)pData);
149+
}
150+
151+
private:
152+
friend class BLEScan;
153+
154+
BLEAdvertisedDevice(const ble_gap_event *event, uint8_t eventType);
155+
void update(const ble_gap_event *event, uint8_t eventType);
156+
uint8_t findAdvField(uint8_t type, uint8_t index = 0, size_t *data_loc = nullptr) const;
157+
size_t findServiceData(uint8_t index, uint8_t *bytes) const;
158+
159+
BLEAddress m_address{};
160+
uint8_t m_advType{};
161+
int8_t m_rssi{};
162+
uint8_t m_callbackSent{};
163+
uint8_t m_advLength{};
164+
165+
#if CONFIG_BT_NIMBLE_EXT_ADV
166+
bool m_isLegacyAdv{};
167+
uint8_t m_sid{};
168+
uint8_t m_primPhy{};
169+
uint8_t m_secPhy{};
170+
uint16_t m_periodicItvl{};
171+
#endif
172+
173+
std::vector<uint8_t> m_payload;
174+
};
175+
176+
#elif defined(CONFIG_BLUEDROID_ENABLED)
177+
178+
/*
179+
* BLEAdvertisedDevice.h
180+
*
181+
* Created on: Jul 3, 2017
182+
* Author: kolban
183+
*/
184+
15185
#include <esp_gattc_api.h>
16186

17187
#include <map>
@@ -148,5 +318,6 @@ class BLEExtAdvertisingCallbacks {
148318
#endif // SOC_BLE_50_SUPPORTED
149319

150320
#endif /* CONFIG_BLUEDROID_ENABLED */
321+
151322
#endif /* SOC_BLE_SUPPORTED */
152323
#endif /* COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_ */

libraries/BLE/src/BLEAdvertisementData.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ class BLEAdvertisementData {
7474
std::vector<uint8_t> m_payload{};
7575
}; // BLEAdvertisementData
7676

77-
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV
77+
#endif // CONFIG_NIMBLE_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV
7878
#endif // NIMBLE_CPP_ADVERTISEMENT_DATA_H_

0 commit comments

Comments
 (0)