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

AssetForwarder makes it possible for the AssetFiltering to merge mesh messages when they have very similar data. More...

#include <cs_AssetForwarder.h>

Inheritance diagram for AssetForwarder:
Collaboration diagram for AssetForwarder:

Classes

struct  outbox_msg_t
 

Public Member Functions

cs_ret_code_t init ()
 Components can implement this if they need to get references to sibling or if they need to do specific initialization. More...
 
void flush ()
 Sends the mesh messages in the outbox and clears it. More...
 
void clearOutbox ()
 Removes all messages currently queued for sending. More...
 
bool sendAssetMacToMesh (asset_record_t *record, const scanned_device_t &asset)
 Prepare a CS_MESH_MODEL_TYPE_ASSET_RSSI_MAC message and put it on the outbox. More...
 
bool sendAssetIdToMesh (asset_record_t *record, const scanned_device_t &asset, const asset_id_t &assetId, uint8_t filterBitmask)
 Prepare a CS_MESH_MODEL_TYPE_ASSET_INFO message and put it on the outbox. More...
 
void setThrottleCountdownBumpTicks (uint8_t ticks)
 sets how many ticks will be added to records upon sending a message. More...
 
virtual void handleEvent (event_t &event)
 Forwards relevant incoming mesh messages to UART. More...
 
- Public 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...
 
- Public Member Functions inherited from Component
template<class T >
T * getComponent (Component *requester=nullptr)
 Returns a component of type T* from _parent->children(), If not found try again with ancestors: _parent-> ... ->_parent->children(). More...
 
virtual cs_ret_code_t init ()
 Components can implement this if they need to get references to sibling or if they need to do specific initialization. More...
 
void parentAllChildren ()
 utility that loops over all elements of getChildren() and setParent on the non-nullptr ones. More...
 
virtual ~Component ()=default
 

Static Public Attributes

static constexpr uint16_t MIN_THROTTLED_ADVERTISEMENT_PERIOD_MS = 1000
 

Private Member Functions

bool dispatchOutboxMessage (outbox_msg_t &outMsg)
 validates the message, then update throttle send over uart send over mesh More...
 
outbox_msg_tgetEmptyOutboxSlot ()
 Returns an empty slot in the outbox. More...
 
outbox_msg_tfindSimilar (outbox_msg_t &outMsg)
 Returns a similar message in the outbox. More...
 
bool addToOutbox (outbox_msg_t &outMsg)
 Adds a message to the outbox. More...
 
void forwardAssetToUart (const cs_mesh_model_msg_asset_report_mac_t &assetMsg, stone_id_t seenByStoneId)
 Forward an asset mesh message to UART. More...
 
void forwardAssetToUart (const cs_mesh_model_msg_asset_report_id_t &assetMsg, stone_id_t seenByStoneId)
 

Private Attributes

stone_id_t _myStoneId
 
uint8_t _throttleCountdownBumpTicks = 0
 
outbox_msg_t _outbox [8] = {}
 

Additional Inherited Members

- Protected Member Functions inherited from Component
virtual std::vector< Component * > getChildren ()
 Components with children can override this method to return them. More...
 
cs_ret_code_t initChildren ()
 
void setParent (Component *p)
 Children that are instantiated later can also be added individually. More...
 

Detailed Description

AssetForwarder makes it possible for the AssetFiltering to merge mesh messages when they have very similar data.

To use it, you place messages in the 'outbox' with sendAssetMacToMesh(..) or sendAssetIdToMesh(..). These functions merge the message with a similar one depending on the respective type.

After all messages have been created, call flush() to send the message, or clearOutbox() to cancel your plans.

By passing an asset_record along the flush() function will update the throttling counter.

Member Function Documentation

◆ addToOutbox()

bool AssetForwarder::addToOutbox ( outbox_msg_t outMsg)
private

Adds a message to the outbox.

Merges wit message in outbox if possible. Returns true on success.

◆ clearOutbox()

void AssetForwarder::clearOutbox ( )

Removes all messages currently queued for sending.

◆ dispatchOutboxMessage()

bool AssetForwarder::dispatchOutboxMessage ( outbox_msg_t outMsg)
private

validates the message, then update throttle send over uart send over mesh

returns true if message was valid

◆ findSimilar()

outbox_msg_t * AssetForwarder::findSimilar ( outbox_msg_t outMsg)
private

Returns a similar message in the outbox.

Returns null pointer when not found.

◆ flush()

void AssetForwarder::flush ( )

Sends the mesh messages in the outbox and clears it.

Updates the records throttling counters.

Messages are sent over both Uart and Mesh

◆ forwardAssetToUart() [1/2]

void AssetForwarder::forwardAssetToUart ( const cs_mesh_model_msg_asset_report_id_t assetMsg,
stone_id_t  seenByStoneId 
)
private

◆ forwardAssetToUart() [2/2]

void AssetForwarder::forwardAssetToUart ( const cs_mesh_model_msg_asset_report_mac_t assetMsg,
stone_id_t  seenByStoneId 
)
private

Forward an asset mesh message to UART.

Parameters
[in]assetMsgThe mesh message to forward.
[in]seenByStoneIdThe stone that scanned the asset.

◆ getEmptyOutboxSlot()

outbox_msg_t * AssetForwarder::getEmptyOutboxSlot ( )
private

Returns an empty slot in the outbox.

Returns null pointer when there is no empty slot.

◆ handleEvent()

virtual void AssetForwarder::handleEvent ( event_t event)
virtual

Forwards relevant incoming mesh messages to UART.

Implements EventListener.

◆ init()

cs_ret_code_t AssetForwarder::init ( )
virtual

Components can implement this if they need to get references to sibling or if they need to do specific initialization.

  • Components are responsible for calling init() on their children.
  • init is allowed to assume all siblings are constructed.

E.g.

class componentX : public Component { public: cs_ret_code_t init() { // construct childA ... // construct childZ

return initChildren(); } };

Reimplemented from Component.

◆ sendAssetIdToMesh()

bool AssetForwarder::sendAssetIdToMesh ( asset_record_t record,
const scanned_device_t asset,
const asset_id_t assetId,
uint8_t  filterBitmask 
)

Prepare a CS_MESH_MODEL_TYPE_ASSET_INFO message and put it on the outbox.

If an identical message is already contained in the outbox, nothing happens.

Returns true if there was enough space in the outbox to place the message. Else, false.

◆ sendAssetMacToMesh()

bool AssetForwarder::sendAssetMacToMesh ( asset_record_t record,
const scanned_device_t asset 
)

Prepare a CS_MESH_MODEL_TYPE_ASSET_RSSI_MAC message and put it on the outbox.

If an identical message is already contained in the outbox, nothing happens.

Record is required for throttling. If not available, throttling will not be updated.

Returns true if there was enough space in the outbox to place the message. Else, false.

◆ setThrottleCountdownBumpTicks()

void AssetForwarder::setThrottleCountdownBumpTicks ( uint8_t  ticks)

sets how many ticks will be added to records upon sending a message.

Member Data Documentation

◆ _myStoneId

stone_id_t AssetForwarder::_myStoneId
private

◆ _outbox

outbox_msg_t AssetForwarder::_outbox[8] = {}
private

◆ _throttleCountdownBumpTicks

uint8_t AssetForwarder::_throttleCountdownBumpTicks = 0
private

◆ MIN_THROTTLED_ADVERTISEMENT_PERIOD_MS

constexpr uint16_t AssetForwarder::MIN_THROTTLED_ADVERTISEMENT_PERIOD_MS = 1000
staticconstexpr

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