diff --git a/src/NimBLEAddress.cpp b/src/NimBLEAddress.cpp index 6aa919a..b6bc952 100644 --- a/src/NimBLEAddress.cpp +++ b/src/NimBLEAddress.cpp @@ -48,6 +48,16 @@ NimBLEAddress::NimBLEAddress(ble_addr_t address) { * @param [in] stringAddress The hex representation of the address. */ NimBLEAddress::NimBLEAddress(const std::string &stringAddress) { + if (stringAddress.length() == 0) { + memset(m_address, 0, 6); + return; + } + + if (stringAddress.length() == 6) { + std::reverse_copy(stringAddress.data(), stringAddress.data() + 6, m_address); + return; + } + if (stringAddress.length() != 17) { memset(m_address, 0, sizeof m_address); // "00:00:00:00:00:00" represents an invalid address NIMBLE_LOGD(LOG_TAG, "Invalid address '%s'", stringAddress.c_str()); diff --git a/src/NimBLEAddress.h b/src/NimBLEAddress.h index 917e376..e81a2bd 100644 --- a/src/NimBLEAddress.h +++ b/src/NimBLEAddress.h @@ -24,6 +24,7 @@ /**************************/ #include +#include /** * @brief A %BLE device address. diff --git a/src/NimBLEAdvertisedDevice.h b/src/NimBLEAdvertisedDevice.h index df8c876..7a4115f 100644 --- a/src/NimBLEAdvertisedDevice.h +++ b/src/NimBLEAdvertisedDevice.h @@ -95,7 +95,7 @@ private: bool m_haveTXPower; - NimBLEAddress m_address = NimBLEAddress("\0\0\0\0\0\0"); + NimBLEAddress m_address = NimBLEAddress(""); uint8_t m_advType; uint16_t m_appearance; int m_deviceType; diff --git a/src/NimBLEClient.h b/src/NimBLEClient.h index 97a7ab8..e2cea9e 100644 --- a/src/NimBLEClient.h +++ b/src/NimBLEClient.h @@ -73,7 +73,7 @@ private: bool retrieveServices(); //Retrieve services from the server // void onHostReset(); - NimBLEAddress m_peerAddress = NimBLEAddress("\0\0\0\0\0\0"); // The BD address of the remote server. + NimBLEAddress m_peerAddress = NimBLEAddress(""); // The BD address of the remote server. uint16_t m_conn_id; bool m_haveServices = false; // Have we previously obtain the set of services from the remote server. bool m_isConnected = false; // Are we currently connected.