MeshNet  1.0.0
Public Member Functions | Protected Attributes
MeshPacketSplitter Class Reference

This class supports splitting MeshPacket to multiple MeshFrames in one carriage. MeshPackets are splitted, because they can contain larger payload than frame. Those frames can be then sent over radio to another receiver, which can build packet from those frames MeshPacketBuilder. More...

#include <meshPacketSplitter.h>

Collaboration diagram for MeshPacketSplitter:
Collaboration graph
[legend]

Public Member Functions

bool SplitNew (const MeshPacket &packet, MeshMAC bssid, uint8_t maxFrameSize_)
 Starts splitting new packet to frames, this has to be called first before splitting. More...
 
bool SplitNew (MeshPacket &&packet, MeshMAC bssid, uint8_t maxFrameSize_)
 Starts splitting new packet to frames, this has to be called first before splitting. More...
 
bool SplitNewMove (MeshPacket &packet, MeshMAC bssid, uint8_t maxFrameSize_)
 Starts splitting new packet to frames, this has to be called first before splitting. More...
 
void Restart (MeshMAC bssid, uint8_t maxFrameSize_)
 Restarts splitting with old packet, which is reused. More...
 
void Restart (uint8_t maxFrameSize_)
 Restarts splitting with old packet, which is reused. More...
 
void Restart (MeshMAC bssid)
 Restarts splitting with old packet, which is reused. More...
 
void Restart ()
 Restarts splitting with old packet, which is reused. Alternative name to this method is SeekToBegin(). More...
 
void Clear ()
 Clears and releases all rsources and stops splitting. More...
 
uint8_t GetMaxFrameSize () const
 Gets maximum frame size, that was set in SplitNew(), SplitNewMove() or Restart() method. More...
 
uint8_t GetLastCarriageFrameSize () const
 Gets size of frame, that will be at the end of carriage. All other frames has size same as GetMaxFrameSize(). When frame doesn't have to be splitted, size of that frame is returned. More...
 
uint8_t GetFramesCount () const
 Gets count of frames into which the packet will be splitted. More...
 
uint8_t GetRemainingFramesCount () const
 Gets count of remaining frames, that will be splitted. More...
 
uint8_t GetCurrentFrameSize () const
 Gets size of the current frame, which will be splitted. More...
 
uint8_t GetCurrentFrameDataSize () const
 Gets size of data part of the current frame, which will be splitted. More...
 
uint8_t GetFrameSize (uint8_t index) const
 Gets size of frame at specific index. More...
 
uint8_t GetFrameDataSize (uint8_t index) const
 Gets size of data part of frame at specific index. More...
 
uint8_t GetCurrentFrameIndex () const
 Gets index of frame, that will be splitted. More...
 
bool Seek (uint8_t frameIndex)
 Seeks (moves) to the frame set by index. This can be used, when same packet has to be retransmitted after calling SplitNextAsFrame(), SplitNextAsFrameHeaderAndData() or SplitNextAsFrameRawData(). More...
 
bool SeekToNext ()
 Seeks (moves) to the next frame. More...
 
bool SeekToEnd ()
 Seeks (moves) to the end, after last frame, that has to be splitted. More...
 
MeshFrame SplitNextAsFrame ()
 Splits current frame and moves to another. More...
 
bool SplitNextAsFrameHeaderAndData (MeshFrameHeader &header, uint8_t *data, uint8_t &dataSize)
 Splits current frame and moves to another. More...
 
bool SplitNextAsFrameRawData (uint8_t *rawData, uint8_t &dataSize)
 Splits current frame and moves to another. More...
 
MeshFrame SplitCurrentAsFrame (bool moveToNext=false)
 Splits current frame and does not move to another. Same frame can be splitted multiple times using this method. More...
 
bool SplitCurrentAsFrameHeaderAndData (MeshFrameHeader &header, uint8_t *data, uint8_t &dataSize, bool moveToNext=false)
 Splits current frame and does not move to another. Same frame can be splitted multiple times using this method. More...
 
bool SplitCurrentAsFrameRawData (uint8_t *rawData, uint8_t &dataSize, bool moveToNext=false)
 Splits current frame and does not move to another. Same frame can be splitted multiple times using this method. More...
 
const MeshPacketGetSplittedPacket () const
 Gets packet, that is being splitted. More...
 
MeshPacket && TakeSplittedPacket ()
 Takes packet, that was splitted and calls clear method. More...
 

Protected Attributes

MeshPacket sPacket
 
