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

This class/component keeps track of the rssi distance of a crownstone to its neighbors (i.e. More...

#include <cs_MeshTopologyResearch.h>

Inheritance diagram for MeshTopologyResearch:
Collaboration diagram for MeshTopologyResearch:

Classes

struct  TimingSettings
 

Public Member Functions

 MeshTopologyResearch ()
 
void handleEvent (event_t &evt)
 Handles the following events: CS_TICK: Coroutine for rssi data updates. More...
 
void init ()
 Obtains the stone_id_t of this crownstone to use for forwarded ping messages. 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...
 

Private Member Functions

uint32_t flushAggregatedRssiData ()
 Coroutine method: To prevent the mesh from flooding, flushing is throttled. More...
 
uint8_t getVarianceRepresentation (float standard_deviation)
 Returns the 3 bit descriptor of the given variance as defined in cs_PacketsInternal.h. More...
 
uint8_t getMeanRssiRepresentation (float mean)
 Returns the 7 bit representation of the given mean as defined in cs_PacketsInternal.h. More...
 
uint8_t getCountRepresentation (uint32_t count)
 Returns the 6 bit representation of the given count as defined in cs_PacketsInternal.h. More...
 
void sendPingRequestOverMesh ()
 Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CS_MESH_MODEL_TYPE_RSSI_PING. More...
 
void sendPingResponseOverMesh ()
 Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CMD_SEND_MESH_MSG_NOOP. More...
 
void receivePingMessage (MeshMsgEvent &mesh_msg_evt)
 If the ping message is a request that has not hopped,. More...
 
void sendRssiDataOverMesh (rssi_data_message_t *rssi_data_message)
 Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CS_MESH_MODEL_TYPE_RSSI_DATA. More...
 
void sendRssiDataOverUart (rssi_data_message_t *rssi_data_message)
 Writes a message of type UART_OPCODE_TX_RSSI_DATA_MESSAGE with the given parameter as data. More...
 
void receiveRssiDataMessage (MeshMsgEvent &mesh_msg_evt)
 Any received rssi_data_message_t will be sendRssiDataOverUart. More...
 
void receiveMeshMsgEvent (MeshMsgEvent &mesh_msg_evt)
 If the event was no-hop: More...
 
void recordRssiValue (stone_id_t sender_id, int8_t rssi, uint8_t channel)
 Saves rssi value to last received map and variance recorder map. More...
 

Private Attributes

stone_id_t my_id = 0xff
 
std::map< stone_id_t, VarianceAggregatorvariance_map [CHANNEL_COUNT] = {}
 
bool boot_sequence_finished = false
 
stone_id_t last_stone_id_broadcasted_in_burst = 0
 
Coroutine flushRoutine
 

Static Private Attributes

static constexpr uint8_t CHANNEL_COUNT = 3
 
static constexpr uint8_t CHANNEL_START = 37
 
static constexpr TimingSettings Settings
 

Detailed Description

This class/component keeps track of the rssi distance of a crownstone to its neighbors (i.e.

those within zero hop distance on the mesh).

At configurable intervals it will broadcast its acquired data in a burst over the mesh so that a hub, or other interested connected devices can retrieve it.

Constructor & Destructor Documentation

◆ MeshTopologyResearch()

Member Function Documentation

◆ flushAggregatedRssiData()

uint32_t MeshTopologyResearch::flushAggregatedRssiData ( )
private

Coroutine method: To prevent the mesh from flooding, flushing is throttled.

  • Flush period: 30 minutes
  • Burst period: 5 milliseconds

Broadcasts a rssi_data_message_t for each of the pairs of crownstones in the local maps, together with the (oriented) average rssi value between those stones. After that, clear all the maps.

◆ getCountRepresentation()

uint8_t MeshTopologyResearch::getCountRepresentation ( uint32_t  count)
inlineprivate

Returns the 6 bit representation of the given count as defined in cs_PacketsInternal.h.

◆ getMeanRssiRepresentation()

uint8_t MeshTopologyResearch::getMeanRssiRepresentation ( float  mean)
inlineprivate

Returns the 7 bit representation of the given mean as defined in cs_PacketsInternal.h.

◆ getVarianceRepresentation()

uint8_t MeshTopologyResearch::getVarianceRepresentation ( float  standard_deviation)
inlineprivate

Returns the 3 bit descriptor of the given variance as defined in cs_PacketsInternal.h.

◆ handleEvent()

void MeshTopologyResearch::handleEvent ( event_t evt)
virtual

Handles the following events: CS_TICK: Coroutine for rssi data updates.

CS_TYPE_EVT_RECV_MESH_MSG of types:

  • CS_MESH_MODEL_TYPE_RSSI_PING
  • CS_MESH_MODEL_TYPE_RSSI_DATA

(Will propagate data over UART for the hub to use it.)

Implements EventListener.

◆ init()

void MeshTopologyResearch::init ( )

Obtains the stone_id_t of this crownstone to use for forwarded ping messages.

◆ receiveMeshMsgEvent()

void MeshTopologyResearch::receiveMeshMsgEvent ( MeshMsgEvent mesh_msg_evt)
private

If the event was no-hop:

  • recordRssiValue(args...)

◆ receivePingMessage()

void MeshTopologyResearch::receivePingMessage ( MeshMsgEvent mesh_msg_evt)
private

If the ping message is a request that has not hopped,.

◆ receiveRssiDataMessage()

void MeshTopologyResearch::receiveRssiDataMessage ( MeshMsgEvent mesh_msg_evt)
private

Any received rssi_data_message_t will be sendRssiDataOverUart.

Assumes mesh_msg_event is of type CS_MESH_MODEL_TYPE_RSSI_DATA.

◆ recordRssiValue()

void MeshTopologyResearch::recordRssiValue ( stone_id_t  sender_id,
int8_t  rssi,
uint8_t  channel 
)
private

Saves rssi value to last received map and variance recorder map.

If the long term recorder has accumulated a lot of data, it will be reduced to prevent overflow.

◆ sendPingRequestOverMesh()

void MeshTopologyResearch::sendPingRequestOverMesh ( )
private

Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CS_MESH_MODEL_TYPE_RSSI_PING.

◆ sendPingResponseOverMesh()

void MeshTopologyResearch::sendPingResponseOverMesh ( )
private

Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CMD_SEND_MESH_MSG_NOOP.

(This nop will be handled by receiveGenericMeshMessage)

◆ sendRssiDataOverMesh()

void MeshTopologyResearch::sendRssiDataOverMesh ( rssi_data_message_t rssi_data_message)
private

Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CS_MESH_MODEL_TYPE_RSSI_DATA.

◆ sendRssiDataOverUart()

void MeshTopologyResearch::sendRssiDataOverUart ( rssi_data_message_t rssi_data_message)
private

Writes a message of type UART_OPCODE_TX_RSSI_DATA_MESSAGE with the given parameter as data.

Member Data Documentation

◆ boot_sequence_finished

bool MeshTopologyResearch::boot_sequence_finished = false
private

◆ CHANNEL_COUNT

constexpr uint8_t MeshTopologyResearch::CHANNEL_COUNT = 3
staticconstexprprivate

◆ CHANNEL_START

constexpr uint8_t MeshTopologyResearch::CHANNEL_START = 37
staticconstexprprivate

◆ flushRoutine

Coroutine MeshTopologyResearch::flushRoutine
private

◆ last_stone_id_broadcasted_in_burst

stone_id_t MeshTopologyResearch::last_stone_id_broadcasted_in_burst = 0
private

◆ my_id

stone_id_t MeshTopologyResearch::my_id = 0xff
private

◆ Settings

constexpr TimingSettings MeshTopologyResearch::Settings
staticconstexprprivate
Initial value:
= {
.min_samples_to_trigger_burst = 20,
.burst_period_ms = 5,
.accumulation_period_ms = 30 * 60 * 1000,
.boot_sequence_period_ms = 1 * 60 * 1000,
}

◆ variance_map

std::map<stone_id_t, VarianceAggregator> MeshTopologyResearch::variance_map[CHANNEL_COUNT] = {}
private

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