mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
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:
parent
08fc2878e7
commit
32e1022e67
4 changed files with 13 additions and 2 deletions
|
@ -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());
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
/**************************/
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
/**
|
||||
* @brief A %BLE device address.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue