SDK  23.9.2
For IoT System Software Development
Public Types | Public Member Functions | List of all members
BLEAddress Class Reference

A BLE device address. More...

#include <BLEAddress.hpp>

Public Types

enum  Type_t {
  TYPE_PUBLIC = 0x00, TYPE_RANDOM = 0x01, TYPE_RPA_PUBLIC = 0x02, TYPE_RPA_RANDOM = 0x03,
  TYPE_UNKNOWN = 0xFF
}
 

Public Member Functions

 BLEAddress (const uint8_t *address)
 Create an address from the native ESP32 representation. More...
 
 BLEAddress (std::string stringAddress)
 Create an address from a hex string. More...
 
bool equals (BLEAddress otherAddress)
 Determine if this address equals another. More...
 
const uint8_t * getNative ()
 Return the native representation of the address. More...
 
std::string toString ()
 Convert a BLE address to a string. More...
 

Detailed Description

A BLE device address.

Every BLE device has a unique address which can be used to identify it and form connections.

Constructor & Destructor Documentation

◆ BLEAddress() [1/2]

BLEAddress::BLEAddress ( const uint8_t *  address)

Create an address from the native ESP32 representation.

Parameters
[in]addressThe native representation.
36  {
37  memcpy(m_address, address, 6);
38 } // BLEAddress

◆ BLEAddress() [2/2]

BLEAddress::BLEAddress ( std::string  stringAddress)

Create an address from a hex string.

A hex string is of the format:

00:00:00:00:00:00

which is 17 characters in length.

Parameters
[in]stringAddressThe hex representation of the address.
52  {
53  if (stringAddress.length() != 17) return;
54 
55  int data[6];
56  sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
57  m_address[0] = (uint8_t) data[0];
58  m_address[1] = (uint8_t) data[1];
59  m_address[2] = (uint8_t) data[2];
60  m_address[3] = (uint8_t) data[3];
61  m_address[4] = (uint8_t) data[4];
62  m_address[5] = (uint8_t) data[5];
63 } // BLEAddress

Member Function Documentation

◆ equals()

bool BLEAddress::equals ( BLEAddress  otherAddress)

Determine if this address equals another.

Parameters
[in]otherAddressThe other address to compare against.
Returns
True if the addresses are equal.
71  {
72  return memcmp(otherAddress.getNative(), m_address, 6) == 0;
73 } // equals

◆ getNative()

const uint8_t * BLEAddress::getNative ( )

Return the native representation of the address.

Returns
The native representation of the address.
80  {
81  return m_address;
82 } // getNative

◆ toString()

std::string BLEAddress::toString ( )

Convert a BLE address to a string.

A string representation of an address is in the format:

xx:xx:xx:xx:xx:xx
Returns
The string representation of the address.
96  {
97  std::stringstream stream;
98  stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[0] << ':';
99  stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[1] << ':';
100  stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[2] << ':';
101  stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[3] << ':';
102  stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[4] << ':';
103  stream << std::setfill('0') << std::setw(2) << std::hex << (int) ((uint8_t*) (m_address))[5];
104  return stream.str();
105 } // toString

The documentation for this class was generated from the following files:
BLEAddress::getNative
const uint8_t * getNative()
Return the native representation of the address.
Definition: BLEAddress.cpp:80