MeshNet  1.0.0
Public Member Functions | Protected Member Functions
MeshOIDTable< BufferSize > Class Template Reference

Mesh ID table stores IDs of transmitted messages, check status of sent messages. Size of table can be defined using template like this: More...

#include <meshTables.h>

Inheritance diagram for MeshOIDTable< BufferSize >:
Inheritance graph
[legend]
Collaboration diagram for MeshOIDTable< BufferSize >:
Collaboration graph
[legend]

Public Member Functions

 MeshOIDTable (const uint32_t rowLife)
 Constructor. More...
 
bool set (uint8_t index, uint8_t id, uint8_t destination, SystemPacketType type, int16_t valid=-1)
 Sets row values in table. More...
 
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. If buffer is full, oldest row will be overwritten. More...
 
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. If buffer is full, oldest row will be overwritten. More...
 
bool removeID (uint8_t ID)
 Removes row data by ID. More...
 
int16_t removeByDestination (uint8_t destination)
 Removes row data by it's destination address. More...
 
int16_t getIndexOfID (uint8_t id) const
 Gets index of row with specified ID in table. More...
 
bool existsID (uint8_t id) const
 Checks if row with specified ID exists in table. More...
 
bool existsDestAndSysPacketType (uint8_t destination, SystemPacketType type) const
 Checks if row with specified destination address and system packet type exists. More...
 
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, this callback function is not called. More...
 
- Public Member Functions inherited from MicroTable< MeshOIDTableRow, BufferSize >
 MicroTable (const uint32_t rowLife)
 Constructor. More...
 
const MeshOIDTableRowget (int16_t index) const
 Gets row from table by index. More...
 
MeshOIDTableRow get (int16_t index)
 Gets row from table by index. More...
 
const MeshOIDTableRowoperator[] (int16_t index) const
 Gets row from table by index. More...
 
MeshOIDTableRow operator[] (int16_t index)
 Gets row from table by index. More...
 
bool set (int16_t index, const MeshOIDTableRow &row)
 Sets row values in table. Row life time is set to maximum. More...
 
bool set (int16_t index, const MeshOIDTableRow &row, int16_t rawLifeTime_)
 Sets row values in table. More...
 
bool remove (const MeshOIDTableRow &rowRef)
 Removes first row, which is equal to rowRef. More...
 
bool remove (int16_t index)
 Removes row at index. More...
 
void clear ()
 Removes all rows data. More...
 
void validate ()
 Decreases all valid column values in specified interval (row lifetime). If valid value is 0, row will not be longer valid. More...
 
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. More...
 
virtual int16_t getIndexOf (const MeshOIDTableRow &rowRef) const
 Gets index of row which is equal to rowRef. More...
 
int16_t getFirstBlankRowIndex (int16_t startPos=0) const
 Gets index of first blank row. More...
 
int16_t getOldestRowIndex () const
 Gets index of first oldest row. More...
 
bool exists (int16_t index) const
 Checks if row at specified index exists in table. More...
 
bool exists (const MeshOIDTableRow &rowRef) const
 Checks if any row, which is equal to rowRef exists in table. More...
 
bool isRowBlank (int16_t index) const
 Checks if row is blank or not. Row, that is not valid is blank. More...
 
int16_t size () const
 Gets capacity of table in rows. More...
 
int16_t count () const
 Gets number of used rows in buffer. More...
 
uint8_t getMaxRowLifeTime () const
 Gets the maximum row life time in millisseconds. More...
 
int16_t getRealUsedSize () const
 Gets real used count of rows in table. This value is calculated like this: last_used_row_index + 1. More...
 
uint8_t getFragmentation () const
 Calculates fragmentation in %. Fragmentation is calculated like this: (getRealUsedSize() - count())/getRealUsedSize() More...
 
void defragment ()
 Removes blank spaces between rows. Call this to speed up searching when buffer is fragmented. More...
 
uint32_t getRowRemainingLifeTime (int16_t index) const
 Gets selected row's remaining life time in milliseconds. More...
 
uint8_t getRawRowRemainingLifeTime (int16_t index) const
 Gets selected row's raw remaining life time. More...
 
