MeshNet  1.0.0
Public Member Functions | Protected Attributes
MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize > Class Template Reference

Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure. This class contains 2 FIFO buffers, first for high priority (routed packet), second for low priority (flood packet). Size of each inner FIFO can be specified in template. Template parameters are: More...

#include <meshBuffers.h>

Inheritance diagram for MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >:
Inheritance graph
[legend]
Collaboration diagram for MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >:
Collaboration graph
[legend]

Public Member Functions

const MeshPacketfront () const
 Gets the first (oldest with the highest priority) item from the buffer. More...
 
MeshPacketfront ()
 Gets the first (oldest with the highest priority) item from the buffer. More...
 
const MeshPacketback () const
 Gets the last (newest with the lowest priority) item from the buffer. More...
 
MeshPacketback ()
 Gets the last (newest with the lowest priority) item from the buffer. More...
 
bool get (MeshPacket &item, uint8_t index) const
 Gets item from the buffer by index. More...
 
const MeshPacketoperator[] (int index) const
 Gets item from the buffer by index. More...
 
MeshPacketoperator[] (int index)
 Gets item from the buffer by index. More...
 
void push (MeshPacket const &item)
 Pushes item after last item in buffer. When buffer is full, first (oldest with the highest priority) item will be overwritten and lostItemsCount() will be incremented by 1. More...
 
void push (MeshPacket &&item)
 Pushes item after last item in buffer. When buffer is full, first (oldest with the highest priority) item will be overwritten and lostItemsCount() will be incremented by 1. More...
 
MeshPacket && popMove ()
 Reads and removes first (oldest with the highest priority) item from the buffer. When buffer is empty, exception may be thrown. More...
 
bool pop ()
 Removes first (oldest with the highest priority) item from the buffer. More...
 
bool removeAt (uint8_t index)
 Removes item at specified index. After removing, count() will return new value. More...
 
uint8_t removeMulti (uint8_t startPos, uint8_t itmCount)
 Removes number of item from specified index. After removing, count() will return new value. More...
 
uint8_t removeIf (bool(*dec)(const MeshPacket &))
 Removes specified items. More...
 
uint8_t removeByDestination (uint8_t destination)
 Removes all packets with specified destination. More...
 
bool existsID (uint8_t ID, uint8_t source) const
 Checks if there is packet in buffer with specified ID and source address, which creates unique packet identifier. More...
 
int16_t getIndexOfPacket (uint8_t ID, uint8_t source) const
 Gets index of packet from unique packet identifier, which consists from ID and packet source address. More...
 
bool empty () const
 Checks if buffer is empty. More...
 
uint8_t count () const
 Gets how many items are stored in buffer. More...
 
uint8_t highCount () const
 Gets how many items are stored in high priority buffer. More...
 
uint8_t lowCount () const
 Gets how many items are stored in low priority buffer. More...
 
uint8_t size () const
 Gets maximum count of items, that can be stored in buffer. More...
 
uint8_t highSize () const
 Gets maximum count of items, that can be stored in high priority buffer. More...
 
uint8_t lowSize () const
 Gets maximum count of items, that can be stored in low priority buffer. More...
 
uint8_t lostItemsCount () const
 
void restartLostItemsCounter ()
 Restarts lostItemsCount counter. More...
 
void clear ()
 Clears whole buffer. More...
 
MeshPacketFIFO< ROUTE_BufferSize > & highFIFO ()
 Gets reference to high priority FIFO. More...
 
const MeshPacketFIFO< ROUTE_BufferSize > & highFIFO () const
 Gets reference to high priority FIFO. More...
 
MeshPacketFIFO< ROUTE_BufferSize > & lowFIFO ()
 Gets reference to low priority FIFO. More...
 
const MeshPacketFIFO< ROUTE_BufferSize > & lowFIFO () const
 Gets reference to low priority FIFO. More...
 
size_t getRawDataSize () const
 Calculates, how many bytes will be printed, when using command printRaw. More...
 
