Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
Advertiser Class Reference

#include <cs_Advertiser.h>

Inheritance diagram for Advertiser:
Collaboration diagram for Advertiser:

Public Member Functions

 Advertiser (Advertiser const &)=delete
 
void operator= (Advertiser const &)=delete
 
void init ()
 Initialize the advertiser. More...
 
void setDeviceName (const std::string &deviceName)
 Set the name of this Crownstone. More...
 
void setAdvertisingInterval (uint16_t advertisingInterval)
 Set the advertising interval in 0.625 ms units. More...
 
void setTxPower (int8_t power)
 Set the radio transmit power. More...
 
void setLowTxPower ()
 Sets TX power to low TX power as stored in State. More...
 
void setNormalTxPower ()
 Sets TX power to normal TX power as stored in State. More...
 
void setConnectable (bool connectable)
 Set whether to advertise being connectable. More...
 
void configureAdvertisement (IBeacon &beacon, bool asScanResponse=false)
 Configure the advertisement to hold iBeacon data. More...
 
void configureAdvertisement (ServiceData &serviceData, bool asScanResponse=false)
 Configure the advertisement to hold Crownstone service data. More...
 
void startAdvertising ()
 Start advertising. More...
 
void stopAdvertising ()
 Stop advertising. More...
 
void handleEvent (event_t &event)
 Internal usage. More...
 

Static Public Member Functions

static AdvertisergetInstance ()
 Get the static singleton instance. More...
 

Private Member Functions

 Advertiser ()
 
void configureAdvertisementParameters ()
 Set advertisement parameters from member variables. More...
 
void setAdvertisementData (ServiceData &serviceData, bool asScanResponse)
 Sets the advertisement data. More...
 
void setAdvertisementData (IBeacon &beacon, bool asScanResponse)
 Sets the advertisement data. More...
 
void updateAdvertisementData ()
 Sets and updates advertisement data. More...
 
void updateAdvertisementParams ()
 Updates the advertisement parameters. More...
 
void updateTxPower ()
 Set the cached TX power at the softdevice. More...
 
void restartAdvertising ()
 Stop and start advertising. More...
 
void setConnectableAdvParams ()
 Sets advertisement parameters to be connectable. More...
 
void setNonConnectableAdvParams ()
 Sets advertisement parameters to be non-connectable. More...
 
bool allocateAdvertisementDataBuffers (bool scanResponse)
 Allocate the advertisement data buffers. More...
 
uint8_t * getAdvertisementBuffer (bool scanResponse)
 Gets an advertisement data buffer that's not in use. More...
 
void markAdvertisementBuffer (const uint8_t *buffer, bool inUse, bool scanResponse)
 Mark an advertisement buffer as in use / no longer in use. More...
 
void onConnect (const ble_connected_t &connectedData)
 
void onDisconnect ()
 
void onConnectOutgoing ()
 
void onTick ()
 
void printAdvertisement ()
 
- Private Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 

Private Attributes

Stack_stack = nullptr
 
bool _isInitialized = false
 
bool _advertising = false
 
bool _wantAdvertising = false
 
bool _startOnNextTick = false
 
uint8_t _advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET
 
int8_t _txPower = 0
 
uint16_t _advertisingInterval = g_ADVERTISEMENT_INTERVAL
 
ble_gap_adv_params_t _advParams
 
bool _advParamsChanged = false
 
bool _isConnectable = false
 
bool _wantConnectable = true
 
ble_advdata_manuf_data_t _ibeaconManufData
 
ble_advdata_service_data_t _crownstoneServiceData
 
ServiceData_serviceData = nullptr
 
std::string _deviceName = "none"
 
ble_advdata_t _configAdvertisementData
 Advertisement data config, filled by one or more advertisement data fields. More...
 
ble_advdata_t _configScanResponse
 Scan response data config, filled by one or more advertisement data fields. More...
 
bool _includeAdvertisementData = false
 Whether the advertisement data config has been filled. More...
 
bool _includeScanResponseData = false
 Whether the scan response data config has been filled. More...
 
uint8_t * _advertisementDataBuffers [2 *_advertisementDataBufferCount] = {nullptr}
 
ble_gap_adv_data_t _advData
 
bool _advertisementDataBuffersInUse [2 *_advertisementDataBufferCount] = {false}
 

Static Private Attributes

static const uint8_t _advertisementDataBufferCount = 2
 
