diff --git a/libraries/BLE/src/BLEAddress.cpp b/libraries/BLE/src/BLEAddress.cpp index 6d83b17e68e..9a31cf0146f 100644 --- a/libraries/BLE/src/BLEAddress.cpp +++ b/libraries/BLE/src/BLEAddress.cpp @@ -59,14 +59,37 @@ BLEAddress::BLEAddress(std::string stringAddress) { * @return True if the addresses are equal. */ bool BLEAddress::equals(BLEAddress otherAddress) { - return memcmp(otherAddress.getNative(), m_address, 6) == 0; + return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0; } // equals +bool BLEAddress::operator==(const BLEAddress& otherAddress) const { + return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0; +} + +bool BLEAddress::operator!=(const BLEAddress& otherAddress) const { + return !(*this == otherAddress); +} + +bool BLEAddress::operator<(const BLEAddress& otherAddress) const { + return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) < 0; +} + +bool BLEAddress::operator<=(const BLEAddress& otherAddress) const { + return !(*this > otherAddress); +} + +bool BLEAddress::operator>=(const BLEAddress& otherAddress) const { + return !(*this < otherAddress); +} + +bool BLEAddress::operator>(const BLEAddress& otherAddress) const { + return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) > 0; +} /** * @brief Return the native representation of the address. * @return The native representation of the address. - */ + */ esp_bd_addr_t *BLEAddress::getNative() { return &m_address; } // getNative diff --git a/libraries/BLE/src/BLEAddress.h b/libraries/BLE/src/BLEAddress.h index 7eff4da4bb6..864b09a3e03 100644 --- a/libraries/BLE/src/BLEAddress.h +++ b/libraries/BLE/src/BLEAddress.h @@ -23,6 +23,12 @@ class BLEAddress { BLEAddress(esp_bd_addr_t address); BLEAddress(std::string stringAddress); bool equals(BLEAddress otherAddress); + bool operator==(const BLEAddress& otherAddress) const; + bool operator!=(const BLEAddress& otherAddress) const; + bool operator<(const BLEAddress& otherAddress) const; + bool operator<=(const BLEAddress& otherAddress) const; + bool operator>(const BLEAddress& otherAddress) const; + bool operator>=(const BLEAddress& otherAddress) const; esp_bd_addr_t* getNative(); std::string toString();