virtual size_t printRaw (OSTREAM &stream, const char *customTag)
 Prints raw FIFO data through stream. Those data can be decoded in PC or in another MCU. More...
 
virtual size_t print (OSTREAM &stream, bool showIndexes=true) const
 Prints items as table from FIFO buffer to stream. More...
 
virtual size_t sizeOf () const
 Gets size of the whole FIFO in bytes. More...
 
size_t printTo (Print &p) const override
 Makes this class printable. More...
 

Protected Attributes

MeshPacketFIFO< ROUTE_BufferSize > routeBuffer
 
MeshPacketFIFO< FLOOD_BufferSize > floodBuffer
 

Detailed Description

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
class MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >

Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure. This class contains 2 FIFO buffers, first for high priority (routed packet), second for low priority (flood packet). Size of each inner FIFO can be specified in template. Template parameters are:

How data are stored:

index (not physically stored) MeshPacket
0 XXX
1 XXX
... ...
XXX - depends on BufferSize XXX

Member Function Documentation

◆ back() [1/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacket& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::back ( )
inline

Gets the last (newest with the lowest priority) item from the buffer.

Note
Always check, if there is at least one available item in the buffer, because the exception can be thrown.
Returns
Returns the last (newest with the lowest priority) item from the buffer.

◆ back() [2/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
const MeshPacket& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::back ( ) const
inline

Gets the last (newest with the lowest priority) item from the buffer.

Note
Always check, if there is at least one available item in the buffer, because the exception can be thrown.
Returns
Returns the last (newest with the lowest priority) item from the buffer.

◆ clear()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
void MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::clear ( )
inline

Clears whole buffer.

◆ count()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::count ( ) const
inline

Gets how many items are stored in buffer.

Returns
Returns how many items are stored in buffer.

◆ empty()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
bool MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::empty ( ) const
inline

Checks if buffer is empty.

Returns
Returns true when buffer is empty.

◆ existsID()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
bool MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::existsID ( uint8_t  ID,
uint8_t  source 
) const
inline

Checks if there is packet in buffer with specified ID and source address, which creates unique packet identifier.

Parameters
IDID of packet to check if exists.
sourceSource address of packet.
Returns
Returns true when packet with specified ID and source address exists in FIFO.

◆ front() [1/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacket& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::front ( )
inline

Gets the first (oldest with the highest priority) item from the buffer.

Note
Always check, if there is at least one available item in the buffer, because the exception can be thrown.
Returns
Returns the first (oldest with the highest priority) item from the buffer.

◆ front() [2/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
const MeshPacket& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::front ( ) const
inline

Gets the first (oldest with the highest priority) item from the buffer.

Note
Always check, if there is at least one available item in the buffer, because the exception can be thrown.
Returns
Returns the first (oldest with the highest priority) item from the buffer.

◆ get()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
bool MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::get ( MeshPacket item,
uint8_t  index 
) const
inline

Gets item from the buffer by index.

Parameters
itemReference to item, that will be filled by data from buffer.
indexIndex of item to get. Index 0 is the first (oldest with highest priority) item from the buffer, same as using front() method.
Returns
Returns true when item was read and false, when there is no available item at specified index.

◆ getIndexOfPacket()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
int16_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::getIndexOfPacket ( uint8_t  ID,
uint8_t  source 
) const
inline

Gets index of packet from unique packet identifier, which consists from ID and packet source address.

Parameters
IDPacket ID to look for.
sourcePacket source address to look for.
Returns
Returns index of row with packet or -1 if no suitable packet found.

◆ getRawDataSize()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
size_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::getRawDataSize ( ) const
inline

Calculates, how many bytes will be printed, when using command printRaw.

Returns
Returns how many bytes will be printed, when using command printRaw.

◆ highCount()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::highCount ( ) const
inline

Gets how many items are stored in high priority buffer.

Returns
Returns how many items are stored in high priority buffer.

◆ highFIFO() [1/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacketFIFO<ROUTE_BufferSize>& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::highFIFO ( )
inline

Gets reference to high priority FIFO.

◆ highFIFO() [2/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
const MeshPacketFIFO<ROUTE_BufferSize>& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::highFIFO ( ) const
inline

Gets reference to high priority FIFO.

◆ highSize()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::highSize ( ) const
inline

Gets maximum count of items, that can be stored in high priority buffer.

Returns
Returns maximum count of items, that can be stored in high priority buffer.

◆ lostItemsCount()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::lostItemsCount ( ) const
inline

@breif Gets how many items were lost (overwrote).

Returns
Returns how many items were lost (overwrote).

◆ lowCount()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::lowCount ( ) const
inline

Gets how many items are stored in low priority buffer.

Returns
Returns how many items are stored in low priority buffer.

◆ lowFIFO() [1/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacketFIFO<ROUTE_BufferSize>& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::lowFIFO ( )
inline

Gets reference to low priority FIFO.

◆ lowFIFO() [2/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
const MeshPacketFIFO<ROUTE_BufferSize>& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::lowFIFO ( ) const
inline

Gets reference to low priority FIFO.

◆ lowSize()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::lowSize ( ) const
inline

Gets maximum count of items, that can be stored in low priority buffer.

Returns
Returns maximum count of items, that can be stored in low priority buffer.

◆ operator[]() [1/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacket& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::operator[] ( int  index)
inline

Gets item from the buffer by index.

Note
Always check, if there is at available item in the buffer at specified index, because the exception can be thrown.
Parameters
indexIndex of item to get. Index 0 is the first (oldest with highest priority) item from the buffer, same as using front() method.

◆ operator[]() [2/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
const MeshPacket& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::operator[] ( int  index) const
inline

Gets item from the buffer by index.

Note
Always check, if there is at available item in the buffer at specified index, because the exception can be thrown.
Parameters
indexIndex of item to get. Index 0 is the first (oldest with highest priority) item from the buffer, same as using front() method.

◆ pop()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
bool MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::pop ( )
inline

Removes first (oldest with the highest priority) item from the buffer.

Note
To read first (oldest) item from this buffer use front() method before pop().
Returns
Returns true if item was removed and false if not.

◆ popMove()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacket&& MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::popMove ( )
inline

Reads and removes first (oldest with the highest priority) item from the buffer. When buffer is empty, exception may be thrown.

Note
Always check, if there is at least one available item in the buffer, because the exception can be thrown.
Returns
Returns first (oldest with the highest priority) item from the buffer.

◆ print()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
virtual size_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::print ( OSTREAM stream,
bool  showIndexes = true 
) const
inlinevirtual

Prints items as table from FIFO buffer to stream.

Parameters
streamStream, where data will be printed.
showIndexesTrue to show indexes of items in printed table.
Returns
Returns number of printed characters.

◆ printRaw()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
virtual size_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::printRaw ( OSTREAM stream,
const char *  customTag 
)
inlinevirtual

Prints raw FIFO data through stream. Those data can be decoded in PC or in another MCU.

Data structure

Byte Data Data name
0-3 "MFF:" Data label (Micro FIFO).
4-7 Custom tag
7 Allocated buffer size (Max number of rows).
8 Size of one row in bytes. (255 = unknown, size of each row has to be stored at the begining of row data)
9 Used rows count (length and CRC bytes not included).
10.....x Raw data
last 4 bytes CRC-32 (excluded 0-3 bytes)
Parameters
streamStream where to print raw data.
customTagCustom data type tag. Maximum length is 4 characters.
Returns
Returns number of printed bytes.

◆ printTo()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
size_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::printTo ( Print &  p) const
inlineoverride

Makes this class printable.

Parameters
pStream, where to print data.
Returns
Returns number of printed characters.

◆ push() [1/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
void MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::push ( MeshPacket &&  item)
inline

Pushes item after last item in buffer. When buffer is full, first (oldest with the highest priority) item will be overwritten and lostItemsCount() will be incremented by 1.

Note
If Type supports moving, it value will be moved.
Parameters
itemItem to push into buffer.

◆ push() [2/2]

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
void MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::push ( MeshPacket const &  item)
inline

Pushes item after last item in buffer. When buffer is full, first (oldest with the highest priority) item will be overwritten and lostItemsCount() will be incremented by 1.

Parameters
itemItem to push into buffer.

◆ removeAt()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
bool MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::removeAt ( uint8_t  index)
inline

Removes item at specified index. After removing, count() will return new value.

Optimizations

Some optimizations are done here to reduce remove time.

  1. std::Move is used to move rows. This can reduce moving time, because no allocation is needed when items in FIFO has allocated space.
  2. FIFO is splitted to half before removing. If index is in lower half, rows from start until index are moved up. If index is in higher half, rows from end until index are moved down. This can reduce complexity to half of it's value.
    Note
    This operation can take some time, because some rows has to be moved, that's why it is not recommended to call it often.
    Parameters
    indexIndex of item to remove.
    Returns
    Returns true if item was removed.

◆ removeByDestination()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::removeByDestination ( uint8_t  destination)
inline

Removes all packets with specified destination.

Optimizations

Some optimizations are done here to reduce remove time.

  1. std::Move is used to move rows. This can reduce moving time, because no allocation is needed when items in FIFO has allocated space.
    Note
    This operation can take some time, because some rows has to be moved, that's why it is not recommended to call it often.
    Parameters
    destinationPacket, which has same destination will be removed.
    Returns
    Returns count of removed items.

◆ removeIf()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::removeIf ( bool(*)(const MeshPacket &)  dec)
inline

Removes specified items.

Optimizations

Some optimizations are done here to reduce remove time.

  1. std::Move is used to move rows. This can reduce moving time, because no allocation is needed when items in FIFO has allocated space.
    Note
    This operation can take some time, because some rows has to be moved, that's why it is not recommended to call it often.
    Parameters
    decFunction, which returns true to remove item.
    Returns
    Returns count of removed items.

◆ removeMulti()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::removeMulti ( uint8_t  startPos,
uint8_t  itmCount 
)
inline

Removes number of item from specified index. After removing, count() will return new value.

Optimizations

Some optimizations are done here to reduce remove time.

  1. std::Move is used to move rows. This can reduce moving time, because no allocation is needed when items in FIFO has allocated space.
  2. FIFO is splitted to half before removing. If the most of removed part is in lower half, rows from start until index are moved up. If the most of removed part is in higher half, rows from end until index are moved down. This can reduce complexity to half of it's value.
    Note
    This operation can take some time, because some rows has to be moved, that's why it is not recommended to call it often.
    Parameters
    startPosIndex of first item to remove.
    itmCountCount of items to remove (including first one).
    Returns
    Returns count of removed items.

◆ restartLostItemsCounter()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
void MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::restartLostItemsCounter ( )
inline

Restarts lostItemsCount counter.

◆ size()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
uint8_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::size ( ) const
inline

Gets maximum count of items, that can be stored in buffer.

Returns
Returns maximum count of items, that can be stored in buffer.

◆ sizeOf()

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
virtual size_t MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::sizeOf ( ) const
inlinevirtual

Gets size of the whole FIFO in bytes.

Returns
Returns size of the whole FIFO in bytes.

Field Documentation

◆ floodBuffer

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacketFIFO<FLOOD_BufferSize> MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::floodBuffer
protected

◆ routeBuffer

template<uint8_t ROUTE_BufferSize, uint8_t FLOOD_BufferSize>
MeshPacketFIFO<ROUTE_BufferSize> MeshPacketPriorityFIFO< ROUTE_BufferSize, FLOOD_BufferSize >::routeBuffer
protected

The documentation for this class was generated from the following file:
MeshPacketPriorityFIFO
Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure....
Definition: meshBuffers.h:752