MeshMAC lastBSSID
 
MeshFrameHeader lastHeader
 
uint8_t carriageFrameCount = 0
 
uint8_t lastCarriageFrameDataSize = 0
 
uint8_t maxFrameSize = 32
 
uint8_t splitDataPos = 0
 
uint8_t remainingCarriageCount = 0
 

Detailed Description

This class supports splitting MeshPacket to multiple MeshFrames in one carriage. MeshPackets are splitted, because they can contain larger payload than frame. Those frames can be then sent over radio to another receiver, which can build packet from those frames MeshPacketBuilder.

Carriage

Carriage is set of frames which was splitted. The first frame in carriage is called header frame or head frame. It contains all packet header fields and part of data. Other frames are called only carriage frames, they contains only necessary frame header fields to identify frame and another part of data. Every carriage contains count of remaining frames. This is field called CarriageCount. Those carriage frames has to be sorted by CarriageCount.

Worst case performance

Table bellow shows the worst case performance, when packet with 512 bytes of data need to be sent. In the first column is maximum size of frame (maxFrameSize parameter). In the second column is calculated summation of all bytes in all splitted frames including header bytes. In the last column is number of frames, the packet will be splitted to.

Max frame size [bytes] Frame size summation [bytes] Count of splitted frames
24 780 33
32 692 22
48 620 13
64 596 10
96 564 6
128 556 5
See also
meshPacketSplitter.h
MeshPacketBuilder
MeshPacket
MeshFrame

Member Function Documentation

◆ Clear()

void MeshPacketSplitter::Clear ( )

Clears and releases all rsources and stops splitting.

◆ GetCurrentFrameDataSize()

uint8_t MeshPacketSplitter::GetCurrentFrameDataSize ( ) const

Gets size of data part of the current frame, which will be splitted.

◆ GetCurrentFrameIndex()

uint8_t MeshPacketSplitter::GetCurrentFrameIndex ( ) const
inline

Gets index of frame, that will be splitted.

Note
Call this before calling SplitNextAsFrame(), SplitNextAsFrameHeaderAndData() or SplitNextAsFrameRawData(), because this method will then return index of next frame.

◆ GetCurrentFrameSize()

uint8_t MeshPacketSplitter::GetCurrentFrameSize ( ) const

Gets size of the current frame, which will be splitted.

◆ GetFrameDataSize()

uint8_t MeshPacketSplitter::GetFrameDataSize ( uint8_t  index) const

Gets size of data part of frame at specific index.

Parameters
indexIndex of frame, which data part size needs to be get.

◆ GetFramesCount()

uint8_t MeshPacketSplitter::GetFramesCount ( ) const
inline

Gets count of frames into which the packet will be splitted.

Returns
Returns 0 when splitting is at the end or has never stared. Returns 1 when frame doesn't have to be splitted, else returns number of frames in carriage.

◆ GetFrameSize()

uint8_t MeshPacketSplitter::GetFrameSize ( uint8_t  index) const

Gets size of frame at specific index.

Parameters
indexIndex of frame, which size needs to be get.

◆ GetLastCarriageFrameSize()

uint8_t MeshPacketSplitter::GetLastCarriageFrameSize ( ) const
inline

Gets size of frame, that will be at the end of carriage. All other frames has size same as GetMaxFrameSize(). When frame doesn't have to be splitted, size of that frame is returned.

◆ GetMaxFrameSize()

uint8_t MeshPacketSplitter::GetMaxFrameSize ( ) const
inline

Gets maximum frame size, that was set in SplitNew(), SplitNewMove() or Restart() method.

◆ GetRemainingFramesCount()

uint8_t MeshPacketSplitter::GetRemainingFramesCount ( ) const
inline

Gets count of remaining frames, that will be splitted.

Returns
Returns 0 when splitting is at the end or has never stared, else returns remaining frames count.

◆ GetSplittedPacket()

const MeshPacket& MeshPacketSplitter::GetSplittedPacket ( ) const
inline

Gets packet, that is being splitted.

Note
Valid packet is returned only when splitting started.

◆ Restart() [1/4]

void MeshPacketSplitter::Restart ( )

Restarts splitting with old packet, which is reused. Alternative name to this method is SeekToBegin().

◆ Restart() [2/4]

void MeshPacketSplitter::Restart ( MeshMAC  bssid)

Restarts splitting with old packet, which is reused.

Parameters
bssidNew BSSID, that has to be set to each frame.

◆ Restart() [3/4]