uint32_t getLifeTimeResolution () const
 Gets life time resolution in milliseconds. More...
 
uint8_t convertLifeTimeToRaw (uint32_t lifeTime) const
 Converts life time in milliseconds to raw life time value. Value is rounded up. More...
 
uint32_t convertRawToLifeTime (uint8_t rawLifeTime) const
 Converts raw life time value to life time in milliseconds. Value is aproximate. To get accurate result, use getRowRemainingLifeTime() method. More...
 
virtual size_t getRawDataSize () const
 Calculates, how many bytes will be printed, when using command printRaw. More...
 
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. More...
 
size_t print (OSTREAM &stream, bool showIndexes=true, bool doNotPrintBlank=true, bool showRemainingRowLifetime=true) const
 Prints items from table to stream. More...
 
size_t printTo (Print &p) const override
 Makes this class printable. More...
 

Protected Member Functions

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 done, but before buffer is updated. More...
 
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, but before buffer is updated. More...
 
- Protected Member Functions inherited from MicroTable< MeshOIDTableRow, BufferSize >
virtual void onCreate (int16_t index, const MeshOIDTableRow &newValue, uint8_t newRawLifeTime)
 This method is called when valid row is set to blank space. It is called after count calculation is done, but before buffer is updated. More...
 
virtual void onClear ()
 This method is called when table is cleared. It is called after cleaning is done, so all variables are fresh. More...
 
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 are fresh. More...
 

Additional Inherited Members

- Protected Attributes inherited from MicroTable< MeshOIDTableRow, BufferSize >
MeshOIDTableRow buffer [RowsCount]
 
uint8_t lifeTime [RowsCount]
 
uint32_t lastValidationTime
 
int16_t usedBufferSize
 
int16_t realUsedSize
 
const uint32_t ValidationInterval
 
const uint32_t RowLife
 

Detailed Description

template<int16_t BufferSize>
class MeshOIDTable< BufferSize >

Mesh ID table stores IDs of transmitted messages, check status of sent messages. Size of table can be defined using template like this:

MeshOIDTable<255> OIDTable(60000);

Size of ID table in this example is 255 rows and lifetime of one row is 60 seconds.

How data are stored:

index (not physically stored) ID [uint8_t] Destination [uint8_t] Type [SystemPacketType] Valid [uint8_t]
0 XXX XXX XXX XXX
1 XXX XXX XXX XXX
... ... ... ... ...
XXX - depends on BufferSize XXX XXX XXX XXX
Note
SystemPacketType can contain type ACK and ACK_ERR, which cannot be used here. If you set SystemPacketType to 0, it means, that data was sent.

Constructor & Destructor Documentation

◆ MeshOIDTable()

template<int16_t BufferSize>
MeshOIDTable< BufferSize >::MeshOIDTable ( const uint32_t  rowLife)
inline

Constructor.

Parameters
rowLifeLife time of each row in milliseconds. Value has to be higher than 0, but it is recommended to set value to higher than 100 seconds.

Member Function Documentation

◆ add() [1/2]

template<int16_t BufferSize>
bool MeshOIDTable< BufferSize >::add ( const MeshOIDTableRow val,
uint8_t  rawLifeTime = 255 
)
inline

Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added. If buffer is full, oldest row will be overwritten.

Parameters
rowRow with values, that will be added to specified row. (Valid property is ignored and is set to 255)
rawLifeTimeRaw life time value to set.
Returns
Returns when row was added or overwrote.

◆ add() [2/2]

template<int16_t BufferSize>
bool MeshOIDTable< BufferSize >::add ( uint8_t  id,
uint8_t  destination,
SystemPacketType  type,
uint8_t  rawLifeTime = 255 
)
inline

Adds or overwrites data in row. If row already exists, it will be overwritten, else new row is added. If buffer is full, oldest row will be overwritten.

Parameters
idID of message.
destinationDestination of message.
typeSystem packet type.
rawLifeTimeRaw life time value to set.
Returns
Returns when row was added or overwrote.

◆ existsDestAndSysPacketType()

