Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_MeshTopologyResearch.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: May 6, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
13#include <util/cs_Coroutine.h>
14#include <util/cs_Variance.h>
15
16#include <cstdint>
17#include <map>
18
29public:
31
44 void handleEvent(event_t& evt);
45
49 void init();
50
51private:
53
54 // stores the relevant history, per neighbor stone_id.
55 static constexpr uint8_t CHANNEL_COUNT = 3;
56 static constexpr uint8_t CHANNEL_START = 37;
57
58 // TODO: change maps to object for small ram memory footprint optimization
59 std::map<stone_id_t, VarianceAggregator> variance_map[CHANNEL_COUNT] = {};
60
61 // will be set to true by coroutine to flush data after startup.
63
64 // loop variables to keep track of outside of coroutine for the burst loop
66
67 // --------------- Coroutine parameters ---------------
68
70
78
83
88
94 };
95
96 static constexpr TimingSettings Settings = {
97#ifdef DEBUG
99 .burst_period_ms = 500,
100 .accumulation_period_ms = 2 * 60 * 1000,
101 .boot_sequence_period_ms = 1 * 60 * 1000
102#else
103 .min_samples_to_trigger_burst = 20,
104 .burst_period_ms = 5,
105 .accumulation_period_ms = 30 * 60 * 1000,
106 .boot_sequence_period_ms = 1 * 60 * 1000,
107#endif
108 };
109
110 // -------------------- Methods --------------------
111
124
129 inline uint8_t getVarianceRepresentation(float standard_deviation);
130
135 inline uint8_t getMeanRssiRepresentation(float mean);
136
141 inline uint8_t getCountRepresentation(uint32_t count);
142
143 // --------------- generating rssi data --------------
144
150
158
163 void receivePingMessage(MeshMsgEvent& mesh_msg_evt);
164
165 // ------------- communicating rssi data -------------
166
172
178
185
186 // ------------- recording mesh messages -------------
187
193
199 void recordRssiValue(stone_id_t sender_id, int8_t rssi, uint8_t channel);
200};
A coroutine essentially is a throttling mechanism: it takes in a tick-event or tick count and execute...
Definition: cs_Coroutine.h:40
Event listener.
Definition: cs_EventListener.h:17
Definition: cs_MeshMsgEvent.h:71
This class/component keeps track of the rssi distance of a crownstone to its neighbors (i....
Definition: cs_MeshTopologyResearch.h:28
static constexpr uint8_t CHANNEL_COUNT
Definition: cs_MeshTopologyResearch.h:55
void recordRssiValue(stone_id_t sender_id, int8_t rssi, uint8_t channel)
Saves rssi value to last received map and variance recorder map.
uint8_t getMeanRssiRepresentation(float mean)
Returns the 7 bit representation of the given mean as defined in cs_PacketsInternal....
stone_id_t my_id
Definition: cs_MeshTopologyResearch.h:52
void init()
Obtains the stone_id_t of this crownstone to use for forwarded ping messages.
void handleEvent(event_t &evt)
Handles the following events: CS_TICK: Coroutine for rssi data updates.
uint8_t getCountRepresentation(uint32_t count)
Returns the 6 bit representation of the given count as defined in cs_PacketsInternal....
bool boot_sequence_finished
Definition: cs_MeshTopologyResearch.h:62
Coroutine flushRoutine
Definition: cs_MeshTopologyResearch.h:69
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.
uint8_t getVarianceRepresentation(float standard_deviation)
Returns the 3 bit descriptor of the given variance as defined in cs_PacketsInternal....
void receiveRssiDataMessage(MeshMsgEvent &mesh_msg_evt)
Any received rssi_data_message_t will be sendRssiDataOverUart.
void sendPingRequestOverMesh()
Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CS_MESH_MODEL_TYPE_RSSI_PING.
void receiveMeshMsgEvent(MeshMsgEvent &mesh_msg_evt)
If the event was no-hop:
std::map< stone_id_t, VarianceAggregator > variance_map[CHANNEL_COUNT]
Definition: cs_MeshTopologyResearch.h:59
static constexpr uint8_t CHANNEL_START
Definition: cs_MeshTopologyResearch.h:56
void sendPingResponseOverMesh()
Dispatches an event of type CMD_SEND_MESH_MSG in order to send a CMD_SEND_MESH_MSG_NOOP.
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.
stone_id_t last_stone_id_broadcasted_in_burst
Definition: cs_MeshTopologyResearch.h:65
static constexpr TimingSettings Settings
Definition: cs_MeshTopologyResearch.h:96
uint32_t flushAggregatedRssiData()
Coroutine method: To prevent the mesh from flooding, flushing is throttled.
void receivePingMessage(MeshMsgEvent &mesh_msg_evt)
If the ping message is a request that has not hopped,.
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
uint8_t stone_id_t
Definition: cs_Typedefs.h:23
Definition: cs_MeshTopologyResearch.h:71
uint32_t boot_sequence_period_ms
When boot sequence period expires, a flush (burst) of the rssi data will be triggered.
Definition: cs_MeshTopologyResearch.h:93
uint32_t accumulation_period_ms
This value determines the period between end and start of bursts.
Definition: cs_MeshTopologyResearch.h:87
uint32_t burst_period_ms
Period between sending data in 'burst mode'.
Definition: cs_MeshTopologyResearch.h:82
uint8_t min_samples_to_trigger_burst
When flushAggregatedRssiData is in the flushing phase, only variance_map entries that have accumulate...
Definition: cs_MeshTopologyResearch.h:77
Definition: cs_MeshModelPackets.h:286