Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ble::Advertisement Class Reference

Object helper to define an advertisement. More...

#include <Advertisement.hxx>

Inheritance diagram for ble::Advertisement:
openlcb::BLEAdvertisement

Public Types

enum  Field { DATA , SCAN_DATA }
 Data fields that make up an advertisement. More...
 
enum class  Flags : uint8_t {
  LE_LIMITED_DISC_MODE = 0x01 , LE_GENERAL_DISC_MODE = 0x02 , BR_EDR_NOT_SUPPORTED = 0x04 , LE_BR_EDR_CONTROLLER = 0x08 ,
  LE_BR_EDR_HOST = 0x10 , LE_ONLY_LIMITED_DISC_MODE = 0x05 , LE_ONLY_GENERAL_DISC_MODE = 0x06
}
 Flag values. More...
 

Public Member Functions

 Advertisement (bool extended=false)
 Constructor.
 
 Advertisement (size_t data_reserve, size_t scan_data_reserve)
 Constructor which reserves data and scan data space.
 
 Advertisement (size_t data_reserve, size_t dummy, bool extended)
 Constructor which reserves data space.
 
std::basic_string< uint8_t > concat_service_data_128 (const uint8_t uuid[16], const void *buf, size_t size)
 Concatenate a 128-bit (16-byte) UUID with provided data.
 
std::basic_string< uint8_t > concat_service_data_128 (const uint8_t uuid[16], std::basic_string< uint8_t > &buf)
 Concatenate a 128-bit (16-byte) UUID with provided data.
 
int prepend (Field field, Defs::AdvType type, const void *buf, size_t size, bool clip=false)
 Add to the beginning of the advertisement.
 
int prepend (Field field, Defs::AdvType type, std::basic_string< uint8_t > &buf, bool clip=false)
 Add to the beginning of the advertisement.
 
int prepend_name (Field field, std::string &name)
 Add name to the beginning of the advertisement.
 
int append (Field field, Defs::AdvType type, const void *buf, size_t size, bool clip=false)
 Add to the end of the advertisement.
 
int append (Field field, Defs::AdvType type, std::basic_string< uint8_t > &buf, bool clip=false)
 Add to the end of the advertisement.
 
int append_name (Field field, std::string &name)
 Add name to the end of the advertisement.
 
int update (Field field, Defs::AdvType type, const void *buf, size_t size, unsigned instance=1, bool exact_size=true, bool clip=false)
 Update existing advertisement.
 
int update (Field field, Defs::AdvType type, std::basic_string< uint8_t > &buf, unsigned instance=1, bool exact_size=true, bool clip=false)
 Update existing advertisement.
 
bool is_extended ()
 Test if extended advertisement or not.
 
uint8_t * get_data ()
 Get the advertisement data.
 
size_t get_data_size ()
 Get the advertisement data size in bytes.
 
uint8_t * get_scan_data ()
 Get the advertisement data.
 
size_t get_scan_data_size ()
 Get the advertisement data size in bytes.
 

Static Public Attributes

static constexpr size_t MAX_DATA_PAYLOAD_SIZE = 31
 Maximum payload size of data.
 
static constexpr size_t MAX_SCAN_DATA_PAYLOAD_SIZE = 31
 Maximum payload size of scan data.
 
static constexpr size_t MAX_EXT_DATA_PAYLOAD_SIZE = 254
 Maximum payload size of extended data.
 

Private Attributes

std::basic_string< uint8_t > data_
 advertising data, also used for extended advertising
 
std::basic_string< uint8_t > scanData_
 
bool extended_
 true extended advertisement, else false
 

Detailed Description

Object helper to define an advertisement.

Definition at line 38 of file Advertisement.hxx.

Member Enumeration Documentation

◆ Field

Data fields that make up an advertisement.

Enumerator
DATA 

main data

SCAN_DATA 

scan data

Definition at line 51 of file Advertisement.hxx.

◆ Flags

enum class ble::Advertisement::Flags : uint8_t
strong

Flag values.

Enumerator
LE_LIMITED_DISC_MODE 

BLE limited discovery mode.

LE_GENERAL_DISC_MODE 

BLE general discovery mode.

BR_EDR_NOT_SUPPORTED 

BR/EDR (classic) not supported.

LE_BR_EDR_CONTROLLER 

