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

Mesh MAC table, is lookup table for node address and MAC address. It acts as DHCP table. Size of table can be defined using template like this: More...

#include <meshTables.h>

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

Public Member Functions

 MeshMACTable (const uint32_t rowLife)
 Constructor. More...
 
bool set (uint8_t address, MeshMAC MAC, int16_t valid=-1)
 Sets row values in table. More...
 
int16_t add (MeshMAC mac, bool isGateway=false)
 Adds MAC address to table at first free index. More...
 
int16_t getAddressFromMAC (MeshMAC mac, int16_t startPos=0) const
 Searches for node address, which is assinged to node MAC address. More...
 
MeshMAC getMACFromAddress (uint8_t address) const
 Gets node MAC address assigned to node address. More...
 
bool addressExists (uint8_t address) const
 Checks if node address exists in table. More...
 
bool MACExists (MeshMAC mac) const
 Checks if node MAC address exists in table. More...
 
int16_t getFreeAddress (uint8_t startFrom=MESH_GATEWAY_MAX_ADDRESS+1)
 Gets first available address. More...
 
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 validity: More...
 
- Public Member Functions inherited from MicroTable< MeshMACTableRow, BufferSize >
 MicroTable (const uint32_t rowLife)
 Constructor. More...
 
const MeshMACTableRowget (int16_t index) const
 Gets row from table by index. More...
 
MeshMACTableRow get (int16_t index)
 Gets row from table by index. More...
 
const MeshMACTableRowoperator[] (int16_t index) const
 Gets row from table by index. More...
 
MeshMACTableRow operator[] (int16_t index)
 Gets row from table by index. More...
 
bool set (int16_t index, const MeshMACTableRow &row)
 Sets row values in table. Row life time is set to maximum. More...
 
bool set (int16_t index, const MeshMACTableRow &row, int16_t rawLifeTime_)
 Sets row values in table. More...
 
