MeshNet  1.0.0
Public Member Functions
MeshPacketBuilder Class Reference

This class can build packet from multiple frames. It is usually used to concatinate data from packet, that was splitted into multiple frames in carriage, because of packet size. This class also checks if frame needs to be built (if is not carriage frame, so packet is not splitted) and converts this frame to packet. More...

#include <meshPacketBuilder.h>

Public Member Functions

MeshPacketBuilderStatus Append (const uint8_t *rawData, uint8_t rawDataSize, int8_t rssi)
 Appends MeshFrame (that will be created from raw data) to packet builder. More...
 
MeshPacketBuilderStatus Append (MeshFrame &frame, int8_t rssi)
 Appends MeshFrame to packet builder. More...
 
MeshPacketBuilderStatus Append (MeshFrameHeader frameHeader, const uint8_t *data, uint8_t dataSize, int8_t rssi)
 Appends MeshFrame (that will be created from frameHeader and frame data) to packet builder. More...
 
void Clear ()
 Clears all appended data and last packet. More...
 
void SetFrameReceivedCallback (void(*callback)(MeshPacketBuilder *, MeshPacketBuilderStatus, const MeshFrameHeader &, const uint8_t *, uint8_t, int8_t))
 Sets callback function, that is called when valid frame is received. This function can be used to calculate CTS delay time. More...
 
void SetPacketCheckCallback (bool(*callback)(MeshPacketBuilder *, const MeshPacketHeader &, MeshMAC, SystemPacketType, const uint8_t *, uint8_t, int8_t))
 Sets callback function, that is called when new packet is going to start build. This callback function has to decide, if packet can be build or has to be ignored. If this callback function is not set, all packet will be received. More...
 
void SetMaxFrameSize (uint8_t size)
 Sets maximum frame size. Defaultly set to 32. More...
 
uint8_t GetMaxFrameSize () const
 Gets maximum frame size. More...
 
uint16_t GetPredictedMinPacketDataLength () const
 Gets minimum predicted packet data length in bytes of packet, that is currently being built. More...
 
uint16_t GetPredictedMaxPacketDataLength () const
 Gets maximum predicted packet data length in bytes of packet, that is currently being built. More...
 
bool IsEmpty () const
 Checks if any packet was built or being built or had an error at built. More...
 
MeshPacketBuilderStatus GetStatus () const
 Gets status of packet, that was built or is being built or had build error. Ignored frames are not reflected in this status. More...
 
bool PacketIsBuilding () const
 Checks if packet is building right now and is not already built. More...
 
bool PacketAvailable () const
 Checks if packet was built. If yes, you can get it using method GetBuiltPacket(). More...
 
bool HasError () const
 Checks if any error happened during packet building. More...
 
const MeshPacketGetBuiltPacket () const
 Gets packet, that was built. More...
 
MeshPacketGetBuiltPacket ()
 Gets packet, that was built. More...
 
MeshPacket && TakeBuiltPacket ()
 Takes packet, that was built and calls clear method. More...
 
MeshMAC GetLastPacketBSSID () const
 Gets BSSID of last packet. More...
 
SystemPacketType GetLastPacketSystemType () const
 Gets system packet type of last packet. If packet is not system packet, SPT_ERROR is returned. More...
 
MeshPacketHeader GetLastPacketHeader () const
 Gets header of last packet. More...
 
MeshFrameControl GetLastPacketFrameControl () const
 Gets frame control of last packet. More...
 
uint8_t RemainingCarriageFramesCount () const
 Count of remaining frames in carriage. More...
 
uint8_t CarriageFramesCount () const
 Count of all frames the packet was splitted at. More...
 
uint8_t ReceivedFramesCount () const
 Gets count of received frames from current packet. More...
 
int8_t GetAverageRSSI () const
 Gets average RSSI of received packet's frames. More...
 
int8_t GetMinRSSI () const
 Gets minimum RSSI of received packet's frames. More...
 
uint32_t GetAppendingEndTime () const
 Gets time, when appending of last packet has ended. This can be used as time, when was last part of that packet received. More...
 

Detailed Description

This class can build packet from multiple frames. It is usually used to concatinate data from packet, that was splitted into multiple frames in carriage, because of packet size. This class also checks if frame needs to be built (if is not carriage frame, so packet is not splitted) and converts this frame to packet.

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.

See also
meshPacketBuilder.h
MeshPacketSplitter
MeshNet
MeshPacket
MeshFrame

Member Function Documentation

◆ Append() [1/3]

MeshPacketBuilderStatus MeshPacketBuilder::Append ( const uint8_t *  rawData,
uint8_t  rawDataSize,
int8_t  rssi 
)

