MeshNet  1.0.0
Public Member Functions
MeshPacketFIFO< BufferSize > Class Template Reference

Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure. More...

#include <meshBuffers.h>

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

Public Member Functions

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...
 
uint8_t removeByDestination (uint8_t destination)
 Removes all packets with specified destination. More...
 
- Public Member Functions inherited from MicroFIFO< MeshPacket, BufferSize >
const MeshPacketfront () const
 Gets the first (oldest) item from the buffer. More...
 
MeshPacketfront ()
 Gets the first (oldest) item from the buffer. More...
 
const MeshPacketback () const
 Gets the last (newest) item from the buffer. More...
 
MeshPacketback ()
 Gets the last (newest) 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) 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) item will be overwritten and lostItemsCount() will be incremented by 1. More...
 
MeshPacket && popMove ()
 Reads and removes first (oldest) item from the buffer. When buffer is empty, exception may be thrown. This method is recommended to use only if std::move will be used. More...
 
bool pop ()
 Removes first (oldest) item from the buffer. More...
 
bool empty () const
 Checks if buffer is empty. More...
 
uint8_t count () const
 Gets how many items are stored in buffer. More...
 
const uint8_t size () const
 Gets maximum count of items, that can be stored in buffer. More...
 
uint8_t lostItemsCount () const
 
void restartLostItemsCounter ()
 Restarts lostItemsCount counter. 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...
 
void clear ()
 Clears whole buffer. 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...
 

Additional Inherited Members

- Protected Member Functions inherited from MicroFIFO< MeshPacket, BufferSize >
int16_t getRawIndex (uint8_t index) const
 Gets raw index in buffer from index. Index starts from startPos. Raw index starts from the beginning of the buffer. More...
 
const MeshPacketgetRowPtr (uint8_t index) const
 Gets pointer to the item in buffer by index. More...
 
MeshPacketgetRowPtr (uint8_t index)
 Gets pointer to the item in buffer by index. More...
 
bool isRawIndexOccupied (uint8_t rawIndex) const
 Checks if there is item stored at raw index. More...
 
- Protected Attributes inherited from MicroFIFO< MeshPacket, BufferSize >
MeshPacket buffer [BufferSize]
 
uint8_t startPos
 
uint8_t endPos
 
uint8_t usedSize
 
uint8_t lostItems
 

Detailed Description

template<uint8_t BufferSize>
class MeshPacketFIFO< BufferSize >

Optimized FIFO buffer for microcontrolers, that can store only MeshPacket structure.

Size of the FIFO buffer in this example can store 255 MeshPackets.

How data are stored:

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

Member Function Documentation

◆ existsID()

template<uint8_t BufferSize>
bool MeshPacketFIFO< 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.

◆ getIndexOfPacket()

template<uint8_t BufferSize>
int16_t MeshPacketFIFO< 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.

◆ removeByDestination()

template<uint8_t BufferSize>
uint8_t MeshPacketFIFO< 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.

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