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

This class implements the in-mesh computation of which crownstone is nearest to a 'trackable' device. More...

#include <cs_NearestCrownstoneTracker.h>

Inheritance diagram for NearestCrownstoneTracker:
Collaboration diagram for NearestCrownstoneTracker:

Public Member Functions

cs_ret_code_t init () override
 Caches CONFIG_CROWNSTONE_ID and AssetStore. More...
 
bool handleAcceptedAsset (const scanned_device_t &asset, const asset_id_t &id, uint8_t filterBitmask)
 Returns true if it is desired to send a message to inform other devices in the mesh of relevant changes. More...
 
void handleEvent (event_t &evt)
 Handlers for: EVT_ASSET_ACCEPTED EVT_FILTERS_UPDATED. 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
 

Private Types

enum class  FilterStrategy { TIME_OUT , RSSI_FALL_OFF }
 

Private Member Functions

void handleMeshMsgEvent (event_t &evt)
 Called on EVT_RECV_MESH_MSG events. More...
 
void handleAssetAcceptedEvent (event_t &evt)
 Called on EVT_ASSET_ACCEPTED events. More...
 
bool onReceiveAssetAdvertisement (cs_mesh_model_msg_asset_report_id_t &trackedEvent)
 Heart of the algorithm. More...
 
void onReceiveAssetReport (cs_mesh_model_msg_asset_report_id_t &report, stone_id_t reporter)
 Heart of the algorithm. More...
 
void broadcastReport (cs_mesh_model_msg_asset_report_id_t &report)
 Sends a mesh broadcast for the given report. More...
 
void broadcastPersonalReport (asset_record_t &record)
 makes a report from the records personalRssi field and broadcast it over the mesh. More...
 
void sendUartUpdate (asset_record_t &record)
 Sends a message over UART containing the winner, its rssi and the asset id. More...
 
void onWinnerChanged (bool winnerIsThisCrownstone)
 (Only logs a message) More...
 
void saveWinningReport (asset_record_t &rec, rssi_and_channel_t winningRssi, stone_id_t winningId)
 saves the report in the _winning list. More...
 
asset_record_tgetRecordFiltered (const asset_id_t &assetId)
 getRecord for assetId from assetStore and return it. More...
 

Private Attributes

stone_id_t _myStoneId
 
AssetStore_assetStore
 

Static Private Attributes

static constexpr uint8_t LAST_RECEIVED_TIMEOUT_THRESHOLD = 180
 
static constexpr uint16_t MIN_THROTTLED_ADVERTISEMENT_PERIOD_MS = 100
 
static constexpr uint8_t RSSI_FALL_OFF_RATE_DB_PER_S = 1
 
static constexpr int8_t RSSI_CUT_OFF_THRESHOLD = -90
 
static constexpr auto FILTER_STRATEGY = FilterStrategy::TIME_OUT
 

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

This class implements the in-mesh computation of which crownstone is nearest to a 'trackable' device.

When a trackable device broadcasts an advertisement, and the TrackableParser consequently dispatches a TrackableEvent, it is this class that performs the necessary communication and computation to decide whether or not this crownstone is closest to the trackable device.

It is possible to enable this component on a subset of the crownstones in a mesh if necessary (for optimization purposes perhaps). When doing that, the resulting nearest crownstone will be an element of this subset.

Member Enumeration Documentation

◆ FilterStrategy

enum class NearestCrownstoneTracker::FilterStrategy
strongprivate
Enumerator
TIME_OUT 
RSSI_FALL_OFF 

Member Function Documentation

◆ broadcastPersonalReport()

void NearestCrownstoneTracker::broadcastPersonalReport ( asset_record_t record)
private

makes a report from the records personalRssi field and broadcast it over the mesh.

◆ broadcastReport()

void NearestCrownstoneTracker::broadcastReport ( cs_mesh_model_msg_asset_report_id_t report)
private

Sends a mesh broadcast for the given report.

(stone id of reporter is contained in bluetooth metadata)

◆ getRecordFiltered()

asset_record_t * NearestCrownstoneTracker::getRecordFiltered ( const asset_id_t assetId)
private

getRecord for assetId from assetStore and return it.

return nullptr if rec->lastReceivedCounter is above threshold.