template<int16_t BufferSize>
bool MeshOIDTable< BufferSize >::existsDestAndSysPacketType ( uint8_t  destination,
SystemPacketType  type 
) const
inline

Checks if row with specified destination address and system packet type exists.

Parameters
destinationDestination address.
typeSystem packet type.
Returns
Returns true when row with specified destination and type exists.

◆ existsID()

template<int16_t BufferSize>
bool MeshOIDTable< BufferSize >::existsID ( uint8_t  id) const
inline

Checks if row with specified ID exists in table.

Parameters
idID to check.
Returns
Returns true when row with specified ID and Source exists in table.

◆ getIndexOfID()

template<int16_t BufferSize>
int16_t MeshOIDTable< BufferSize >::getIndexOfID ( uint8_t  id) const
inline

Gets index of row with specified ID in table.

Parameters
idID to look for.
Returns
Returns index of row with specified ID in table.

◆ onRemove()

template<int16_t BufferSize>
void MeshOIDTable< BufferSize >::onRemove ( int16_t  index,
const MeshOIDTableRow oldValue,
uint8_t  oldRawLifeTime,
bool  removedByValidation = false 
)
inlineoverrideprotectedvirtual

This method is called when valid row is removed. It is called after count calculation is done, but before buffer is updated.

Parameters
indexIndex of row.
oldValueReference to removed value.
oldRawLifeTimeOld raw life time value.

Reimplemented from MicroTable< MeshOIDTableRow, BufferSize >.

◆ onSet()

template<int16_t BufferSize>
void MeshOIDTable< BufferSize >::onSet ( int16_t  index,
const MeshOIDTableRow oldValue,
uint8_t  oldRawLifeTime,
const MeshOIDTableRow newValue,
uint8_t  newRawLifeTime 
)
inlineoverrideprotectedvirtual

This method is called when valid row is set to new value. It is called after count calculation is done, but before buffer is updated.

Parameters
indexIndex of row.
oldValueReference to old value at index.
oldRawLifeTimeOld raw life time value.
newValueReference to new value, to be inserted to row.
newRawLifeTimeNew raw life time value.

Reimplemented from MicroTable< MeshOIDTableRow, BufferSize >.

◆ removeByDestination()

template<int16_t BufferSize>
int16_t MeshOIDTable< BufferSize >::removeByDestination ( uint8_t  destination)
inline

Removes row data by it's destination address.

Parameters
destinationDestination to remove.
Returns
Returns count of removed rows.

◆ removeID()

template<int16_t BufferSize>
bool MeshOIDTable< BufferSize >::removeID ( uint8_t  ID)
inline

Removes row data by ID.

Parameters
IDID value of row to remove.
Returns
Returns true when row was removed.

◆ set()

template<int16_t BufferSize>
bool MeshOIDTable< BufferSize >::set ( uint8_t  index,
uint8_t  id,
uint8_t  destination,
SystemPacketType  type,
int16_t  valid = -1 
)
inline

Sets row values in table.

Parameters
indexIndex of row.
idID of message.
destinationDestination of message.
typeSystem packet type.
validSet this value to 255 to reset row lifetime. Set it to -1, to keep old value. Accepted value (0-255).
Returns
Returns true when row was set.

◆ setOnRemoveCallback()

template<int16_t BufferSize>
void MeshOIDTable< BufferSize >::setOnRemoveCallback ( void(*)(MeshOIDTable< BufferSize > *, int16_t, const MeshOIDTableRow &, uint8_t, MeshOIDTableRemoveReason callback)
inline

Sets callback function, which is called when any item is removed from this table. If table is cleared, this callback function is not called.

Parameters
callbackCallback function.

Callback function parameters

  • MeshOIDTable<BufferSize> - Pointer to table, which called this callback.
  • int16_t - Index of removed item.
  • MeshOIDTableRow - Removed row.
  • uint8_t - Old raw life time value.
  • MeshOIDTableRemoveReason - Remove reason.

The documentation for this class was generated from the following file:
MeshOIDTable
Mesh ID table stores IDs of transmitted messages, check status of sent messages. Size of table can be...
Definition: meshTables.h:1941