Mbed OS Reference
Loading...
Searching...
No Matches
AdvertisingDataSimpleBuilder< DataSize > Class Template Reference

Build advertising data. More...

#include <AdvertisingDataSimpleBuilder.h>

Public Member Functions

 AdvertisingDataSimpleBuilder ()
 Construct a AdvertisingDataSimpleBuilder. More...
 
AdvertisingDataSimpleBuildersetAppearance (adv_data_appearance_t appearance)
 Add device appearance in the advertising payload. More...
 
AdvertisingDataSimpleBuildersetFlags (adv_data_flags_t flags=adv_data_flags_t::default_flags)
 Add BLE flags in the advertising payload. More...
 
AdvertisingDataSimpleBuildersetTxPowerAdvertised (advertising_power_t txPower)
 Add the advertising TX in the advertising payload. More...
 
AdvertisingDataSimpleBuildersetName (const char *name, bool complete=true)
 Add device name to the advertising payload. More...
 
AdvertisingDataSimpleBuildersetManufacturerSpecificData (mbed::Span< const uint8_t > data)
 Add manufacturer specific data to the advertising payload. More...
 
AdvertisingDataSimpleBuildersetAdvertisingInterval (adv_interval_t interval)
 Add advertising interval to the payload. More...
 
AdvertisingDataSimpleBuildersetConnectionIntervalPreference (conn_interval_t min, conn_interval_t max)
 Add connection interval preferences to the payload. More...
 
AdvertisingDataSimpleBuildersetServiceData (const UUID &service, mbed::Span< const uint8_t > data)
 Add service data to the advertising payload. More...
 
AdvertisingDataSimpleBuildersetLocalService (const UUID &data, bool complete=true)
 Add local service ID to the advertising payload. More...
 
AdvertisingDataSimpleBuildersetLocalServiceList (mbed::Span< const UUID > data, bool complete=true)
 Add local service IDs to the advertising payload. More...
 
AdvertisingDataSimpleBuildersetRequestedService (const UUID &data)
 Add a UUID of a solicited service. More...
 
AdvertisingDataSimpleBuildersetRequestedServiceList (mbed::Span< const UUID > data)
 Add a list of UUIDs of solicited services. More...
 
AdvertisingDataSimpleBuilderaddData (adv_data_type_t advDataType, mbed::Span< const uint8_t > fieldData)
 Add a new field into the payload. More...
 
mbed::Span< const uint8_t > getAdvertisingData () const
 Get the subspan of the buffer containing valid data. More...
 

Detailed Description

template<size_t DataSize>
class ble::AdvertisingDataSimpleBuilder< DataSize >

Build advertising data.

It is a simplified version of AdvertisingDataBuilder that can generate advertising data "inline".

It differs from AdvertisingDataBuilder on the following points:

  • The buffer used to build the advertising data is embedded in the object.
  • If insertion fails, an assertion is raised. Outside of debug mode, if an insertion fails, the buffer is not modified.
  • The API is fluent.
  • It hides advanced functions.
void setupAdvertisingData(ble::Gap& gap)
{
using namespace ble;
LEGACY_ADVERTISING_HANDLE,
.setName("My device", true)
.setLocalService(ATT_UUID_HEART_RATE_SERVICE)
);
}
AdvertisingDataSimpleBuilder & setAppearance(adv_data_appearance_t appearance)
Add device appearance in the advertising payload.
AdvertisingDataSimpleBuilder & setFlags(adv_data_flags_t flags=adv_data_flags_t::default_flags)
Add BLE flags in the advertising payload.
AdvertisingDataSimpleBuilder & setName(const char *name, bool complete=true)
Add device name to the advertising payload.
mbed::Span< const uint8_t > getAdvertisingData() const
Get the subspan of the buffer containing valid data.
AdvertisingDataSimpleBuilder & setLocalService(const UUID &data, bool complete=true)
Add local service ID to the advertising payload.
Define device discovery, connection and link management procedures.
Definition: Gap.h:282
ble_error_t setAdvertisingPayload(advertising_handle_t handle, mbed::Span< const uint8_t > payload)
Set new advertising payload for a given advertising set.
Entry namespace for all BLE API definitions.
@ GENERIC_HEART_RATE_SENSOR
Generic Heart Rate Sensor.

Definition at line 66 of file AdvertisingDataSimpleBuilder.h.

Constructor & Destructor Documentation

◆ AdvertisingDataSimpleBuilder()

Member Function Documentation

◆ setAppearance()

AdvertisingDataSimpleBuilder & setAppearance ( adv_data_appearance_t  appearance)

Add device appearance in the advertising payload.

Parameters
[in]appearanceThe appearance to advertise.
Returns
A reference to this object.
Note
If the field is already present in the payload, it is replaced.

Definition at line 84 of file AdvertisingDataSimpleBuilder.h.

◆ setFlags()