Appends MeshFrame (that will be created from raw data) to packet builder.

Parameters
[in]rawDataRaw received data, from which frame can be created.
rawDataSizeSize of raw data in bytes.
rssiRSSI value of received frame.
Returns
Returns appending status. Note, that this status is also for ignored frames, but method GetStatus() is status of full packet or waiting part of packet.
Note
It is recommended to set SetPacketCheckCallback() before calling this method. The packet check callback can decide, if packet will be ignored or not.
See also
MeshPacketBuilder

◆ Append() [2/3]

MeshPacketBuilderStatus MeshPacketBuilder::Append ( MeshFrame frame,
int8_t  rssi 
)

Appends MeshFrame to packet builder.

Parameters
frameFrame to append.
rssiRSSI value of received frame.
Returns
Returns appending status. Note, that this status is also for ignored frames, but method GetStatus() is status of full packet or waiting part of packet.
Note
It is recommended to set SetPacketCheckCallback() before calling this method. The packet check callback can decide, if packet will be ignored or not.
See also
MeshPacketBuilder

◆ Append() [3/3]

MeshPacketBuilderStatus MeshPacketBuilder::Append ( MeshFrameHeader  frameHeader,
const uint8_t *  data,
uint8_t  dataSize,
int8_t  rssi 
)

Appends MeshFrame (that will be created from frameHeader and frame data) to packet builder.

Parameters
frameHeaderFrame header to append.
[in]dataFrame data (frame header data has not to be included).
dataSizeSize of data in bytes.
rssiRSSI value of received frame.
Returns
Returns appending status. Note, that this status is also for ignored frames, but method GetStatus() is status of full packet or waiting part of packet.
Note
It is recommended to set SetPacketCheckCallback() before calling this method. The packet check callback can decide, if packet will be ignored or not.
See also
MeshPacketBuilder

◆ CarriageFramesCount()

uint8_t MeshPacketBuilder::CarriageFramesCount ( ) const

Count of all frames the packet was splitted at.

Note
Can be get only when PacketAvailable() or PacketIsBuilding() returns true.
Returns
Returns count of all frames in carriage.

◆ Clear()

void MeshPacketBuilder::Clear ( )

Clears all appended data and last packet.

◆ GetAppendingEndTime()

uint32_t MeshPacketBuilder::GetAppendingEndTime ( ) const
inline

Gets time, when appending of last packet has ended. This can be used as time, when was last part of that packet received.

Note
Can be get only when PacketAvailable() or PacketIsBuilding() returns true.
Returns
Returns time, when last packet frame was last time appended in ms.

◆ GetAverageRSSI()

int8_t MeshPacketBuilder::GetAverageRSSI ( ) const

Gets average RSSI of received packet's frames.

◆ GetBuiltPacket() [1/2]

MeshPacket& MeshPacketBuilder::GetBuiltPacket ( )
inline

Gets packet, that was built.

Note
Packet can be get only when PacketAvailable() returns true.

◆ GetBuiltPacket() [2/2]

const MeshPacket& MeshPacketBuilder::GetBuiltPacket ( ) const
inline

Gets packet, that was built.

Note
Packet can be get only when PacketAvailable() returns true.

◆ GetLastPacketBSSID()

MeshMAC MeshPacketBuilder::GetLastPacketBSSID ( ) const
inline

Gets BSSID of last packet.

Note
Packet BSSID can be get only when PacketAvailable() or PacketIsBuilding() returns true.

◆ GetLastPacketFrameControl()

MeshFrameControl MeshPacketBuilder::GetLastPacketFrameControl ( ) const
inline

Gets frame control of last packet.

Note
Packet frame control can be get only when PacketAvailable() or PacketIsBuilding() returns true.

◆ GetLastPacketHeader()

MeshPacketHeader MeshPacketBuilder::GetLastPacketHeader ( ) const
inline

Gets header of last packet.

Note
Packet header can be get only when PacketAvailable() or PacketIsBuilding() returns true.

◆ GetLastPacketSystemType()

SystemPacketType MeshPacketBuilder::GetLastPacketSystemType ( ) const
inline

Gets system packet type of last packet. If packet is not system packet, SPT_ERROR is returned.

Note
System packet type can be get only when PacketAvailable() or PacketIsBuilding() returns true.

◆ GetMaxFrameSize()

uint8_t MeshPacketBuilder::GetMaxFrameSize ( ) const
inline

Gets maximum frame size.

Returns
Returns maximum frame size.

◆ GetMinRSSI()

int8_t MeshPacketBuilder::GetMinRSSI ( ) const
inline

Gets minimum RSSI of received packet's frames.