bool remove (const MeshMACTableRow &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 MeshMACTableRow &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 MeshMACTableRow &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 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 are fresh. More...
 
- Protected Member Functions inherited from MicroTable< MeshMACTableRow, BufferSize >
virtual void onCreate (int16_t index, const MeshMACTableRow &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 onSet (int16_t index, const MeshMACTableRow &oldValue, uint8_t oldRawLifeTime, const MeshMACTableRow &newValue, uint8_t newRawLifeTime)
 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...
 
virtual void onRemove (int16_t index, const MeshMACTableRow &oldValue, uint8_t oldRawLifeTime, bool removedByValidation=false)
 This method is called when valid row is removed. 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...
 

Additional Inherited Members

- Protected Attributes inherited from MicroTable< MeshMACTableRow, BufferSize >
MeshMACTableRow 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 MeshMACTable< BufferSize >

Mesh MAC table, is lookup table for node address and MAC address. It acts as DHCP table. Size of table can be defined using template like this:

MeshMACTable<255> dhcpTable(60000);

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

Difference between Static and Dynamic mesh route table

How data are stored:

Node address - as index (not physically stored) Node MAC [MeshMAC] Valid [uint8_t]
0 XXX XXX
1 XXX XXX
... ... ...
x - depends on BufferSize XXX XXX

Constructor & Destructor Documentation

◆ MeshMACTable()

template<int16_t BufferSize>
MeshMACTable< BufferSize >::MeshMACTable ( 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()

template<int16_t BufferSize>
int16_t MeshMACTable< BufferSize >::add ( MeshMAC  mac,
bool  isGateway = false 
)
inline

Adds MAC address to table at first free index.

Parameters
macMAC address to add.
isGatewayTrue if gateway node is added. If set to false, minimum available address (index) starts at (MESH_GATEWAY_MAX_ADDRESS + 1), else it starts at 0.
Returns
Returns assigned address to MAC address or -1 if no free address was found.

◆ addressExists()

template<int16_t BufferSize>
bool MeshMACTable< BufferSize >::addressExists ( uint8_t  address) const
inline

Checks if node address exists in table.

◆ getAddressFromMAC()

template<int16_t BufferSize>
int16_t MeshMACTable< BufferSize >::getAddressFromMAC ( MeshMAC  mac,
int16_t  startPos = 0 
) const
inline

Searches for node address, which is assinged to node MAC address.

Note
One MAC address can contain multiple node addresses. To list them all call this method in loop until -1 is returned.
MeshMACTable<250> table(86400);
//Here comes some wotk with table (setting, removing, etc.)
const MeshMAC searchedMAC(0,0,0,1);
int16_t source = -1;
while(source = table.getAddressFromMAC(searchedMAC, source+1) >= 0){
cout << "Node address found: " << (int)source << endl;
}
Parameters
macMAC address of node, which addresses has to be found.
startPosIndex (address), where to start searching.
Returns
Returns address assigned to MAC address of node.

◆ getFreeAddress()

template<int16_t BufferSize>
int16_t MeshMACTable< BufferSize >::getFreeAddress ( uint8_t  startFrom = MESH_GATEWAY_MAX_ADDRESS + 1)
inline

Gets first available address.

Parameters
startFromMinimum address, where to start searching from.
Returns
Returns first available address or -1 when no available address exists.

◆ getMACFromAddress()

template<int16_t BufferSize>
MeshMAC MeshMACTable< BufferSize >::getMACFromAddress ( uint8_t  address) const
inline

Gets node MAC address assigned to node address.

Note
Only one node MAC address can be assigned to one node address, but multiple node addresses can be assigned to one node MAC address.
Parameters
addressAddress of node.
Returns
Returns MAC address assigned to node address or invalid MeshMAC struct if no MAC was found.

◆ MACExists()

template<int16_t BufferSize>
bool MeshMACTable< BufferSize >::MACExists ( MeshMAC  mac) const
inline

Checks if node MAC address exists in table.

◆ onRowLifeChanged()

template<int16_t BufferSize>
void MeshMACTable< BufferSize >::onRowLifeChanged ( int16_t  index,
uint8_t  old_raw,
uint8_t  new_raw 
)
inlineoverrideprotectedvirtual

This method is called when table is cleared. It is called after cleaning is done, so all variables are fresh.

Parameters
indexIndex of changed row.
old_rawOld raw life time value (0-255).
new_rawNew raw life time value (0-255).

Reimplemented from MicroTable< MeshMACTableRow, BufferSize >.

◆ set()

template<int16_t BufferSize>
bool MeshMACTable< BufferSize >::set ( uint8_t  address,
MeshMAC  MAC,
int16_t  valid = -1 
)
inline

Sets row values in table.

Parameters
addressVariable address of node.
MACPhysical MAC address of node.
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.

◆ setValidityChangeCallback()

template<int16_t BufferSize>
void MeshMACTable< BufferSize >::setValidityChangeCallback ( void(*)(MeshMACTable< BufferSize > *, int16_t, const MeshMACTableRow &, bool, bool)  callback)
inline

Sets callback function, which is called when row validity has changed. There can be 3 states of validity:

  1. Valid (rawLifeTime > DHCPTABLE_ROW_RAW_LIFETIME_RESERVED): valid = true, removed = false
  2. Invalid (rawLifeTime <= DHCPTABLE_ROW_RAW_LIFETIME_RESERVED && rawLifeTime > 0): valid = false, removed = false
  3. Blank (rawLifeTime == 0) valid = false, removed = true
    Parameters
    callbackCallback function.

Callback function parameters

  • MeshRouteTable<BufferSize> Pointer to table which called this callback
  • int16_t - Index of item.
  • MeshMACTableRow - Affected row.
  • bool - True if row is valid.
  • bool - True if row is removed.

The documentation for this class was generated from the following file:
MeshMACTable
Mesh MAC table, is lookup table for node address and MAC address. It acts as DHCP table....
Definition: meshTables.h:1168
MeshMAC
Structure that represents physical MAC address used in MeshNEt protocol. MeshMAC address unlike MAC a...
Definition: meshHelper.h:207