this must be init()-ialized.

◆ handleAcceptedAsset()

bool NearestCrownstoneTracker::handleAcceptedAsset ( const scanned_device_t asset,
const asset_id_t id,
uint8_t  filterBitmask 
)

Returns true if it is desired to send a message to inform other devices in the mesh of relevant changes.

◆ handleAssetAcceptedEvent()

void NearestCrownstoneTracker::handleAssetAcceptedEvent ( event_t evt)
private

Called on EVT_ASSET_ACCEPTED events.

Transforms an accepted asset event into a report and handles it by calling onReceivedAssetAdvertisement.

◆ handleEvent()

void NearestCrownstoneTracker::handleEvent ( event_t evt)
virtual

Handlers for: EVT_ASSET_ACCEPTED EVT_FILTERS_UPDATED.

Implements EventListener.

◆ handleMeshMsgEvent()

void NearestCrownstoneTracker::handleMeshMsgEvent ( event_t evt)
private

Called on EVT_RECV_MESH_MSG events.

Extract report from other crownstones that come in from the mesh and call onReceiveAssetReport.

◆ init()

cs_ret_code_t NearestCrownstoneTracker::init ( )
overridevirtual

Caches CONFIG_CROWNSTONE_ID and AssetStore.

If assetstore is not available, ERR_NOT_FOUND is returned.

Reimplemented from Component.

◆ onReceiveAssetAdvertisement()

bool NearestCrownstoneTracker::onReceiveAssetAdvertisement ( cs_mesh_model_msg_asset_report_id_t trackedEvent)
private

Heart of the algorithm.

See implementation for exact behaviour.

This method implements what a crownstone needs to communicate when it directly receives an advertisement from a trackable device.

Updates personal report, possibly updates winning report.

Returns true if it is desired to send a message to inform other devices in the mesh of relevant changes.

◆ onReceiveAssetReport()

void NearestCrownstoneTracker::onReceiveAssetReport ( cs_mesh_model_msg_asset_report_id_t report,
stone_id_t  reporter 
)
private

Heart of the algorithm.

See implementation for exact behaviour.

This method implements what a crownstone needs to communicate when it receives a message from another crownstone containing information about a trackable device.

Possibly updates winning report and possibly broadcasts a message to inform other devices in the mesh of relevant changes. E.g. when the updated winning report now loses from this devices personal report.

◆ onWinnerChanged()

void NearestCrownstoneTracker::onWinnerChanged ( bool  winnerIsThisCrownstone)
private

(Only logs a message)

◆ saveWinningReport()

void NearestCrownstoneTracker::saveWinningReport ( asset_record_t rec,
rssi_and_channel_t  winningRssi,
stone_id_t  winningId 
)
private

saves the report in the _winning list.

◆ sendUartUpdate()

void NearestCrownstoneTracker::sendUartUpdate ( asset_record_t record)
private

Sends a message over UART containing the winner, its rssi and the asset id.

Member Data Documentation

◆ _assetStore

AssetStore* NearestCrownstoneTracker::_assetStore
private

◆ _myStoneId

stone_id_t NearestCrownstoneTracker::_myStoneId
private

◆ FILTER_STRATEGY

constexpr auto NearestCrownstoneTracker::FILTER_STRATEGY = FilterStrategy::TIME_OUT
staticconstexprprivate

◆ LAST_RECEIVED_TIMEOUT_THRESHOLD

constexpr uint8_t NearestCrownstoneTracker::LAST_RECEIVED_TIMEOUT_THRESHOLD = 180
staticconstexprprivate

◆ MIN_THROTTLED_ADVERTISEMENT_PERIOD_MS

constexpr uint16_t NearestCrownstoneTracker::MIN_THROTTLED_ADVERTISEMENT_PERIOD_MS = 100
staticconstexprprivate

◆ RSSI_CUT_OFF_THRESHOLD

constexpr int8_t NearestCrownstoneTracker::RSSI_CUT_OFF_THRESHOLD = -90
staticconstexprprivate

◆ RSSI_FALL_OFF_RATE_DB_PER_S

constexpr uint8_t NearestCrownstoneTracker::RSSI_FALL_OFF_RATE_DB_PER_S = 1
staticconstexprprivate

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