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

A representation of a BLE advertised device found by a scan. More...

#include <BLEAdvertisedDevice.hpp>

Public Member Functions

BLEAddress getAddress ()
 Get the address. More...
 
uint16_t getAppearance ()
 Get the appearance. More...
 
std::string getManufacturerData ()
 Get the manufacturer data. More...
 
std::string getName ()
 Get the name. More...
 
int16_t getRSSI ()
 Get the RSSI. More...
 
BLEScangetScan ()
 Get the scan object that created this advertisement. More...
 
std::string getServiceData ()
 Get the service data. More...
 
BLEUUID getServiceDataUUID ()
 Get the service data UUID. More...
 
BLEUUID getServiceUUID ()
 Get the Service UUID. More...
 
int8_t getTXPower ()
 Get the TX Power. More...
 
const uint8_t * getPayload ()
 Get the advertised payload. More...
 
size_t getPayloadLength ()
 Get the advertised payload length. More...
 
BLEAddress::Type_t getAddressType ()
 
void setAddressType (BLEAddress::Type_t type)
 
bool isAdvertisingService (BLEUUID uuid)
 Check advertised serviced for existence required UUID. More...
 
bool haveAppearance ()
 Does this advertisement have an appearance value? More...
 
bool haveManufacturerData ()
 Does this advertisement have manufacturer data? More...
 
bool haveName ()
 Does this advertisement have a name value? More...
 
bool haveRSSI ()
 Does this advertisement have a signal strength value? More...
 
bool haveServiceData ()
 Does this advertisement have a service data value? More...
 
bool haveServiceUUID ()
 Does this advertisement have a service UUID value? More...
 
bool haveTXPower ()
 Does this advertisement have a transmission power value? More...
 
std::string toString ()
 Create a string representation of this device. More...
 

Detailed Description

A representation of a BLE advertised device found by a scan.

When we perform a BLE scan, the result will be a set of devices that are advertising. This class provides a model of a detected device.

Member Function Documentation

◆ getAddress()

BLEAddress BLEAdvertisedDevice::getAddress ( )

Get the address.

Every BLE device exposes an address that is used to identify it and subsequently connect to it. Call this function to obtain the address of the advertised device.

Returns
The address of the advertised device.
66  {
67  return m_address;
68 } // getAddress

◆ getAppearance()

uint16_t BLEAdvertisedDevice::getAppearance ( )

Get the appearance.

A BLE device can declare its own appearance. The appearance is how it would like to be shown to an end user typcially in the form of an icon.

Returns
The appearance of the advertised device.
79  {
80  return m_appearance;
81 } // getAppearance

◆ getManufacturerData()

std::string BLEAdvertisedDevice::getManufacturerData ( )

Get the manufacturer data.

Returns
The manufacturer data of the advertised device.
88  {
89  return m_manufacturerData;
90 } // getManufacturerData

◆ getName()

std::string BLEAdvertisedDevice::getName ( )

Get the name.

Returns
The name of the advertised device.
97  {
98  return m_name;
99 } // getName

◆ getPayload()

const uint8_t * BLEAdvertisedDevice::getPayload ( )

Get the advertised payload.

The payload includes both a advertisement and a scan response.

Note
This is modified by CoXlab Inc.
533  {
534  return (const uint8_t *) m_payload.data();
535 }

◆ getPayloadLength()

size_t BLEAdvertisedDevice::getPayloadLength ( )

Get the advertised payload length.

The payload length will be equal or less than 62.

  • 31 (maximum length of an advertisement) + 31 (maximum length of a scan response)
Note
This is modified by CoXlab Inc.
553  {
554  return m_payload.size();
555 }

◆ getRSSI()

int16_t BLEAdvertisedDevice::getRSSI ( )

Get the RSSI.

Returns
The RSSI of the advertised device.
106  {
107  return m_rssi;
108 } // getRSSI

◆ getScan()

BLEScan * BLEAdvertisedDevice::getScan ( )

Get the scan object that created this advertisement.

Returns
The scan object.
115  {
116  return m_pScan;
117 } // getScan

◆ getServiceData()

std::string BLEAdvertisedDevice::getServiceData ( )

Get the service data.

Returns
The ServiceData of the advertised device.
124  {
125  return m_serviceData;
126 } //getServiceData

◆ getServiceDataUUID()

BLEUUID BLEAdvertisedDevice::getServiceDataUUID ( )

Get the service data UUID.

Returns
The service data UUID.
133  {
134  return m_serviceDataUUID;
135 } // getServiceDataUUID

◆ getServiceUUID()

BLEUUID BLEAdvertisedDevice::getServiceUUID ( )

Get the Service UUID.

Returns
The Service UUID of the advertised device.
142  { //TODO Remove it eventually, is no longer useful
143  return m_serviceUUIDs[0];
144 } // getServiceUUID

◆ getTXPower()

int8_t BLEAdvertisedDevice::getTXPower ( )

Get the TX Power.

Returns
The TX Power of the advertised device.
161  {
162  return m_txPower;
163 } // getTXPower

◆ haveAppearance()

