Go to the documentation of this file.
15 #ifndef INC_MESHTABLES_H_
16 #define INC_MESHTABLES_H_
60 std::string printRowForChangeLog()
const {
61 return std::to_string((
int)
MAC);
132 std::string printRowForChangeLog()
const {
133 return std::to_string((
int)
Source) +
"|" + std::to_string((
int)
Neighbor) +
"|" + std::to_string((
int)
Hop);
183 std::string printRowForChangeLog()
const {
184 return std::to_string((
int)
ID) +
"|" + std::to_string((
int)
Source);
239 std::string printRowForChangeLog()
const {
240 return std::to_string((
int)
ID) +
"|" + std::to_string((
int)
Source) +
"|" + std::to_string(
BSSID);
252 MeshOIDTableRow(uint8_t
id, uint8_t destination, SystemPacketType type);
297 std::string printRowForChangeLog()
const {
298 return std::to_string((
int)
ID) +
"|" + std::to_string((
int)
Destination) +
"|" + std::to_string((
int)
Type);
304 HAS_MEM_FUNC(printRowForChangeLog, has_printRowForChangeLog);
350 template<
typename RowT,
int16_t RowsCount,
bool IndexIsValue = false>
359 static_assert(has_printRowForChangeLog<RowT, std::string(RowT::*)()
const>::value || !std::is_class<RowT>::value,
"RowT class does not have \"std::string printRowForChangeLog() const\" member function, which is needed when logging table change during simulation.");
362 static_assert(RowsCount != 0,
"RowsCount has to be greather than 0.");
363 static_assert(has_printRow<RowT,
size_t(RowT::*)(
OSTREAM&)
const>::value || !std::is_class<RowT>::value || IndexIsValue,
"RowT class has to contain \"size_t printRow(OSTREAM& stream) const\" member function.");
364 static_assert(has_printRow<RowT,
size_t(RowT::*)(
OSTREAM&, int16_t)
const>::value || !std::is_class<RowT>::value || !IndexIsValue,
"RowT class has to contain \"size_t printRow(OSTREAM& stream, int16_t index) const\" member function.");
367 static_assert(is_streamable<RowT>::value || std::is_class<RowT>::value,
"Row type is not class and is not printable, it cannot be used.");
369 static_assert(has_equalityOperator<RowT,
bool(RowT::*)(
const RowT&)
const>::value,
"RowT has to contain basic const binary equality operator ==.");
387 inline const RowT&
get(int16_t index)
const {
396 inline RowT
get(int16_t index) {
424 bool set(int16_t index,
const RowT& row) {
425 if (index < RowsCount && index >= 0) {
435 uint8_t oldLifeTime =
lifeTime[index];
437 onSet(index,
buffer[index], oldLifeTime, row, 255);
438 if (oldLifeTime !=
lifeTime[index]) {
445 if constexpr (has_printRowForChangeLog<RowT, std::string(RowT::*)()
const>::value) {
446 NotifyTableChangeBegin(MST_SET) << (int)index <<
"|" <<
buffer[index].printRowForChangeLog() <<
"|" << (int)
lifeTime[index];
449 NotifyTableChangeBegin(MST_SET) << (int)index <<
"|" <<
buffer[index] <<
"|" << (
int)
lifeTime[index];
451 NotifyTableChangeEnd();
465 bool set(int16_t index,
const RowT& row, int16_t rawLifeTime_) {
466 if (index < RowsCount && index >= 0 && rawLifeTime_ <= 255) {
467 if (rawLifeTime_ < 0) rawLifeTime_ =
lifeTime[index];
468 bool lastValid =
lifeTime[index] != 0;
470 if (lastValid != (rawLifeTime_ != 0)) {
480 uint8_t oldLifeTime =
lifeTime[index];
496 uint8_t oldLifeTime =
lifeTime[index];
498 onSet(index,
buffer[index], oldLifeTime, row, rawLifeTime_);
499 if (oldLifeTime !=
lifeTime[index]) {
504 if (rawLifeTime_ == 0) {
506 if constexpr (has_clear<RowT,
void(RowT::*)()>::value) {
515 if constexpr (has_printRowForChangeLog<RowT, std::string(RowT::*)()
const>::value) {
516 NotifyTableChangeBegin(MST_SET) << (int)index <<
"|" <<
buffer[index].printRowForChangeLog() <<
"|" << (int)
lifeTime[index];
519 NotifyTableChangeBegin(MST_SET) << (int)index <<
"|" <<
buffer[index] <<
"|" << (
int)
lifeTime[index];
521 NotifyTableChangeEnd();
547 if (index < realUsedSize && index >= 0) {
557 uint8_t oldLifeTime =
lifeTime[index];
563 if constexpr (has_printRowForChangeLog<RowT, std::string(RowT::*)()
const>::value) {
564 NotifyTableChangeBegin(MST_REMOVE) << (int)index <<
"|" <<
buffer[index].printRowForChangeLog() <<
"|" << (int)
lifeTime[index];
567 NotifyTableChangeBegin(MST_REMOVE) << (int)index <<
"|" <<
buffer[index] <<
"|" << (
int)
lifeTime[index];
569 NotifyTableChangeEnd();
574 if constexpr (has_clear<RowT,
void(RowT::*)()>::value) {
589 NotifyTableChangeBegin(MST_CLEAR);
590 NotifyTableChangeEnd();
593 for (int16_t i = 0; i < RowsCount; i++) {
596 if constexpr (has_clear<RowT,
void(RowT::*)()>::value) {
612 uint32_t sysTime = millis();
618 uint32_t mil = sysTime;
639 if constexpr (has_clear<RowT,
void(RowT::*)()>::value) {
644 if constexpr (has_printRowForChangeLog<RowT, std::string(RowT::*)()
const>::value) {
645 NotifyTableChangeBegin(MST_REMOVE_VLD) << (int)i <<
"|" <<
buffer[i].printRowForChangeLog() <<
"|" << (int)
lifeTime[i];
648 NotifyTableChangeBegin(MST_REMOVE_VLD) << (int)i <<
"|" <<
buffer[i] <<
"|" << (
int)
lifeTime[i];
650 NotifyTableChangeEnd();
674 if (index < realUsedSize && index >= 0 && !
isRowBlank(index) && rawLifeTime_ > 0) {
677 if (old != rawLifeTime_) {
681 NotifyTableChangeBegin(MST_PROLONG) << (int)index <<
"|" << (
int)
lifeTime[index];
682 NotifyTableChangeEnd();
709 if (
count() == RowsCount || startPos >= RowsCount)
return -1;
712 int16_t i = startPos;
713 for (; i < RowsCount &&
lifeTime[i] != 0; i++);
722 uint8_t oldestLifeTime = 255;
740 inline bool exists(int16_t index)
const {
798 template <class = typename std::enable_if<!IndexIsValue>::type> uint8_t
getFragmentation()
const{
808 template <class = typename std::enable_if<!IndexIsValue>::type>
void defragment() {
810 int16_t writePos = 0;
814 for (int16_t readPos = 1; readPos <
realUsedSize; readPos++) {
816 for (; writePos < readPos &&
lifeTime[writePos] != 0; writePos++);
824 if constexpr (has_clear<RowT,
void(RowT::*)()>::value) {
833 NotifyTableChangeBegin(MST_DEFRAG);
834 NotifyTableChangeEnd();
844 if (index < realUsedSize && index >= 0 && !
isRowBlank(index)) {
847 if (rawVal <= timeDifference) {
852 return rawVal - timeDifference;
864 if (index < realUsedSize && index >= 0) {
884 return ((value > 255) ? 255 : value);
931 crc.setInputReverse(
true);
932 crc.setOutputReverse(
true);
933 crc.setPolynomial32();
934 crc.reset(0xFFFFFFFFUL);
937 ret = stream.print(tableIdentifier);
938 ret = stream.print(
':');
944 int16_t row_cnt = RowsCount;
945 ret += stream.write((uint8_t*)&row_cnt, 2);
946 crc.append((uint8_t*)&row_cnt, 2);
948 ret += stream.write((uint8_t*)&
RowLife, 4);
949 crc.append((uint8_t*)&
RowLife, 4);
951 WTB elapsedTimeFromLastValidation;
953 ret += stream.write(elapsedTimeFromLastValidation.buffer, 4);
954 crc.append(elapsedTimeFromLastValidation.buffer, 4);
959 uint16_t sentCnt = 0;
962 ret += stream.write((uint8_t*)&i, 2);
963 crc.append((uint8_t*)&i, 2);
965 ret += stream.write((uint8_t*)&
buffer[i],
sizeof(RowT));
966 crc.append((uint8_t*)&
buffer[i],
sizeof(RowT));
978 uint32_t CRC_val = crc.getLastCRC(0xFFFFFFFFUL);
979 ret += stream.write((uint8_t*)&CRC_val, 4);
994 size_t print(
OSTREAM& stream,
bool showIndexes =
true,
bool doNotPrintBlank =
true,
bool showRemainingRowLifetime =
true)
const {
996 if (showIndexes) ret += stream.print(
"Index|");
997 if constexpr (has_printHeader<RowT,
size_t(*)(
OSTREAM&)>::value) {
998 ret += RowT::printHeader(stream);
1001 ret += stream.print(
"Value");
1003 if (showRemainingRowLifetime) ret += stream.print(
"|Remaining life time");
1005 size_t dashCnt = ret;
1006 ret += stream.println();
1007 for(
size_t i = 0; i < dashCnt; i++) ret += stream.print(
'-');
1008 ret += stream.println();
1011 ret += stream.println(
"Empty");
1015 if (!(doNotPrintBlank &&
lifeTime[i] == 0)) {
1017 char txtBuffer[10] = { 0 };
1018 ITOA(i, txtBuffer,
sizeof(txtBuffer) /
sizeof(
char), 10);
1020 ret += stream.print(txtBuffer);
1021 ret += stream.print(
'|');
1023 if constexpr (has_printRow<RowT,
size_t(RowT::*)(
OSTREAM&)
const>::value && !IndexIsValue) {
1024 ret +=
buffer[i].printRow(stream);
1026 else if constexpr (has_printRow<RowT,
size_t(RowT::*)(
OSTREAM&, int16_t)
const>::value && IndexIsValue) {
1027 ret +=
buffer[i].printRow(stream, i);
1030 ret += stream.print(
buffer[i]);
1032 if (showRemainingRowLifetime) {
1033 ret += stream.print(
'|');
1035 char txtBuffer[3] = { 0 };
1036 ret += stream.print(
" ");
1037 uint8_t sec = remLifeTime % 60;
1039 uint8_t min = remLifeTime % 60;
1041 uint8_t hrs = remLifeTime % 24;
1045 ITOA(remLifeTime, txtBuffer,
sizeof(txtBuffer) /
sizeof(
char), 10);
1047 ret += stream.print(txtBuffer);
1048 ret += stream.print(
"d ");
1051 ITOA(hrs, txtBuffer,
sizeof(txtBuffer) /
sizeof(
char), 10);
1053 ret += stream.print(txtBuffer);
1054 ret += stream.print(
':');
1057 ITOA(min, txtBuffer,
sizeof(txtBuffer) /
sizeof(
char), 10);
1059 ret += stream.print(txtBuffer);
1060 ret += stream.print(
':');
1063 ITOA(sec, txtBuffer,
sizeof(txtBuffer) /
sizeof(
char), 10);
1065 ret += stream.print(txtBuffer);
1068 ret += stream.print(
" ");
1070 ret += stream.println();
1096 virtual void onCreate(int16_t index,
const RowT& newValue, uint8_t newRawLifeTime) {}
1107 virtual void onSet(int16_t index,
const RowT& oldValue, uint8_t oldRawLifeTime,
const RowT& newValue, uint8_t newRawLifeTime) {}
1117 virtual void onRemove(int16_t index,
const RowT& oldValue, uint8_t oldRawLifeTime,
bool removedByValidation =
false) {}
1167 template <
int16_t BufferSize>
1169 public MicroTable<MeshMACTableRow, BufferSize>
1230 if (startPos < 0)
return false;
1231 for (int16_t i = startPos; i < MicroTable<MeshMACTableRow, BufferSize>::realUsedSize; i++) {
1292 onValidityChangeCallback = callback;
1299 bool removed = new_raw == 0;
1301 bool old_removed = old_raw == 0;
1302 if (onValidityChangeCallback != NULL && (valid != old_valid || removed != old_removed)) {
1328 template <
int16_t BufferSize>
1330 public MicroTable<MeshRouteTableRow, BufferSize>
1355 bool set(int16_t index, uint8_t source, uint8_t neighbor, uint8_t hop, int16_t valid = -1) {
1370 int16_t
set(uint8_t source, uint8_t neighbor, uint8_t hop, int16_t valid = -1) {
1418 inline bool add(uint8_t source, uint8_t neighbor, uint8_t hop) {
1482 int16_t removedCnt = 0;
1483 for (int16_t i = 0; i < MicroTable<MeshRouteTableRow, BufferSize>::realUsedSize; i++) {
1498 int16_t removedCnt = 0;
1499 for (int16_t i = 0; i < MicroTable<MeshRouteTableRow, BufferSize>::realUsedSize; i++) {
1523 for (int16_t i = 0; i < MicroTable<MeshRouteTableRow, BufferSize>::realUsedSize; i++) {
1538 for (int16_t i = 0; i < MicroTable<MeshRouteTableRow, BufferSize>::realUsedSize; i++) {
1553 for (int16_t i = 0; i < MicroTable<MeshRouteTableRow, BufferSize>::realUsedSize; i++) {
1596 onNewCallback = callback;
1612 if (onNewCallback != NULL) {
1613 onNewCallback(
this, index, newValue, newRawLifeTime);
1656 uint8_t oldestLifeTime = 255;
1658 for (int16_t i = 0; i < MicroTable<MeshRouteTableRow, BufferSize>::realUsedSize; i++) {
1690 template <
int16_t BufferSize>
1692 public MicroTable<MeshIDTableRow, BufferSize>
1714 bool set(uint16_t index, uint8_t
id, uint8_t source, int16_t valid = -1) {
1725 bool add(uint8_t
id, uint8_t source) {
1728 return set(index,
id, source, 255);
1734 return set(index,
id, source, 255);
1738 return set(index,
id, source, 255);
1786 bool exists(uint8_t
id, uint8_t source)
const{
1808 template <
int16_t BufferSize>
1810 public MicroTable<MeshFIDTableRow, BufferSize>
1833 bool set(uint16_t index, uint8_t
id, uint8_t source,
MeshMAC bssid, int16_t valid = -1) {
1848 return set(index,
id, source, bssid, 255);
1854 return set(index,
id, source, bssid, 255);
1858 return set(index,
id, source, bssid, 255);
1940 template <
int16_t BufferSize>
1942 public MicroTable<MeshOIDTableRow, BufferSize>
1965 bool set(uint8_t index, uint8_t
id, uint8_t destination, SystemPacketType type, int16_t valid = -1) {
1978 bool add(uint8_t
id, uint8_t destination, SystemPacketType type, uint8_t rawLifeTime = 255) {
1981 return set(index,
id, destination, type, rawLifeTime);
1987 return set(index,
id, destination, type, rawLifeTime);
1991 return set(index,
id, destination, type, rawLifeTime);
2040 for (int16_t i = 0; i < MicroTable<MeshOIDTableRow, BufferSize>::realUsedSize; i++) {
2055 for (int16_t i = 0; i < MicroTable<MeshOIDTableRow, BufferSize>::realUsedSize; i++) {
2070 for (int16_t i = 0; i < MicroTable<MeshOIDTableRow, BufferSize>::realUsedSize; i++) {
2092 onRemoveCallback = callback;
2106 if (onRemoveCallback != NULL && oldValue.
ID != newValue.
ID) {
2107 onRemoveCallback(
this, index, oldValue, oldRawLifeTime,
OIDTR_Set);
2118 void onRemove(int16_t index,
const MeshOIDTableRow& oldValue, uint8_t oldRawLifeTime,
bool removedByValidation =
false)
override {
2119 if (onRemoveCallback != NULL) {
const uint32_t ValidationInterval
Definition: meshTables.h:1141
SystemPacketType Type
Type of system message.
Definition: meshTables.h:267
void onCreate(int16_t index, const MeshRouteTableRow &newValue, uint8_t newRawLifeTime) override
This method is called when valid row is set to blank space. It is called after count calculation is d...
Definition: meshTables.h:1608
Mesh MAC table, is lookup table for node address and MAC address. It acts as DHCP table....
Definition: meshTables.h:1168
virtual size_t printRaw(OSTREAM &stream, const char tableIdentifier[4]) const
Prints raw table data through stream. Those data can be decoded in PC or in another MCU.
Definition: meshTables.h:929
uint8_t Destination
Message destination. If set to UNKNOWN_MESH_ADDRESS (253), no destination is specified.
Definition: meshTables.h:261
uint8_t convertLifeTimeToRaw(uint32_t lifeTime) const
Converts life time in milliseconds to raw life time value. Value is rounded up.
Definition: meshTables.h:882
bool add(uint8_t id, uint8_t destination, SystemPacketType type, uint8_t rawLifeTime=255)
Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added....
Definition: meshTables.h:1978
#define ITOA
Definition: meshConfig.h:17
bool existsDestAndSysPacketType(uint8_t destination, SystemPacketType type) const
Checks if row with specified destination address and system packet type exists.
Definition: meshTables.h:2069
MeshMAC MAC
MAC address.
Definition: meshTables.h:32
const RowT & operator[](int16_t index) const
Gets row from table by index.
Definition: meshTables.h:405
Mesh route table contains all known routes. Source address column value has to be unique....
Definition: meshTables.h:1329
int16_t count() const
Gets number of used rows in buffer.
Definition: meshTables.h:774
Structure, that acts as one row in MeshFIDTable.
Definition: meshTables.h:193
virtual size_t getRawDataSize() const
Calculates, how many bytes will be printed, when using command printRaw.
Definition: meshTables.h:901
int16_t getIndexOfIDSourceAndBSSID(uint8_t id, uint8_t source, MeshMAC bssid) const
Gets index of row with specified ID and Source in table.
Definition: meshTables.h:1898
bool set(int16_t index, uint8_t source, uint8_t neighbor, uint8_t hop, int16_t valid=-1)
Sets row values in table.
Definition: meshTables.h:1355
@ T_RIGHT
Definition: meshHelper.h:118
bool set(uint16_t index, uint8_t id, uint8_t source, int16_t valid=-1)
Sets row values in table.
Definition: meshTables.h:1714
Structure, that contains one row with data from out ID table.
Definition: meshTables.h:249
virtual void onRowLifeChanged(int16_t index, uint8_t old_raw, uint8_t new_raw)
This method is called when table is cleared. It is called after cleaning is done, so all variables ar...
Definition: meshTables.h:1132
bool remove(const RowT &rowRef)
Removes first row, which is equal to rowRef.
Definition: meshTables.h:533
void onSet(int16_t index, const MeshOIDTableRow &oldValue, uint8_t oldRawLifeTime, const MeshOIDTableRow &newValue, uint8_t newRawLifeTime) override
This method is called when valid row is set to new value. It is called after count calculation is don...
Definition: meshTables.h:2105
uint8_t directNeighborCount
Definition: meshTables.h:1669
void setValidityChangeCallback(void(*callback)(MeshMACTable< BufferSize > *, int16_t, const MeshMACTableRow &, bool, bool))
Sets callback function, which is called when row validity has changed. There can be 3 states of valid...
Definition: meshTables.h:1291
bool operator==(const MeshRouteTableRow &another) const
Definition: meshTables.h:127
bool operator==(const MeshOIDTableRow &another) const
Definition: meshTables.h:292
bool isRowDirectNeighbor(int16_t index) const
Checks if row contains record of direct neighbor (source number and neighbor number are equal).
Definition: meshTables.h:1512
Mesh ID table stores IDs of transmitted messages, check status of sent messages. Size of table can be...
Definition: meshTables.h:1941
void clear()
Removes all rows data.
Definition: meshTables.h:586
virtual void onRemove(int16_t index, const RowT &oldValue, uint8_t oldRawLifeTime, bool removedByValidation=false)
This method is called when valid row is removed. It is called after count calculation is done,...
Definition: meshTables.h:1117
bool add(const MeshFIDTableRow &val)
Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added....
Definition: meshTables.h:1868
Structure, that contains one row with data from route table.
Definition: meshTables.h:70
size_t printRow(OSTREAM &stream) const
Definition: meshTables.cpp:101
MeshOIDTable(const uint32_t rowLife)
Constructor.
Definition: meshTables.h:1950
int16_t set(const MeshRouteTableRow &row, int16_t valid=-1)
Sets row values in table. Row index is established using getIndexOfSource() method....
Definition: meshTables.h:1394
bool add(uint8_t id, uint8_t source)
Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added....
Definition: meshTables.h:1725
bool setRawRemainingLifeTime(int16_t index, uint8_t rawLifeTime_=255)
Sets row life time. Valid counter for this rowcan be changed, only when row is still valid.
Definition: meshTables.h:673
uint8_t ID
ID of message.
Definition: meshTables.h:201
bool set(int16_t index, const RowT &row)
Sets row values in table. Row life time is set to maximum.
Definition: meshTables.h:424
@ OIDTR_Removed
Definition: meshTables.h:1917
int16_t removeByNeighbor(uint8_t neighbor)
Removes all rows with specified neighbor address.
Definition: meshTables.h:1481
bool existsID(uint8_t id) const
Checks if row with specified ID exists in table.
Definition: meshTables.h:2054
void validate()
Decreases all valid column values in specified interval (row lifetime). If valid value is 0,...
Definition: meshTables.h:611
void clear()
Removes all data from current row.
Definition: meshTables.h:214
int16_t usedBufferSize
Definition: meshTables.h:1139
uint8_t Hop
Number of hops from current node to Source.
Definition: meshTables.h:86
bool add(const MeshIDTableRow &val)
Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added....
Definition: meshTables.h:1748
bool isGateway() const
Checks if row is route to gateway node.
Definition: meshTables.h:100
@ OIDTR_Set
Definition: meshTables.h:1918
uint8_t lifeTime[RowsCount]
Definition: meshTables.h:1136
bool exists(const RowT &rowRef) const
Checks if any row, which is equal to rowRef exists in table.
Definition: meshTables.h:749
bool set(uint8_t address, MeshMAC MAC, int16_t valid=-1)
Sets row values in table.
Definition: meshTables.h:1188
RowT buffer[RowsCount]
Definition: meshTables.h:1135
bool addressExists(uint8_t address) const
Checks if node address exists in table.
Definition: meshTables.h:1258
MeshRouteTableRow()=default
Mesh foreign packet's ID table stores IDs of received packets from another network,...
Definition: meshTables.h:1809
#define DHCPTABLE_ROW_RAW_LIFETIME_RESERVED
Definition: meshConfig.h:147
MeshRouteTable(const uint32_t rowLife)
Constructor.
Definition: meshTables.h:1338
bool add(uint8_t id, uint8_t source, MeshMAC bssid)
Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added....
Definition: meshTables.h:1845
bool add(uint8_t source, uint8_t neighbor, uint8_t hop)
Adds or overwrites data in row. This method works slightly different, because it implements part of m...
Definition: meshTables.h:1418
void onClear() override
This method is called when table is cleared. It is called after cleaning is done, so all variables ar...
Definition: meshTables.h:1647
int16_t realUsedSize
Definition: meshTables.h:1140
RowT get(int16_t index)
Gets row from table by index.
Definition: meshTables.h:396
int16_t getFirstBlankRowIndex(int16_t startPos=0) const
Gets index of first blank row.
Definition: meshTables.h:708
uint32_t getRowRemainingLifeTime(int16_t index) const
Gets selected row's remaining life time in milliseconds.
Definition: meshTables.h:843
uint8_t Neighbor
Neighbor node address, that is connected (directly/indirectly) to source node.
Definition: meshTables.h:82
void alignText(char *text, int size, char fill, TextAlignment alignment)
Aligns text in char array.
Definition: meshHelper.cpp:97
uint8_t ID
ID of message.
Definition: meshTables.h:257
void clear()
Removes all data from current row.
Definition: meshTables.h:37
Structure, that acts as one row in MeshIDTable.
Definition: meshTables.h:142
bool exists(uint8_t id, uint8_t source, MeshMAC bssid) const
Checks if row with specified ID and Source exists in table.
Definition: meshTables.h:1909
bool add(const MeshOIDTableRow &val, uint8_t rawLifeTime=255)
Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added....
Definition: meshTables.h:2002
bool set(int16_t index, const RowT &row, int16_t rawLifeTime_)
Sets row values in table.
Definition: meshTables.h:465
uint8_t getFragmentation() const
Calculates fragmentation in %. Fragmentation is calculated like this: (getRealUsedSize() - count())/g...
Definition: meshTables.h:798
uint32_t convertRawToLifeTime(uint8_t rawLifeTime) const
Converts raw life time value to life time in milliseconds. Value is aproximate. To get accurate resul...
Definition: meshTables.h:893
static size_t printHeader(OSTREAM &stream)
Print header for table of rows.
Definition: meshTables.cpp:131
uint8_t getDirectNeighborCount() const
Gets number direct neighbors in buffer.
Definition: meshTables.h:1581
bool removeID(uint8_t ID)
Removes row data by ID.
Definition: meshTables.h:2011
This file contains class which can be used to handling mesh packets.
bool exists(int16_t index) const
Checks if row at specified index exists in table.
Definition: meshTables.h:740
bool isDirectNeighbor() const
Checks if row is route to direct neighbor or not.
Definition: meshTables.h:92
@ T_LEFT
Definition: meshHelper.h:116
MeshFIDTableRow()=default
int16_t getIndexOfIDAndSource(uint8_t id, uint8_t source) const
Gets index of row with specified ID and Source in table.
Definition: meshTables.h:1776
bool sourceExists(uint8_t source) const
Checks if source node exists in table.
Definition: meshTables.h:1521
static size_t printHeader(OSTREAM &stream)
Print header for table of rows.
Definition: meshTables.cpp:97
uint8_t getRawRowRemainingLifeTime(int16_t index) const
Gets selected row's raw remaining life time.
Definition: meshTables.h:863
bool remove(int16_t index)
Removes row at index.
Definition: meshTables.h:546
size_t printRow(OSTREAM &stream) const
Definition: meshTables.cpp:36
int16_t getFreeAddress(uint8_t startFrom=MESH_GATEWAY_MAX_ADDRESS+1)
Gets first available address.
Definition: meshTables.h:1274
size_t printRow(OSTREAM &stream) const
Definition: meshTables.cpp:73
uint8_t ID
ID of message.
Definition: meshTables.h:150
void setOnRemoveCallback(void(*callback)(MeshOIDTable< BufferSize > *, int16_t, const MeshOIDTableRow &, uint8_t, MeshOIDTableRemoveReason))
Sets callback function, which is called when any item is removed from this table. If table is cleared...
Definition: meshTables.h:2091
MeshOIDTableRow()=default
int16_t getIndexOfSource(uint8_t source) const
Gets index of source address.
Definition: meshTables.h:1552
virtual void onClear()
This method is called when table is cleared. It is called after cleaning is done, so all variables ar...
Definition: meshTables.h:1123
int16_t getAddressFromMAC(MeshMAC mac, int16_t startPos=0) const
Searches for node address, which is assinged to node MAC address.
Definition: meshTables.h:1229
HAS_MEM_FUNC(printRowForChangeLog, has_printRowForChangeLog)
size_t printRow(OSTREAM &stream) const
Definition: meshTables.cpp:18
void onRemove(int16_t index, const MeshOIDTableRow &oldValue, uint8_t oldRawLifeTime, bool removedByValidation=false) override
This method is called when valid row is removed. It is called after count calculation is done,...
Definition: meshTables.h:2118
bool removeByIDSourceAndBSSID(uint8_t ID, uint8_t source, MeshMAC bssid)
Removes row data by source and ID.
Definition: meshTables.h:1883
virtual void onCreate(int16_t index, const RowT &newValue, uint8_t newRawLifeTime)
This method is called when valid row is set to blank space. It is called after count calculation is d...
Definition: meshTables.h:1096
static size_t printHeader(OSTREAM &stream)
Print header for table of rows.
Definition: meshTables.cpp:32
void setNewCallback(void(*callback)(MeshRouteTable< BufferSize > *, int16_t, const MeshRouteTableRow &, uint8_t))
Sets callback function, which is called when new record was inserted to table. This callback is not c...
Definition: meshTables.h:1595
#define OSTREAM
Definition: meshConfig.h:41
virtual int16_t getIndexOf(const RowT &rowRef) const
Gets index of row which is equal to rowRef.
Definition: meshTables.h:694
int16_t size() const
Gets capacity of table in rows.
Definition: meshTables.h:766
typedef SPT_DATA
Definition: meshPacket.h:32
void defragment()
Removes blank spaces between rows. Call this to speed up searching when buffer is fragmented.
Definition: meshTables.h:808
void clear()
Removes all data from current row.
Definition: meshTables.h:272
void operator+=(const MeshRouteTableRow &val)
Definition: meshTables.h:1461
size_t printTo(Print &p) const override
Makes this class printable.
Definition: meshTables.h:1082
void operator+=(const MeshFIDTableRow &val)
Definition: meshTables.h:1872
bool exists(uint8_t id, uint8_t source) const
Checks if row with specified ID and Source exists in table.
Definition: meshTables.h:1786
MeshIDTable(const uint32_t rowLife)
Constructor.
Definition: meshTables.h:1701
Mesh ID table stores IDs of received packets, to prevent receiving same packet multiple times....
Definition: meshTables.h:1691
RowT operator[](int16_t index)
Gets row from table by index.
Definition: meshTables.h:414
bool operator==(const MeshMACTableRow &another) const
Definition: meshTables.h:55
void onRemove(int16_t index, const MeshRouteTableRow &oldValue, uint8_t oldRawLifeTime, bool removedByValidation=false) override
This method is called when valid row is set to new value. It is called after count calculation is don...
Definition: meshTables.h:1637
void clear()
Removes all data from current row.
Definition: meshTables.h:159
int16_t getOldestRowIndexNotGW() const
Gets index of first oldest row, except gateway nodes.
Definition: meshTables.h:1655
int16_t getRealUsedSize() const
Gets real used count of rows in table. This value is calculated like this: last_used_row_index + 1.
Definition: meshTables.h:790
uint32_t getLifeTimeResolution() const
Gets life time resolution in milliseconds.
Definition: meshTables.h:873
Structure that represents physical MAC address used in MeshNEt protocol. MeshMAC address unlike MAC a...
Definition: meshHelper.h:207
bool MACExists(MeshMAC mac) const
Checks if node MAC address exists in table.
Definition: meshTables.h:1265
MicroTable(const uint32_t rowLife)
Constructor.
Definition: meshTables.h:375
bool operator==(const MeshFIDTableRow &another) const
Definition: meshTables.h:234
virtual void onSet(int16_t index, const RowT &oldValue, uint8_t oldRawLifeTime, const RowT &newValue, uint8_t newRawLifeTime)
This method is called when valid row is set to new value. It is called after count calculation is don...
Definition: meshTables.h:1107
int16_t set(uint8_t source, uint8_t neighbor, uint8_t hop, int16_t valid=-1)
Sets row values in table. Row index is established using getIndexOfSource() method....
Definition: meshTables.h:1370
const RowT & get(int16_t index) const
Gets row from table by index.
Definition: meshTables.h:387
bool removeBySource(uint8_t source)
Removes row, which contains specified source address.
Definition: meshTables.h:1470
int16_t getIndexOfID(uint8_t id) const
Gets index of row with specified ID in table.
Definition: meshTables.h:2039
int16_t getOldestRowIndex() const
Gets index of first oldest row.
Definition: meshTables.h:721
MeshMACTable(const uint32_t rowLife)
Constructor.
Definition: meshTables.h:1176
size_t printRow(OSTREAM &stream) const
Definition: meshTables.cpp:135
bool neighborExists(uint8_t neighbor) const
Checks if neighbor node exists in table.
Definition: meshTables.h:1536
uint32_t lastValidationTime
Definition: meshTables.h:1138
bool operator==(const MeshIDTableRow &another) const
Definition: meshTables.h:178
void operator+=(const MeshIDTableRow &val)
Definition: meshTables.h:1752
Structure, that contains one row with data from address to MAC lookup table. Designed for gateway nod...
Definition: meshTables.h:24
void clear()
Removes all data from current row.
Definition: meshTables.h:107
size_t print(OSTREAM &stream, bool showIndexes=true, bool doNotPrintBlank=true, bool showRemainingRowLifetime=true) const
Prints items from table to stream.
Definition: meshTables.h:994
void onRowLifeChanged(int16_t index, uint8_t old_raw, uint8_t new_raw) override
This method is called when table is cleared. It is called after cleaning is done, so all variables ar...
Definition: meshTables.h:1297
int16_t removeByDestination(uint8_t destination)
Removes row data by it's destination address.
Definition: meshTables.h:2024
uint8_t Source
Source node number.
Definition: meshTables.h:154
bool set(uint8_t index, uint8_t id, uint8_t destination, SystemPacketType type, int16_t valid=-1)
Sets row values in table.
Definition: meshTables.h:1965
bool isRowBlank(int16_t index) const
Checks if row is blank or not. Row, that is not valid is blank.
Definition: meshTables.h:758
@ OIDTR_Validation
Definition: meshTables.h:1919
static size_t printHeader(OSTREAM &stream)
Print header for table of rows.
Definition: meshTables.cpp:69
MeshOIDTableRemoveReason
Definition: meshTables.h:1916
MeshMACTableRow()=default
int16_t add(MeshMAC mac, bool isGateway=false)
Adds MAC address to table at first free index.
Definition: meshTables.h:1199
const uint32_t RowLife
Definition: meshTables.h:1142
bool add(const MeshRouteTableRow &val)
Adds or overwrites data in row. This method works slightly different as basic add method,...
Definition: meshTables.h:1431
int16_t removeByAddress(uint8_t address)
Removes all rows which contains specified address in "Source" or "Neighbor" field.
Definition: meshTables.h:1497
MeshFIDTable(const uint32_t rowLife)
Constructor.
Definition: meshTables.h:1819
uint8_t Source
Source address.
Definition: meshTables.h:78
int16_t getNeighborFromSource(int8_t source) const
Gets neighbor, which is connected (directly or indirectly) with source node.
Definition: meshTables.h:1566
MeshMAC getMACFromAddress(uint8_t address) const
Gets node MAC address assigned to node address.
Definition: meshTables.h:1246
uint8_t Source
Source node number.
Definition: meshTables.h:205
static size_t printHeader(OSTREAM &stream)
Print header for table of rows.
Definition: meshTables.cpp:14
#define MESH_GATEWAY_MAX_ADDRESS
Maximum address, which is reserved for gateway. Defaultly addressed 0,1,2 are reserved for gateway an...
Definition: meshConfig.h:69
MeshMAC BSSID
BSSID of network.
Definition: meshTables.h:209
This class emulates table storage. This table is created without dynamic allocation....
Definition: meshTables.h:351
uint8_t getMaxRowLifeTime() const
Gets the maximum row life time in millisseconds.
Definition: meshTables.h:782
bool set(uint16_t index, uint8_t id, uint8_t source, MeshMAC bssid, int16_t valid=-1)
Sets row values in table.
Definition: meshTables.h:1833
bool removeByIDAndSource(uint8_t ID, uint8_t source)
Removes row data by source and ID.
Definition: meshTables.h:1762