void MeshPacketSplitter::Restart ( MeshMAC  bssid,
uint8_t  maxFrameSize_ 
)

Restarts splitting with old packet, which is reused.

Parameters
bssidNew BSSID, that has to be set to each frame.
maxFrameSize_New max frame size.

◆ Restart() [4/4]

void MeshPacketSplitter::Restart ( uint8_t  maxFrameSize_)

Restarts splitting with old packet, which is reused.

Parameters
maxFrameSize_New max frame size.

◆ Seek()

bool MeshPacketSplitter::Seek ( uint8_t  frameIndex)

Seeks (moves) to the frame set by index. This can be used, when same packet has to be retransmitted after calling SplitNextAsFrame(), SplitNextAsFrameHeaderAndData() or SplitNextAsFrameRawData().

Parameters
frameIndexIndex of frame, where to seek.
Returns
Returns true when seek was successfull and frameIndex was not out of range.

◆ SeekToEnd()

bool MeshPacketSplitter::SeekToEnd ( )

Seeks (moves) to the end, after last frame, that has to be splitted.

Returns
Returns true when seek wa successfull.

◆ SeekToNext()

bool MeshPacketSplitter::SeekToNext ( )

Seeks (moves) to the next frame.

Returns
Returns true when seek was successfull and end was not reached.

◆ SplitCurrentAsFrame()

MeshFrame MeshPacketSplitter::SplitCurrentAsFrame ( bool  moveToNext = false)

Splits current frame and does not move to another. Same frame can be splitted multiple times using this method.

Note
Always check before calling this method, if there are remaining frames using GetRemainingFramesCount() method.
Parameters
moveToNextTrue when splitter has to move to another frame after splitting. When you want to use it, it is recommended to use moveToNext() method.
Returns
Returns splitted frame as MeshFrame.

◆ SplitCurrentAsFrameHeaderAndData()

bool MeshPacketSplitter::SplitCurrentAsFrameHeaderAndData ( MeshFrameHeader header,
uint8_t *  data,
uint8_t &  dataSize,
bool  moveToNext = false 
)

Splits current frame and does not move to another. Same frame can be splitted multiple times using this method.

Note
Always check before calling this method, if there are remaining frames using GetRemainingFramesCount() method.
Parameters
[out]headerHeader of frame, that was splitted.
[out]dataBuffer reserved for data from splitted frame. Size of this buffer has to be minimally same as GetCurrentFrameDataSize() value.
[out]dataSizeThe size of data copyied to data buffer. This value is not checked when copying to data buffer, that why you has to check it before calling this function using GetCurrentFrameDataSize() method.
moveToNextTrue when splitter has to move to another frame after splitting. When you want to use it, it is recommended to use moveToNext() method.
Returns
Returns true when frame was splitted.

◆ SplitCurrentAsFrameRawData()

bool MeshPacketSplitter::SplitCurrentAsFrameRawData ( uint8_t *  rawData,
uint8_t &  dataSize,
bool  moveToNext = false 
)

Splits current frame and does not move to another. Same frame can be splitted multiple times using this method.

Note
Always check before calling this method, if there are remaining frames using GetRemainingFramesCount() method.
Parameters
[out]headerHeader of frame, that was splitted.
[out]rawDataBuffer reserved for data, from which the frame can be created. Size of this buffer has to be minimally same as GetMaxFrameSize() value.
[out]dataSizeThe size of data copyied to data buffer. This value is not checked when copying to data buffer, that why you has to check it before calling this function using GetCurrentFrameSize() method.
moveToNextTrue when splitter has to move to another frame after splitting. When you want to use it, it is recommended to use moveToNext() method.
Returns
Returns true when frame was splitted.

◆ SplitNew() [1/2]

bool MeshPacketSplitter::SplitNew ( const MeshPacket packet,
MeshMAC  bssid,
uint8_t  maxFrameSize_ 
)

Starts splitting new packet to frames, this has to be called first before splitting.

Parameters
packetPacket, that has to be splitted. This packed is copyied.
Note
When packet can be destroyed after calling this method, it is recommended to call SplitNewMove(), because it will be more efficient.
Parameters
bssidBSSID, that has to be inserted to each frame header.
maxFrameSize_Maximum size of frames. Can be set from MESH_FRAME_SIZE_MIN_LIMIT to MESH_FRAME_SIZE_LIMIT.
Returns
Returns true when splitting started and no error happened.

◆ SplitNew() [2/2]