static const uint8_t _advertisementDataBufferSize = BLE_GAP_ADV_SET_DATA_SIZE_MAX
 

Constructor & Destructor Documentation

◆ Advertiser() [1/2]

◆ Advertiser() [2/2]

Advertiser::Advertiser ( Advertiser const &  )
delete

Member Function Documentation

◆ allocateAdvertisementDataBuffers()

bool Advertiser::allocateAdvertisementDataBuffers ( bool  scanResponse)
private

Allocate the advertisement data buffers.

Returns true on success.

◆ configureAdvertisement() [1/2]

void Advertiser::configureAdvertisement ( IBeacon beacon,
bool  asScanResponse = false 
)

Configure the advertisement to hold iBeacon data.

Sets and updates the advertisement data.

Parameters
[in]beaconObject with the iBeacon parameters.
[in]asScanResponseWhether to set the iBeacon data in the scan response.

◆ configureAdvertisement() [2/2]

void Advertiser::configureAdvertisement ( ServiceData serviceData,
bool  asScanResponse = false 
)

Configure the advertisement to hold Crownstone service data.

Sets and updates the advertisement data.

Parameters
[in]serviceDataThe Crownstone service data class.
[in]asScanResponseWhether to set the service data in the scan response.

◆ configureAdvertisementParameters()

void Advertiser::configureAdvertisementParameters ( )
private

Set advertisement parameters from member variables.

◆ getAdvertisementBuffer()

uint8_t * Advertiser::getAdvertisementBuffer ( bool  scanResponse)
private

Gets an advertisement data buffer that's not in use.

Parameters
[in]scanResponseWhether to get a scan response data buffer.
Returns
Pointer to the buffer, or a nullptr if no free buffer is found.

◆ getInstance()

static Advertiser & Advertiser::getInstance ( )
inlinestatic

Get the static singleton instance.

◆ handleEvent()

void Advertiser::handleEvent ( event_t event)
virtual

Internal usage.

Implements EventListener.

◆ init()

void Advertiser::init ( )

Initialize the advertiser.

Can only be done after the radio has been initialized. It's best to configure the advertiser before initializing.

Starts listening for events.

◆ markAdvertisementBuffer()

void Advertiser::markAdvertisementBuffer ( const uint8_t *  buffer,
bool  inUse,
bool  scanResponse 
)
private

Mark an advertisement buffer as in use / no longer in use.

Parameters
[in]bufferPointer to the advertisement data buffer.
[in]inUseWhether to mark buffer as in use.
[in]scanResponseWhether the buffer is a scan response data buffer.

◆ onConnect()

void Advertiser::onConnect ( const ble_connected_t connectedData)
private

◆ onConnectOutgoing()

void Advertiser::onConnectOutgoing ( )
private

◆ onDisconnect()

void Advertiser::onDisconnect ( )
private

◆ onTick()

void Advertiser::onTick ( )
private

◆ operator=()

void Advertiser::operator= ( Advertiser const &  )
delete

◆ printAdvertisement()

void Advertiser::printAdvertisement ( )
private

◆ restartAdvertising()

void Advertiser::restartAdvertising ( )
private

Stop and start advertising.

This will make sure new advertising parameters are applied.

◆ setAdvertisementData() [1/2]

void Advertiser::setAdvertisementData ( IBeacon beacon,
bool  asScanResponse 
)
private

Sets the advertisement data.

Writes to _config_advdata.

Parameters
[in]beaconThe iBeacon data.
[in]asScanResponseWhether to set the iBeacon data in the scan response.

◆ setAdvertisementData() [2/2]

void Advertiser::setAdvertisementData ( ServiceData serviceData,
bool  asScanResponse 
)
private

Sets the advertisement data.

Parameters
[in]serviceDataThe Crownstone service data class.
[in]asScanResponseWhether to set the service data in the scan response.

◆ setAdvertisingInterval()

void Advertiser::setAdvertisingInterval ( uint16_t  advertisingInterval)

Set the advertising interval in 0.625 ms units.

◆ setConnectable()

void Advertiser::setConnectable ( bool  connectable)

Set whether to advertise being connectable.

Parameters
[in]connectableTrue when connectable.

◆ setConnectableAdvParams()

void Advertiser::setConnectableAdvParams ( )
private

Sets advertisement parameters to be connectable.

◆ setDeviceName()

