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

#include <cs_AssetStore.h>

Inheritance diagram for AssetStore:
Collaboration diagram for AssetStore:

Public Member Functions

 AssetStore ()
 
cs_ret_code_t init () override
 Components can implement this if they need to get references to sibling or if they need to do specific initialization. More...
 
void handleEvent (event_t &evt) override
 Handle events. More...
 
asset_record_thandleAcceptedAsset (const scanned_device_t &asset, const asset_id_t &assetId)
 Get or create a record for the given assetId. More...
 
asset_record_tgetRecord (const asset_id_t &id)
 returns a pointer of record if found, else returns nullptr. More...
 
void addThrottlingBump (asset_record_t &record, uint16_t timeToNextThrottleOpenMs)
 Adds a value to the records' throttlingCountdownTicks. More...
 
uint16_t throttlingBumpMsToTicks (uint16_t timeToNextThrottleOpenMs)
 Convert ms to ticks, rounding fractional parts upwards. 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 uint8_t LAST_RECEIVED_TIMEOUT_THRESHOLD_S = 250
 Time in seconds after which a record is timed out. More...
 
static constexpr auto LAST_RECEIVED_COUNTER_PERIOD_MS = 1000
 Interval at which the timeout counter is increased, should be 1 second. More...
 
static constexpr auto THROTTLE_COUNTER_PERIOD_MS = 100
 Interval at which the throttle countdown is decreased. More...
 

Private Member Functions

asset_record_tgetOrCreateRecord (const asset_id_t &id)
 returns a pointer of record if found, else tries to create a new blank record and return a pointer to that, else returns nullptr. More...
 
void incrementLastReceivedCounters ()
 Adds 1 to the update/sent counters of all valid records, until 0xff is reached. More...
 
void decrementThrottlingCounters ()
 Decrements throttlingCountdownTicks by 1of all valid records, until zero is reached. More...
 

Private Attributes

Store< asset_record_t, MAX_RECORDS_store
 
Coroutine updateLastReceivedCounterRoutine
 
Coroutine updateLastSentCounterRoutine
 

Static Private Attributes

static constexpr auto MAX_RECORDS = 50u
 

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...
 

Constructor & Destructor Documentation

◆ AssetStore()

Member Function Documentation

◆ addThrottlingBump()

void AssetStore::addThrottlingBump ( asset_record_t record,
uint16_t  timeToNextThrottleOpenMs 
)

Adds a value to the records' throttlingCountdownTicks.

This will ensure that the record.isThrottled() will be true for (at least) timeToNextThrottleOpenMs.

◆ decrementThrottlingCounters()

void AssetStore::decrementThrottlingCounters ( )
private

Decrements throttlingCountdownTicks by 1of all valid records, until zero is reached.

◆ getOrCreateRecord()

asset_record_t * AssetStore::getOrCreateRecord ( const asset_id_t id)
private

returns a pointer of record if found, else tries to create a new blank record and return a pointer to that, else returns nullptr.

◆ getRecord()

asset_record_t * AssetStore::getRecord ( const asset_id_t id)

returns a pointer of record if found, else returns nullptr.

◆ handleAcceptedAsset()

asset_record_t * AssetStore::handleAcceptedAsset ( const scanned_device_t asset,
const asset_id_t assetId 
)

Get or create a record for the given assetId.

Then update rssi values according to the incoming scan and revert the lastReceivedCounter to 0.

Returns the adjusted record if found, else returns nullptr

◆ handleEvent()

void AssetStore::handleEvent ( event_t event)
overridevirtual

Handle events.

This method is overloaded by all classes that derive from EventListener. They can receive an event_t struct and act upon it. These events are dispatched by the EventDispatcher.

Implements EventListener.

◆ incrementLastReceivedCounters()

void AssetStore::incrementLastReceivedCounters ( )
private

Adds 1 to the update/sent counters of all valid records, until 0xff is reached.

◆ init()

cs_ret_code_t AssetStore::init ( )
overridevirtual

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.

◆ throttlingBumpMsToTicks()

uint16_t AssetStore::throttlingBumpMsToTicks ( uint16_t  timeToNextThrottleOpenMs)

Convert ms to ticks, rounding fractional parts upwards.

Member Data Documentation

◆ _store

Store<asset_record_t, MAX_RECORDS> AssetStore::_store
private

◆ LAST_RECEIVED_COUNTER_PERIOD_MS

constexpr auto AssetStore::LAST_RECEIVED_COUNTER_PERIOD_MS = 1000
staticconstexpr

Interval at which the timeout counter is increased, should be 1 second.

◆ LAST_RECEIVED_TIMEOUT_THRESHOLD_S

constexpr uint8_t AssetStore::LAST_RECEIVED_TIMEOUT_THRESHOLD_S = 250
staticconstexpr

Time in seconds after which a record is timed out.

Must be smaller than 0xFF.

◆ MAX_RECORDS

constexpr auto AssetStore::MAX_RECORDS = 50u
staticconstexprprivate

◆ THROTTLE_COUNTER_PERIOD_MS

constexpr auto AssetStore::THROTTLE_COUNTER_PERIOD_MS = 100
staticconstexpr

Interval at which the throttle countdown is decreased.

◆ updateLastReceivedCounterRoutine

Coroutine AssetStore::updateLastReceivedCounterRoutine
private

◆ updateLastSentCounterRoutine

Coroutine AssetStore::updateLastSentCounterRoutine
private

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