bool MeshPacketSplitter::SplitNew ( MeshPacket &&  packet,
MeshMAC  bssid,
uint8_t  maxFrameSize_ 
)

Starts splitting new packet to frames, this has to be called first before splitting.

Parameters
packetPacket, that has to be splitted. This packed is moved, to class memory.
Note
Packet is not copyied as using SplitNew() method, but it is moved. Moving is more efficient than copying, because allocation is not needed. The disadvantage of moving is, that MeshPacket that was inserted will be destroyed.
Parameters
bssidBSSID, that has to be inserted to each frame header.
maxFrameSize_Maximum size of frames. Can be set from MESH_FRAME_SIZE_MIN_LIMIT to MESH_FRAME_SIZE_LIMIT.
Returns
Returns true when splitting started and no error happened.

◆ SplitNewMove()

bool MeshPacketSplitter::SplitNewMove ( MeshPacket packet,
MeshMAC  bssid,
uint8_t  maxFrameSize_ 
)

Starts splitting new packet to frames, this has to be called first before splitting.

Parameters
packetPacket, that has to be splitted. This packed is moved, to class memory.
Note
Packet is not copyied as using SplitNew() method, but it is moved. Moving is more efficient than copying, because allocation is not needed. The disadvantage of moving is, that MeshPacket that was inserted will be destroyed.
Parameters
bssidBSSID, that has to be inserted to each frame header.
maxFrameSize_Maximum size of frames. Can be set from MESH_FRAME_SIZE_MIN_LIMIT to MESH_FRAME_SIZE_LIMIT.
Returns
Returns true when splitting started and no error happened.

◆ SplitNextAsFrame()

MeshFrame MeshPacketSplitter::SplitNextAsFrame ( )
inline

Splits current frame and moves to another.

Note
Always check before calling this method, if there are remaining frames using GetRemainingFramesCount() method.
Returns
Returns splitted frame as MeshFrame.

◆ SplitNextAsFrameHeaderAndData()

bool MeshPacketSplitter::SplitNextAsFrameHeaderAndData ( MeshFrameHeader header,
uint8_t *  data,
uint8_t &  dataSize 
)
inline

Splits current frame and moves to another.

Note
Always check before calling this method, if there are remaining frames using GetRemainingFramesCount() method.
Parameters
[out]headerHeader of frame, that was splitted.
[out]dataBuffer reserved for data from splitted frame. Size of this buffer has to be minimally same as GetCurrentFrameDataSize() value.
[out]dataSizeThe size of data copyied to data buffer. This value is not checked when copying to data buffer, that why you has to check it before calling this function using GetCurrentFrameDataSize() method.
Returns
Returns true when frame was splitted.

◆ SplitNextAsFrameRawData()

bool MeshPacketSplitter::SplitNextAsFrameRawData ( uint8_t *  rawData,
uint8_t &  dataSize 
)
inline

Splits current frame and moves to another.

Note
Always check before calling this method, if there are remaining frames using GetRemainingFramesCount() method.
Parameters
[out]headerHeader of frame, that was splitted.
[out]rawDataBuffer reserved for data, from which the frame can be created. Size of this buffer has to be minimally same as GetMaxFrameSize() value.
[out]dataSizeThe size of data copyied to data buffer. This value is not checked when copying to data buffer, that why you has to check it before calling this function using GetCurrentFrameSize() method.
Returns
Returns true when frame was splitted.

◆ TakeSplittedPacket()

MeshPacket && MeshPacketSplitter::TakeSplittedPacket ( )

Takes packet, that was splitted and calls clear method.

Note
Move constructor is called, so packet will not be copyied in memory.
Valid packet is returned only when splitting started.

Field Documentation

◆ carriageFrameCount

uint8_t MeshPacketSplitter::carriageFrameCount = 0
protected

◆ lastBSSID

MeshMAC MeshPacketSplitter::lastBSSID
protected

◆ lastCarriageFrameDataSize

uint8_t MeshPacketSplitter::lastCarriageFrameDataSize = 0
protected

◆ lastHeader

MeshFrameHeader MeshPacketSplitter::lastHeader
protected

◆ maxFrameSize

uint8_t MeshPacketSplitter::maxFrameSize = 32
protected

◆ remainingCarriageCount

uint8_t MeshPacketSplitter::remainingCarriageCount = 0
protected

◆ sPacket

MeshPacket MeshPacketSplitter::sPacket
protected

◆ splitDataPos

uint8_t MeshPacketSplitter::splitDataPos = 0
protected

The documentation for this class was generated from the following files: