@@ -33,6 +33,7 @@ static const char* LOG_TAG = "NimBLEAddress";
3333 */
3434NimBLEAddress::NimBLEAddress (ble_addr_t address) {
3535 memcpy (m_address, address.val , 6 );
36+ m_addrType = address.type ;
3637} // NimBLEAddress
3738
3839
@@ -46,8 +47,11 @@ NimBLEAddress::NimBLEAddress(ble_addr_t address) {
4647 * which is 17 characters in length.
4748 *
4849 * @param [in] stringAddress The hex string representation of the address.
50+ * @param [in] type The type of the address.
4951 */
50- NimBLEAddress::NimBLEAddress (const std::string &stringAddress) {
52+ NimBLEAddress::NimBLEAddress (const std::string &stringAddress, uint8_t type) {
53+ m_addrType = type;
54+
5155 if (stringAddress.length () == 0 ) {
5256 memset (m_address, 0 , 6 );
5357 return ;
@@ -78,19 +82,23 @@ NimBLEAddress::NimBLEAddress(const std::string &stringAddress) {
7882/* *
7983 * @brief Constructor for compatibility with bluedroid esp library using native ESP representation.
8084 * @param [in] address A uint8_t[6] or esp_bd_addr_t containing the address.
85+ * @param [in] type The type of the address.
8186 */
82- NimBLEAddress::NimBLEAddress (uint8_t address[6 ]) {
87+ NimBLEAddress::NimBLEAddress (uint8_t address[6 ], uint8_t type ) {
8388 std::reverse_copy (address, address + sizeof m_address, m_address);
89+ m_addrType = type;
8490} // NimBLEAddress
8591
8692
8793/* *
8894 * @brief Constructor for address using a hex value.\n
8995 * Use the same byte order, so use 0xa4c1385def16 for "a4:c1:38:5d:ef:16"
9096 * @param [in] address uint64_t containing the address.
97+ * @param [in] type The type of the address.
9198 */
92- NimBLEAddress::NimBLEAddress (const uint64_t &address) {
99+ NimBLEAddress::NimBLEAddress (const uint64_t &address, uint8_t type ) {
93100 memcpy (m_address, &address, sizeof m_address);
101+ m_addrType = type;
94102} // NimBLEAddress
95103
96104
@@ -113,6 +121,15 @@ const uint8_t *NimBLEAddress::getNative() const {
113121} // getNative
114122
115123
124+ /* *
125+ * @brief Get the address type.
126+ * @return The address type.
127+ */
128+ uint8_t NimBLEAddress::getType () const {
129+ return m_addrType;
130+ } // getType
131+
132+
116133/* *
117134 * @brief Convert a BLE address to a string.
118135 *
@@ -152,8 +169,11 @@ bool NimBLEAddress::operator !=(const NimBLEAddress & rhs) const {
152169 * that accept std::string and/or or it's methods as a parameter.
153170 */
154171NimBLEAddress::operator std::string () const {
155- char buffer[18 ];
156- sprintf (buffer, " %02x:%02x:%02x:%02x:%02x:%02x" , m_address[5 ], m_address[4 ], m_address[3 ], m_address[2 ], m_address[1 ], m_address[0 ]);
172+ char buffer[26 ];
173+ snprintf (buffer, sizeof (buffer), " %02x:%02x:%02x:%02x:%02x:%02x type: %d" ,
174+ m_address[5 ], m_address[4 ], m_address[3 ],
175+ m_address[2 ], m_address[1 ], m_address[0 ],
176+ m_addrType);
157177 return std::string (buffer);
158178} // operator std::string
159179
0 commit comments