BLE + BR/EDR controller.

LE_BR_EDR_HOST 

BLE + BR/EDR Host.

LE_ONLY_LIMITED_DISC_MODE 

BLE only limited discovery mode.

LE_ONLY_GENERAL_DISC_MODE 

BEE only general discovery mode.

Definition at line 58 of file Advertisement.hxx.

Constructor & Destructor Documentation

◆ Advertisement() [1/3]

ble::Advertisement::Advertisement ( bool  extended = false)
inline

Constructor.

Parameters
extendedtrue if an extended advertisement, else false

Definition at line 71 of file Advertisement.hxx.

◆ Advertisement() [2/3]

ble::Advertisement::Advertisement ( size_t  data_reserve,
size_t  scan_data_reserve 
)
inline

Constructor which reserves data and scan data space.

This cannot be and extended advertisement because it is assumed to have scan data.

Parameters
data_reservesize in bytes to reserve for the data
scan_data_reservesize in bytes to reserve for the scan data

Definition at line 80 of file Advertisement.hxx.

◆ Advertisement() [3/3]

ble::Advertisement::Advertisement ( size_t  data_reserve,
size_t  dummy,
bool  extended 
)
inline

Constructor which reserves data space.

Parameters
data_reservesize in bytes to reserve for the data
dummynot used, present to remove ambiguity
extendedtrue if an extended advertisement, else false

Definition at line 99 of file Advertisement.hxx.

Member Function Documentation

◆ append() [1/2]

int ble::Advertisement::append ( Field  field,
Defs::AdvType  type,
const void *  buf,
size_t  size,
bool  clip = false 
)

Add to the end of the advertisement.

Parameters
fieldfield to place the data into
typetype of data to add
bufdata to add
sizesize of data in bytes
clipif the data does not all fit, clip the end of it off
Returns
number of bytes added, else -1 upon error

Definition at line 85 of file Advertisement.cxx.

◆ append() [2/2]

int ble::Advertisement::append ( Field  field,
Defs::AdvType  type,
std::basic_string< uint8_t > &  buf,
bool  clip = false 
)
inline

Add to the end of the advertisement.

Parameters
fieldfield to place the data into
typetype of data to add
bufdata to add
clipif the data does not all fit, clip the end of it off
Returns
number of bytes added, else -1 upon error

Definition at line 184 of file Advertisement.hxx.

◆ append_name()

int ble::Advertisement::append_name ( Field  field,
std::string &  name 
)
inline

Add name to the end of the advertisement.

Will use type NAME_COMPLETE if it fits. Will use NAME_SHORT if it does not fit.

Parameters
fieldfield to place the data into
namename to add
Returns
number of bytes added, else -1 upon error

Definition at line 195 of file Advertisement.hxx.

◆ concat_service_data_128() [1/2]

std::basic_string< uint8_t > ble::Advertisement::concat_service_data_128 ( const uint8_t  uuid[16],
const void *  buf,
size_t  size 
)

Concatenate a 128-bit (16-byte) UUID with provided data.

Parameters
uuid128-bit UUID
datadata to concatenate
sizesize of data in bytes to concatenate
Returns
resulting string

Definition at line 36 of file Advertisement.cxx.

◆ concat_service_data_128() [2/2]

std::basic_string< uint8_t > ble::Advertisement::concat_service_data_128 ( const uint8_t  uuid[16],
std::basic_string< uint8_t > &  buf 
)
inline

Concatenate a 128-bit (16-byte) UUID with provided data.

Parameters
uuid128-bit UUID
datadata to concatenate
Returns
resulting string

Definition at line 123 of file Advertisement.hxx.

◆ get_data()

uint8_t * ble::Advertisement::get_data ( )
inline

Get the advertisement data.

Returns
pointer to the advertisement data

Definition at line 246 of file Advertisement.hxx.

◆ get_data_size()

size_t ble::Advertisement::get_data_size ( )
inline

Get the advertisement data size in bytes.

Returns
size in bytes

Definition at line 253 of file Advertisement.hxx.

◆ get_scan_data()

uint8_t * ble::Advertisement::get_scan_data ( )
inline

Get the advertisement data.

Returns
pointer to the advertisement data

Definition at line 260 of file Advertisement.hxx.

◆ get_scan_data_size()