void Advertiser::setDeviceName ( const std::string &  deviceName)

Set the name of this Crownstone.

◆ setLowTxPower()

void Advertiser::setLowTxPower ( )

Sets TX power to low TX power as stored in State.

◆ setNonConnectableAdvParams()

void Advertiser::setNonConnectableAdvParams ( )
private

Sets advertisement parameters to be non-connectable.

◆ setNormalTxPower()

void Advertiser::setNormalTxPower ( )

Sets TX power to normal TX power as stored in State.

◆ setTxPower()

void Advertiser::setTxPower ( int8_t  power)

Set the radio transmit power.

Parameters
[in]powerPower in dBm. Accepted values are -40, -20, -16, -12, -8, -4, 0, and 4.

◆ startAdvertising()

void Advertiser::startAdvertising ( )

Start advertising.

Make sure you configured an advertisement before starting to advertise.

◆ stopAdvertising()

void Advertiser::stopAdvertising ( )

Stop advertising.

◆ updateAdvertisementData()

void Advertiser::updateAdvertisementData ( )
private

Sets and updates advertisement data.

Sets _advData, and sets it at softdevice if there's a valid handle. Uses a different buffer than previous time.

◆ updateAdvertisementParams()

void Advertiser::updateAdvertisementParams ( )
private

Updates the advertisement parameters.

When parameters are changed, advertising will be stopped and started again. Else, only the service data is updated.

◆ updateTxPower()

void Advertiser::updateTxPower ( )
private

Set the cached TX power at the softdevice.

Can only be done once the advHandle is set.

Member Data Documentation

◆ _advData

ble_gap_adv_data_t Advertiser::_advData
private

◆ _advertisementDataBufferCount

const uint8_t Advertiser::_advertisementDataBufferCount = 2
staticprivate

◆ _advertisementDataBuffers

uint8_t* Advertiser::_advertisementDataBuffers[2 *_advertisementDataBufferCount] = {nullptr}
private

◆ _advertisementDataBuffersInUse

bool Advertiser::_advertisementDataBuffersInUse[2 *_advertisementDataBufferCount] = {false}
private

◆ _advertisementDataBufferSize

const uint8_t Advertiser::_advertisementDataBufferSize = BLE_GAP_ADV_SET_DATA_SIZE_MAX
staticprivate

◆ _advertising

bool Advertiser::_advertising = false
private

◆ _advertisingInterval

uint16_t Advertiser::_advertisingInterval = g_ADVERTISEMENT_INTERVAL
private

◆ _advHandle

uint8_t Advertiser::_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET
private

◆ _advParams

ble_gap_adv_params_t Advertiser::_advParams
private

◆ _advParamsChanged

bool Advertiser::_advParamsChanged = false
private

◆ _configAdvertisementData

ble_advdata_t Advertiser::_configAdvertisementData
private

Advertisement data config, filled by one or more advertisement data fields.

In between step to be encoded into an advertisement data buffer.

◆ _configScanResponse

ble_advdata_t Advertiser::_configScanResponse
private

Scan response data config, filled by one or more advertisement data fields.

In between step to be encoded into a scan response data buffer.

◆ _crownstoneServiceData

ble_advdata_service_data_t Advertiser::_crownstoneServiceData
private

◆ _deviceName

std::string Advertiser::_deviceName = "none"
private

◆ _ibeaconManufData

ble_advdata_manuf_data_t Advertiser::_ibeaconManufData
private

◆ _includeAdvertisementData

bool Advertiser::_includeAdvertisementData = false
private

Whether the advertisement data config has been filled.

When true, the advertisement data buffers are also allocated.

◆ _includeScanResponseData

bool Advertiser::_includeScanResponseData = false
private

Whether the scan response data config has been filled.

When true, the scan response data buffers are also allocated.

◆ _isConnectable

bool Advertiser::_isConnectable = false
private

◆ _isInitialized

bool Advertiser::_isInitialized = false
private

◆ _serviceData

ServiceData* Advertiser::_serviceData = nullptr
private

◆ _stack

Stack* Advertiser::_stack = nullptr
private

◆ _startOnNextTick

bool Advertiser::_startOnNextTick = false
private

◆ _txPower

int8_t Advertiser::_txPower = 0
private

◆ _wantAdvertising

bool Advertiser::_wantAdvertising = false
private

◆ _wantConnectable

bool Advertiser::_wantConnectable = true
private

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