AdvertisingDataSimpleBuilder & setFlags ( adv_data_flags_t  flags = adv_data_flags_t::default_flags)

Add BLE flags in the advertising payload.

Parameters
[in]flagsBitfield describing the capability of the device. See allowed flags in Flags_t.
Returns
A reference to this object.
Note
If the field is already present in the payload, it is replaced.

Definition at line 101 of file AdvertisingDataSimpleBuilder.h.

◆ setTxPowerAdvertised()

AdvertisingDataSimpleBuilder & setTxPowerAdvertised ( advertising_power_t  txPower)

Add the advertising TX in the advertising payload.

Parameters
[in]txPowerTransmission power level in dB.
Returns
A reference to this object.
Note
If the field is already present in the payload, it is replaced.

Definition at line 119 of file AdvertisingDataSimpleBuilder.h.

◆ setName()

AdvertisingDataSimpleBuilder & setName ( const char *  name,
bool  complete = true 
)

Add device name to the advertising payload.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]nameNull terminated string containing the name.
[in]completeComplete local name if true, otherwise
Returns
A reference to this object.
Note
If the field is already present in the payload, it is replaced.

Definition at line 138 of file AdvertisingDataSimpleBuilder.h.

◆ setManufacturerSpecificData()

AdvertisingDataSimpleBuilder & setManufacturerSpecificData ( mbed::Span< const uint8_t >  data)

Add manufacturer specific data to the advertising payload.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]dataNew data to be added.
Returns
a reference to this object.

Definition at line 154 of file AdvertisingDataSimpleBuilder.h.

◆ setAdvertisingInterval()

AdvertisingDataSimpleBuilder & setAdvertisingInterval ( adv_interval_t  interval)

Add advertising interval to the payload.

This field can only carry 2 bytes.

Parameters
intervalInterval to advertise. Cannot be larger than 0xFFFF.
Returns
a reference to this object.

Definition at line 168 of file AdvertisingDataSimpleBuilder.h.

◆ setConnectionIntervalPreference()

AdvertisingDataSimpleBuilder & setConnectionIntervalPreference ( conn_interval_t  min,
conn_interval_t  max 
)

Add connection interval preferences to the payload.

Parameters
minMinimum connection interval to advertise.
maxMaximum connection interval to advertise.
Returns
a reference to this object.

Definition at line 183 of file AdvertisingDataSimpleBuilder.h.

◆ setServiceData()

AdvertisingDataSimpleBuilder & setServiceData ( const UUID service,
mbed::Span< const uint8_t >  data 
)

Add service data to the advertising payload.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]serviceUUID of the service.
[in]dataNew data to be added.
Returns
A reference to this object.

Definition at line 203 of file AdvertisingDataSimpleBuilder.h.

◆ setLocalService()

AdvertisingDataSimpleBuilder & setLocalService ( const UUID data,
bool  complete = true 
)

Add local service ID to the advertising payload.

If the data can't fit, no modification will take place.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]dataNew data to be added.
[in]completeTrue if this is a complete list.
Returns
A reference to this object.

Definition at line 221 of file AdvertisingDataSimpleBuilder.h.

◆ setLocalServiceList()

AdvertisingDataSimpleBuilder & setLocalServiceList ( mbed::Span< const UUID data,
bool  complete = true 
)

Add local service IDs to the advertising payload.

If the data can't fit, no modification will take place.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]dataNew data to be added.
[in]completeTrue if this is a complete list.
Returns
A reference to this object.

Definition at line 245 of file AdvertisingDataSimpleBuilder.h.

◆ setRequestedService()

AdvertisingDataSimpleBuilder & setRequestedService ( const UUID data)

Add a UUID of a solicited service.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]dataList of 128 or 16 bit service UUIDs.
Returns
A reference to this object.

Definition at line 264 of file AdvertisingDataSimpleBuilder.h.

◆ setRequestedServiceList()

AdvertisingDataSimpleBuilder & setRequestedServiceList ( mbed::Span< const UUID data)

Add a list of UUIDs of solicited services.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]dataList of 128 or 16 bit service UUIDs.
Returns
A reference to this object.

Definition at line 280 of file AdvertisingDataSimpleBuilder.h.

◆ addData()

AdvertisingDataSimpleBuilder & addData ( adv_data_type_t  advDataType,
mbed::Span< const uint8_t >  fieldData 
)

Add a new field into the payload.

The operation fails if type is already present.

Note
Data size for individual types cannot exceed 255 bytes.
Parameters
[in]advDataTypeThe type of the field to add.
[in]fieldDataSpan of data to add.
Returns
A reference to this object.

Definition at line 297 of file AdvertisingDataSimpleBuilder.h.

◆ getAdvertisingData()

mbed::Span< const uint8_t > getAdvertisingData ( ) const

Get the subspan of the buffer containing valid data.

Returns
A Span containing the payload.

Definition at line 312 of file AdvertisingDataSimpleBuilder.h.