size_t ble::Advertisement::get_scan_data_size ( )
inline

Get the advertisement data size in bytes.

Returns
size in bytes

Definition at line 268 of file Advertisement.hxx.

◆ is_extended()

bool ble::Advertisement::is_extended ( )
inline

Test if extended advertisement or not.

Returns
true if extended advertisement, else false

Definition at line 239 of file Advertisement.hxx.

◆ prepend() [1/2]

int ble::Advertisement::prepend ( Field  field,
Defs::AdvType  type,
const void *  buf,
size_t  size,
bool  clip = false 
)

Add to the beginning of the advertisement.

Parameters
ffield to place the advertisement into
typetype of data to add
bufdata to add
sizesize of data in bytes
clipif the data does not all fit, clip the end of it off
Returns
number of bytes added, else -1 upon error

Definition at line 48 of file Advertisement.cxx.

◆ prepend() [2/2]

int ble::Advertisement::prepend ( Field  field,
Defs::AdvType  type,
std::basic_string< uint8_t > &  buf,
bool  clip = false 
)
inline

Add to the beginning of the advertisement.

Parameters
fieldfield to place the data into
typetype of data to add
bufdata to add
clipif the data does not all fit, clip the end of it off
Returns
number of bytes added, else -1 upon error

Definition at line 145 of file Advertisement.hxx.

◆ prepend_name()

int ble::Advertisement::prepend_name ( Field  field,
std::string &  name 
)
inline

Add name to the beginning of the advertisement.

Will use type NAME_COMPLETE if it fits. Will use NAME_SHORT if it does not fit.

Parameters
fieldfield to place the data into
namename to add
Returns
number of bytes added, else -1 upon error

Definition at line 156 of file Advertisement.hxx.

◆ update() [1/2]

int ble::Advertisement::update ( Field  field,
Defs::AdvType  type,
const void *  buf,
size_t  size,
unsigned  instance = 1,
bool  exact_size = true,
bool  clip = false 
)

Update existing advertisement.

Parameters
fieldfield to place the data into
typetype of data to update
bufdata to update
sizesize of data in bytes
instancethe instance occurance to update
exact_sizethe new data size must match the old data size
clipif the data does not all fit, clip the end of it off
Returns
number of bytes updated, else -1 upon error

Definition at line 122 of file Advertisement.cxx.

◆ update() [2/2]

int ble::Advertisement::update ( Field  field,
Defs::AdvType  type,
std::basic_string< uint8_t > &  buf,
unsigned  instance = 1,
bool  exact_size = true,
bool  clip = false 
)
inline

Update existing advertisement.

Parameters
fieldfield to place the data into
typetype of data to update
bufdata to update
sizesize of data in bytes
instancethe instance occurance to update
exact_sizethe new data size must match the old data size
clipif the data does not all fit, clip the end of it off
Returns
number of bytes updated, else -1 upon error

Definition at line 229 of file Advertisement.hxx.

Member Data Documentation

◆ data_

std::basic_string<uint8_t> ble::Advertisement::data_
private

advertising data, also used for extended advertising

advertising scan data

Definition at line 287 of file Advertisement.hxx.

◆ extended_

bool ble::Advertisement::extended_
private

true extended advertisement, else false

Definition at line 292 of file Advertisement.hxx.

◆ MAX_DATA_PAYLOAD_SIZE

constexpr size_t ble::Advertisement::MAX_DATA_PAYLOAD_SIZE = 31
staticconstexpr

Maximum payload size of data.

Definition at line 42 of file Advertisement.hxx.

◆ MAX_EXT_DATA_PAYLOAD_SIZE

constexpr size_t ble::Advertisement::MAX_EXT_DATA_PAYLOAD_SIZE = 254
staticconstexpr

Maximum payload size of extended data.

Definition at line 48 of file Advertisement.hxx.

◆ MAX_SCAN_DATA_PAYLOAD_SIZE

constexpr size_t ble::Advertisement::MAX_SCAN_DATA_PAYLOAD_SIZE = 31
staticconstexpr

Maximum payload size of scan data.

Definition at line 45 of file Advertisement.hxx.

◆ scanData_

std::basic_string<uint8_t> ble::Advertisement::scanData_
private

Definition at line 290 of file Advertisement.hxx.


The documentation for this class was generated from the following files: