Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_MeshTopology.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Apr 30, 2021
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
12
13#include <cstdint>
14
15#if BUILD_MESH_TOPOLOGY_RESEARCH == 1
17#endif
18
20public:
24 static constexpr uint8_t MAX_NEIGHBOURS = 50;
25
29 static constexpr uint8_t TIMEOUT_SECONDS = 3 * 60;
30
34 static constexpr uint16_t SEND_INTERVAL_SECONDS_PER_NEIGHBOUR = 5 * 60;
35 static constexpr uint16_t SEND_INTERVAL_SECONDS_PER_NEIGHBOUR_FAST = 10;
36
42 static constexpr uint16_t SEND_NOOP_INTERVAL_SECONDS = 1 * 60;
43 static constexpr uint16_t SEND_NOOP_INTERVAL_SECONDS_FAST = 10;
44
48 static constexpr uint16_t FAST_INTERVAL_TIMEOUT_SECONDS = 5 * 60;
49
57
68
69private:
70 static constexpr uint8_t INDEX_NOT_FOUND = 0xFF;
71
72 static constexpr int8_t RSSI_INIT = 0; // Should be in protocol
73
74 struct __attribute__((__packed__)) neighbour_node_t {
80 };
81
86
91
95 uint8_t _neighbourCount = 0;
96
100 uint8_t _nextSendIndex = 0;
101
106
111
116
120 uint8_t _msgCount = 0;
121
125 void reset();
126
130 void add(stone_id_t id, int8_t rssi, uint8_t channel);
131
135 void updateNeighbour(neighbour_node_t& node, stone_id_t id, int8_t rssi, uint8_t channel);
136
140 uint8_t find(stone_id_t id);
141
145 void getRssi(stone_id_t stoneId, cs_result_t& result);
146
150 void sendNoop();
151
155 void sendNext();
156
161
162 // Event handlers
165 void onMeshMsg(MeshMsgEvent& packet, cs_result_t& result);
167
171 void print();
172
173public:
178
179#if BUILD_MESH_TOPOLOGY_RESEARCH == 1
180private:
181 MeshTopologyResearch _research;
182#endif
183};
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
Definition: cs_MeshTopology.h:19
static constexpr uint8_t TIMEOUT_SECONDS
Time after last seen, before a neighbour is removed from the list.
Definition: cs_MeshTopology.h:29
static constexpr uint16_t FAST_INTERVAL_TIMEOUT_SECONDS
After a reset, the FAST intervals will be used instead, for this amount of seconds.
Definition: cs_MeshTopology.h:48
cs_ret_code_t onStoneMacMsg(MeshMsgEvent &meshMsg)
cs_ret_code_t getMacAddress(stone_id_t stoneId)
Get the MAC address of a neighbouring crownstone.
void sendNoop()
Send a no-hop noop mesh message.
void getRssi(stone_id_t stoneId, cs_result_t &result)
Get the RSSI of given stone ID and put it in the result buffer.
uint16_t _sendCountdown
Countdown in seconds until sending the next mesh message.
Definition: cs_MeshTopology.h:105
void reset()
Resets the stored topology.
uint16_t _fastIntervalCountdown
Countdown in seconds until sending at regular interval again.
Definition: cs_MeshTopology.h:115
neighbour_node_t * _neighbours
A list of all known neighbours, allocated on init.
Definition: cs_MeshTopology.h:90
static constexpr uint16_t SEND_INTERVAL_SECONDS_PER_NEIGHBOUR
Interval at which a mesh messages is sent for each neighbour.
Definition: cs_MeshTopology.h:34
void onNeighbourRssi(stone_id_t id, cs_mesh_model_msg_neighbour_rssi_t &packet)
void onTickSecond()
uint16_t _sendNoopCountdown
Countdown in seconds until sending the next no hop ping mesh message.
Definition: cs_MeshTopology.h:110
static constexpr uint16_t SEND_NOOP_INTERVAL_SECONDS_FAST
Definition: cs_MeshTopology.h:43
stone_id_t _myId
Stone ID of this crownstone, read on init.
Definition: cs_MeshTopology.h:85
static constexpr uint8_t INDEX_NOT_FOUND
Definition: cs_MeshTopology.h:70
uint8_t _msgCount
Overflowing message counter.
Definition: cs_MeshTopology.h:120
uint8_t find(stone_id_t id)
Find a neighbour in the list.
void handleEvent(event_t &evt)
Internal usage.
void sendNext()
Sends the RSSI of 1 neighbour over the mesh and UART.
static constexpr uint8_t MAX_NEIGHBOURS
Maximum number of neighbours in the list.
Definition: cs_MeshTopology.h:24
static constexpr uint16_t SEND_INTERVAL_SECONDS_PER_NEIGHBOUR_FAST
Definition: cs_MeshTopology.h:35
cs_ret_code_t init()
Initializes the class:
static constexpr int8_t RSSI_INIT
Definition: cs_MeshTopology.h:72
void print()
Print all neighbours.
uint8_t _nextSendIndex
Next index of the neighbours list to send via the mesh.
Definition: cs_MeshTopology.h:100
static constexpr uint16_t SEND_NOOP_INTERVAL_SECONDS
Interval at which a no-hop noop message is sent.
Definition: cs_MeshTopology.h:42
void add(stone_id_t id, int8_t rssi, uint8_t channel)
Add a neighbour to the list.
void updateNeighbour(neighbour_node_t &node, stone_id_t id, int8_t rssi, uint8_t channel)
Update the data of a node in the list.
void onMeshMsg(MeshMsgEvent &packet, cs_result_t &result)
uint8_t _neighbourCount
Number of neighbours in the list.
Definition: cs_MeshTopology.h:95
void sendRssiToUart(stone_id_t reveiverId, cs_mesh_model_msg_neighbour_rssi_t &packet)
Sends the RSSI to a neighbour over UART.
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
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
Definition: cs_MeshTopology.h:74
stone_id_t id
Definition: cs_MeshTopology.h:75
int8_t rssiChannel37
Definition: cs_MeshTopology.h:76
int8_t rssiChannel39
Definition: cs_MeshTopology.h:78
int8_t rssiChannel38
Definition: cs_MeshTopology.h:77
uint8_t lastSeenSecondsAgo
Definition: cs_MeshTopology.h:79
Definition: cs_MeshModelPackets.h:293
Definition: cs_PacketsInternal.h:46