Correct error in creation of NimBLEAddress from six bytes in a std::string

* Add creation of a NimBLEAddress from a std::string of 6 exactly bytes.

* Add creation of a NimBLEAddress from an empty string.
This commit is contained in:
h2zero
2020-05-18 10:11:54 -06:00
parent 08fc2878e7
commit 32e1022e67
4 changed files with 13 additions and 2 deletions

View File

@@ -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());