bool BLEAdvertisedDevice::haveAppearance ( )

Does this advertisement have an appearance value?

Returns
True if there is an appearance value present.
171  {
172  return m_haveAppearance;
173 } // haveAppearance

◆ haveManufacturerData()

bool BLEAdvertisedDevice::haveManufacturerData ( )

Does this advertisement have manufacturer data?

Returns
True if there is manufacturer data present.
180  {
181  return (m_manufacturerData.length() > 0);
182 } // haveManufacturerData

◆ haveName()

bool BLEAdvertisedDevice::haveName ( )

Does this advertisement have a name value?

Returns
True if there is a name value present.
189  {
190  return (m_name.length() > 0);
191 } // haveName

◆ haveRSSI()

bool BLEAdvertisedDevice::haveRSSI ( )

Does this advertisement have a signal strength value?

Returns
True if there is a signal strength value present.
198  {
199  return (m_rssi > SHRT_MIN);
200 } // haveRSSI

◆ haveServiceData()

bool BLEAdvertisedDevice::haveServiceData ( )

Does this advertisement have a service data value?

Returns
True if there is a service data value present.
207  {
208  return m_haveServiceData;
209 } // haveServiceData

◆ haveServiceUUID()

bool BLEAdvertisedDevice::haveServiceUUID ( )

Does this advertisement have a service UUID value?

Returns
True if there is a service UUID value present.
216  {
217  return (m_serviceUUIDs.size() > 0);
218 } // haveServiceUUID

◆ haveTXPower()

bool BLEAdvertisedDevice::haveTXPower ( )

Does this advertisement have a transmission power value?

Returns
True if there is a transmission power value present.
225  {
226  return (m_txPower > CHAR_MIN);
227 } // haveTXPower

◆ isAdvertisingService()

bool BLEAdvertisedDevice::isAdvertisingService ( BLEUUID  uuid)

Check advertised serviced for existence required UUID.

Returns
Return true if service is advertised
150  {
151  for (unsigned i = 0; i < m_serviceUUIDs.size(); i++) {
152  if (m_serviceUUIDs[i].equals(uuid)) return true;
153  }
154  return false;
155 }

◆ toString()

std::string BLEAdvertisedDevice::toString ( )

Create a string representation of this device.

Returns
A string representation of this device.
500  {
501  std::stringstream ss;
502  ss << "{address: " << getAddress().toString();
503  if (haveName()) {
504  ss << ", name: " << m_name;
505  }
506  if (haveAppearance()) {
507  ss << ", appearance: " << getAppearance();
508  }
509  if (haveManufacturerData()) {
510  ss << ", manufacturer data:";
511  for (uint8_t i = 0; i < getManufacturerData().length(); i++) {
512  ss << ' ' << std::setfill('0') << std::setw(2) << std::hex << (int)((uint8_t *) getManufacturerData().data())[i];
513  }
514  ss << std::setw(0) << std::dec;
515  }
516  if (haveServiceUUID()) {
517  ss << ", serviceUUID: " << getServiceUUID().toString();
518  }
519  if (haveTXPower()) {
520  ss << ", txPower: " << (int)getTXPower();
521  }
522  ss << "}";
523  return ss.str();
524 } // toString

The documentation for this class was generated from the following files:
BLEUUID::toString
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:317
BLEAdvertisedDevice::haveAppearance
bool haveAppearance()
Does this advertisement have an appearance value?
Definition: BLEAdvertisedDevice.cpp:171
BLEAdvertisedDevice::getAddress
BLEAddress getAddress()
Get the address.
Definition: BLEAdvertisedDevice.cpp:66
BLEAdvertisedDevice::getAppearance
uint16_t getAppearance()
Get the appearance.
Definition: BLEAdvertisedDevice.cpp:79
BLEAdvertisedDevice::haveName
bool haveName()
Does this advertisement have a name value?
Definition: BLEAdvertisedDevice.cpp:189
BLEAdvertisedDevice::getTXPower
int8_t getTXPower()
Get the TX Power.
Definition: BLEAdvertisedDevice.cpp:161
BLEAdvertisedDevice::haveTXPower
bool haveTXPower()
Does this advertisement have a transmission power value?
Definition: BLEAdvertisedDevice.cpp:225
BLEAddress::toString
std::string toString()
Convert a BLE address to a string.
Definition: BLEAddress.cpp:96
BLEAdvertisedDevice::getManufacturerData
std::string getManufacturerData()
Get the manufacturer data.
Definition: BLEAdvertisedDevice.cpp:88
BLEAdvertisedDevice::haveManufacturerData
bool haveManufacturerData()
Does this advertisement have manufacturer data?
Definition: BLEAdvertisedDevice.cpp:180
BLEAdvertisedDevice::getServiceUUID
BLEUUID getServiceUUID()
Get the Service UUID.
Definition: BLEAdvertisedDevice.cpp:142
BLEAdvertisedDevice::haveServiceUUID
bool haveServiceUUID()
Does this advertisement have a service UUID value?
Definition: BLEAdvertisedDevice.cpp:216