◆ GetPredictedMaxPacketDataLength()

uint16_t MeshPacketBuilder::GetPredictedMaxPacketDataLength ( ) const
inline

Gets maximum predicted packet data length in bytes of packet, that is currently being built.

Note
Correct value can be read only when PacketIsBuilding() is true.
Returns
Maximum value of predicted data length in bytes.

◆ GetPredictedMinPacketDataLength()

uint16_t MeshPacketBuilder::GetPredictedMinPacketDataLength ( ) const
inline

Gets minimum predicted packet data length in bytes of packet, that is currently being built.

Note
Correct value can be read only when PacketIsBuilding() is true.
Returns
Minimum value of predicted data length in bytes.

◆ GetStatus()

MeshPacketBuilderStatus MeshPacketBuilder::GetStatus ( ) const
inline

Gets status of packet, that was built or is being built or had build error. Ignored frames are not reflected in this status.

Returns
Returns status.
See also
MeshPacketBuilder

◆ HasError()

bool MeshPacketBuilder::HasError ( ) const
inline

Checks if any error happened during packet building.

◆ IsEmpty()

bool MeshPacketBuilder::IsEmpty ( ) const
inline

Checks if any packet was built or being built or had an error at built.

Returns
Returns true when no packet was built or is being built or had an error at built.

◆ PacketAvailable()

bool MeshPacketBuilder::PacketAvailable ( ) const
inline

Checks if packet was built. If yes, you can get it using method GetBuiltPacket().

◆ PacketIsBuilding()

bool MeshPacketBuilder::PacketIsBuilding ( ) const
inline

Checks if packet is building right now and is not already built.

◆ ReceivedFramesCount()

uint8_t MeshPacketBuilder::ReceivedFramesCount ( ) const
inline

Gets count of received frames from current packet.

Returns
Returns count of received frames from current packet.

◆ RemainingCarriageFramesCount()

uint8_t MeshPacketBuilder::RemainingCarriageFramesCount ( ) const

Count of remaining frames in carriage.

Note
Can be get only when PacketAvailable() or PacketIsBuilding() returns true.
Returns
Returns count of remaining frames in carriage.

◆ SetFrameReceivedCallback()

void MeshPacketBuilder::SetFrameReceivedCallback ( void(*)(MeshPacketBuilder *, MeshPacketBuilderStatus, const MeshFrameHeader &, const uint8_t *, uint8_t, int8_t)  callback)
inline

Sets callback function, that is called when valid frame is received. This function can be used to calculate CTS delay time.

Parameters
callbackCallback funcion.

Callback function parameters

  • MeshPacketBuilder* - Pointer to builder, which is calling callback function.
  • MeshPacketBuilderStatus - Status of current frame.
  • MeshPacketHeader - Frame header of frame, which was received.
  • const uint8_t* - Pointer to data which are contained in first frame.
  • uint8_t - Size of frame data.
  • int8_t - RSSI of received frame.

◆ SetMaxFrameSize()

void MeshPacketBuilder::SetMaxFrameSize ( uint8_t  size)

Sets maximum frame size. Defaultly set to 32.

Parameters
sizeMaximum frame size limit from range: MESH_FRAME_SIZE_MIN_LIMIT to MESH_FRAME_SIZE_LIMIT.

◆ SetPacketCheckCallback()

void MeshPacketBuilder::SetPacketCheckCallback ( bool(*)(MeshPacketBuilder *, const MeshPacketHeader &, MeshMAC, SystemPacketType, const uint8_t *, uint8_t, int8_t)  callback)
inline

Sets callback function, that is called when new packet is going to start build. This callback function has to decide, if packet can be build or has to be ignored. If this callback function is not set, all packet will be received.

Note
BSSID should be compared in this callback function.
Parameters
callbackCallback funcion.

Callback function parameters

  • MeshPacketBuilder* - Pointer to builder, which is calling callback function.
  • MeshPacketHeader - Packet header of packet, which was received.
  • MeshMAC - BSSID (network identifier).
  • SystemPacketType - System packet type. This parameter has to be checked only when packet is system packet.
  • const uint8_t* - Pointer to data which are contained in first frame including SystemPacketType byte. NULL is set here when packet is not system packet.
  • uint8_t - Size of frame data. Zero, when system packet was not received.
  • int8_t - RSSI of received frame.
  • returns - True if packet has to be build, false if packet has to be ignored.

◆ TakeBuiltPacket()

MeshPacket && MeshPacketBuilder::TakeBuiltPacket ( )

Takes packet, that was built and calls clear method.

Note
Move constructor is called, so packet will not be copyied in memory.
Packet can be get only when PacketAvailable() returns true.

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