Skip to content

Commit 9a3e007

Browse files
committed
Fix BLEAddress NimBLE API
1 parent 18acb0e commit 9a3e007

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

libraries/BLE/src/BLEAddress.h

+15-5
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
class BLEAddress : private ble_addr_t {
4242
public:
4343
/**
44-
* @brief Create a blank address, i.e. 00:00:00:00:00:00, type 0.
45-
*/
44+
* @brief Create a blank address, i.e. 00:00:00:00:00:00, type 0.
45+
*/
4646
BLEAddress() = default;
4747
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);
48+
BLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type = BLE_ADDR_PUBLIC);
49+
BLEAddress(const std::string &stringAddress, uint8_t type = BLE_ADDR_PUBLIC);
50+
BLEAddress(const uint64_t &address, uint8_t type = BLE_ADDR_PUBLIC);
5151

5252
bool isRpa() const;
5353
bool isNrpa() const;
@@ -62,8 +62,18 @@ class BLEAddress : private ble_addr_t {
6262
const BLEAddress &reverseByteOrder();
6363
bool operator==(const BLEAddress &rhs) const;
6464
bool operator!=(const BLEAddress &rhs) const;
65+
bool operator<(const BLEAddress &rhs) const;
66+
bool operator<=(const BLEAddress &rhs) const;
67+
bool operator>(const BLEAddress &rhs) const;
68+
bool operator>=(const BLEAddress &rhs) const;
6569
operator std::string() const;
6670
operator uint64_t() const;
71+
72+
// Compatibility with old API
73+
[[deprecated("Use getBase() instead")]]
74+
const uint8_t *getNative() const {
75+
return &(getBase()->val);
76+
}
6777
};
6878

6979
#elif defined(CONFIG_BLUEDROID_ENABLED)

libraries/BLE/src/NimBLEAddress.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,30 @@ bool BLEAddress::operator!=(const BLEAddress &rhs) const {
214214
return !this->operator==(rhs);
215215
} // operator !=
216216

217+
bool BLEAddress::operator<(const BLEAddress &rhs) const {
218+
if (this->type != rhs.type) {
219+
return false;
220+
}
221+
222+
return memcmp(rhs.val, this->val, sizeof(this->val)) < 0;
223+
}
224+
225+
bool BLEAddress::operator<=(const BLEAddress &rhs) const {
226+
return !this->operator>(rhs);
227+
}
228+
229+
bool BLEAddress::operator>=(const BLEAddress &rhs) const {
230+
return !this->operator<(rhs);
231+
}
232+
233+
bool BLEAddress::operator>(const BLEAddress &rhs) const {
234+
if (this->type != rhs.type) {
235+
return false;
236+
}
237+
238+
return memcmp(rhs.val, this->val, sizeof(this->val)) > 0;
239+
}
240+
217241
/**
218242
* @brief Convenience operator to convert this address to string representation.
219243
* @details This allows passing BLEAddress to functions that accept std::string and/or it's methods as a parameter.

0 commit comments

Comments
 (0)