77#include " sdkconfig.h"
88#if defined(CONFIG_BT_ENABLED)
99
10- #include " BLEAddress.h"
11- #include < string>
12- #include < sstream>
13- #include < iomanip>
14- #include < string.h>
1510#include < stdio.h>
11+ #include < string.h>
12+
13+ #include < iomanip>
14+ #include < sstream>
15+ #include < string>
16+
17+ #include " BLEAddress.h"
1618#ifdef ARDUINO_ARCH_ESP32
1719#include " esp32-hal-log.h"
1820#endif
1921
20-
2122/* *
2223 * @brief Create an address from the native ESP32 representation.
2324 * @param [in] address The native representation.
2425 */
25- BLEAddress::BLEAddress (esp_bd_addr_t address) {
26- memcpy (m_address, address, ESP_BD_ADDR_LEN) ;
27- } // BLEAddress
28-
26+ BLEAddress::BLEAddress (esp_bd_addr_t address, esp_ble_wl_addr_type_t type ) {
27+ m_type = type ;
28+ memcpy (m_address, address, ESP_BD_ADDR_LEN);
29+ } // BLEAddress
2930
3031/* *
3132 * @brief Create an address from a hex string
@@ -38,38 +39,32 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
3839 *
3940 * @param [in] stringAddress The hex representation of the address.
4041 */
41- BLEAddress::BLEAddress (std::string stringAddress) {
42- if (stringAddress.length () != 17 ) return ;
43-
44- int data[6 ];
45- sscanf (stringAddress.c_str (), " %x:%x:%x:%x:%x:%x" , &data[0 ], &data[1 ], &data[2 ], &data[3 ], &data[4 ], &data[5 ]);
46- m_address[0 ] = (uint8_t ) data[0 ];
47- m_address[1 ] = (uint8_t ) data[1 ];
48- m_address[2 ] = (uint8_t ) data[2 ];
49- m_address[3 ] = (uint8_t ) data[3 ];
50- m_address[4 ] = (uint8_t ) data[4 ];
51- m_address[5 ] = (uint8_t ) data[5 ];
52- } // BLEAddress
42+ BLEAddress::BLEAddress (std::string stringAddress, esp_ble_wl_addr_type_t type) {
43+ m_type = type;
44+ if (stringAddress.length () != 17 ) return ;
5345
46+ int data[6 ];
47+ sscanf (stringAddress.c_str (), " %x:%x:%x:%x:%x:%x" , &data[0 ], &data[1 ], &data[2 ], &data[3 ], &data[4 ], &data[5 ]);
48+ m_address[0 ] = (uint8_t )data[0 ];
49+ m_address[1 ] = (uint8_t )data[1 ];
50+ m_address[2 ] = (uint8_t )data[2 ];
51+ m_address[3 ] = (uint8_t )data[3 ];
52+ m_address[4 ] = (uint8_t )data[4 ];
53+ m_address[5 ] = (uint8_t )data[5 ];
54+ } // BLEAddress
5455
5556/* *
5657 * @brief Determine if this address equals another.
5758 * @param [in] otherAddress The other address to compare against.
5859 * @return True if the addresses are equal.
5960 */
60- bool BLEAddress::equals (BLEAddress otherAddress) {
61- return memcmp (otherAddress.getNative (), m_address, 6 ) == 0 ;
62- } // equals
63-
61+ bool BLEAddress::equals (BLEAddress otherAddress) { return memcmp (otherAddress.getNative (), m_address, 6 ) == 0 && m_type == otherAddress.m_type ; } // equals
6462
6563/* *
6664 * @brief Return the native representation of the address.
6765 * @return The native representation of the address.
6866 */
69- esp_bd_addr_t *BLEAddress::getNative () {
70- return &m_address;
71- } // getNative
72-
67+ esp_bd_addr_t *BLEAddress::getNative () { return &m_address; } // getNative
7368
7469/* *
7570 * @brief Convert a BLE address to a string.
@@ -83,13 +78,15 @@ esp_bd_addr_t *BLEAddress::getNative() {
8378 * @return The string representation of the address.
8479 */
8580std::string BLEAddress::toString () {
86- std::stringstream stream;
87- stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int ) ((uint8_t *) (m_address))[0 ] << ' :' ;
88- stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int ) ((uint8_t *) (m_address))[1 ] << ' :' ;
89- stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int ) ((uint8_t *) (m_address))[2 ] << ' :' ;
90- stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int ) ((uint8_t *) (m_address))[3 ] << ' :' ;
91- stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int ) ((uint8_t *) (m_address))[4 ] << ' :' ;
92- stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int ) ((uint8_t *) (m_address))[5 ];
93- return stream.str ();
94- } // toString
81+ std::stringstream stream;
82+ stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int )((uint8_t *)(m_address))[0 ] << ' :' ;
83+ stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int )((uint8_t *)(m_address))[1 ] << ' :' ;
84+ stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int )((uint8_t *)(m_address))[2 ] << ' :' ;
85+ stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int )((uint8_t *)(m_address))[3 ] << ' :' ;
86+ stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int )((uint8_t *)(m_address))[4 ] << ' :' ;
87+ stream << std::setfill (' 0' ) << std::setw (2 ) << std::hex << (int )((uint8_t *)(m_address))[5 ];
88+ return stream.str ();
89+ } // toString
90+
91+ esp_ble_wl_addr_type_t BLEAddress::getType () const { return m_type; }
9592#endif
0 commit comments