7
7
#include " sdkconfig.h"
8
8
#if defined(CONFIG_BT_ENABLED)
9
9
10
- #include " BLEAddress.h"
11
- #include < string>
12
- #include < sstream>
13
- #include < iomanip>
14
- #include < string.h>
15
10
#include < stdio.h>
11
+ #include < string.h>
12
+
13
+ #include < iomanip>
14
+ #include < sstream>
15
+ #include < string>
16
+
17
+ #include " BLEAddress.h"
16
18
#ifdef ARDUINO_ARCH_ESP32
17
19
#include " esp32-hal-log.h"
18
20
#endif
19
21
20
-
21
22
/* *
22
23
* @brief Create an address from the native ESP32 representation.
23
24
* @param [in] address The native representation.
24
25
*/
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
29
30
30
31
/* *
31
32
* @brief Create an address from a hex string
@@ -38,38 +39,32 @@ BLEAddress::BLEAddress(esp_bd_addr_t address) {
38
39
*
39
40
* @param [in] stringAddress The hex representation of the address.
40
41
*/
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 ;
53
45
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
54
55
55
56
/* *
56
57
* @brief Determine if this address equals another.
57
58
* @param [in] otherAddress The other address to compare against.
58
59
* @return True if the addresses are equal.
59
60
*/
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
64
62
65
63
/* *
66
64
* @brief Return the native representation of the address.
67
65
* @return The native representation of the address.
68
66
*/
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
73
68
74
69
/* *
75
70
* @brief Convert a BLE address to a string.
@@ -83,13 +78,15 @@ esp_bd_addr_t *BLEAddress::getNative() {
83
78
* @return The string representation of the address.
84
79
*/
85
80
std::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; }
95
92
#endif
0 commit comments