MeshNet  1.0.0
Public Member Functions | Data Fields | Static Protected Member Functions | Protected Attributes
MeshPacket Class Reference

Class, that stores mesh packet with it's data. The size of this class can be slightly bigger then real packet size. Fields that increasing size are: More...

#include <meshPacket.h>

Inheritance diagram for MeshPacket:
Inheritance graph
[legend]
Collaboration diagram for MeshPacket:
Collaboration graph
[legend]

Public Member Functions

 MeshPacket ()
 
 MeshPacket (const MeshPacket &mp)
 Copy constructor. More...
 
 MeshPacket (MeshPacket &&mp) noexcept
 Move constructor. More...
 
 ~MeshPacket ()
 Destructor. More...
 
MeshPacketoperator= (const MeshPacket &mp)
 Copy assignment operator. More...
 
MeshPacketoperator= (MeshPacket &&mp) noexcept
 Move assignment operator. More...
 
uint16_t Length () const
 Length of payload. More...
 
uint8_t operator[] (uint16_t i) const
 
uint8_t & operator[] (uint16_t i)
 
SystemPacketType GetSystemPacketType () const
 Gets type of system packet. More...
 
uint8_t GetPayloadByteAt (uint16_t index) const
 Reads payload byte at specified index. More...
 
virtual bool SetPayloadByteAt (uint16_t index, uint8_t value)
 Sets payload byte at specified index. More...
 
virtual bool SetPayload (const uint8_t *payload, const uint16_t payloadLength)
 Sets payload data. More...
 
bool SetPayload (const MeshVariableArray< uint8_t > &va)
 Copyies payload data from variable array to current packet payload. More...
 
virtual bool SetPayload (MeshVariableArray< uint8_t > &&va)
 Copyies payload data from variable array to current packet payload and clears data in that variable array. More...
 
void GetPayload (uint8_t *payload, uint16_t &payloadLength) const
 Gets payload data. More...
 
bool GetPayload (MeshVariableArray< uint8_t > &payload) const
 Copyies payload data. More...
 
MeshVariableArray< uint8_t > TakePayload ()
 Takes payload data. Payload will be cleared after this operation, because std::move was used. This method has a lot better performance than GetPayload() method, because there is no manual copying. More...
 
bool ResizePayload (uint16_t size, bool doNotCopy=false)
 Resizes payload. More...
 
void ClearPayload ()
 Clears payload data. More...
 
virtual void Clear ()
 Clears all data in packet. More...
 
virtual bool copyFrom (const MeshPacket &another)
 Copyies data from another packet to current packet. More...
 
virtual void moveFrom (MeshPacket &another)
 Copyies data from another packet to current packet and clears data in another packet. More...
 
const uint8_t * p_ptr () const
 Pointer to payload. More...
 
size_t prettyPrint (OSTREAM &stream) const
 Pretty prints packet to stream. More...
 
size_t printTo (Print &p) const override
 Makes this class printable. More...
 
size_t printHeader (OSTREAM *stream) const override
 Prints header of table. More...
 
size_t printLine (OSTREAM *stream) const override
 Prints this data as row to table. More...
 
size_t sizeOf () const override
 Gets size of the whole class in bytes including dynamically allocated part. More...
 
size_t printRaw (OSTREAM *stream, void(*CRC_calculation)(uint8_t *, size_t)) const override
 Prints current instance into stream in raw bytes. More...
 
virtual size_t getRawSize () const override
 Calculates size of raw bytes. More...
 
virtual bool HasError () const
 Checks if packet is not valid. More...
 
void SetError ()
 Sets that packet is not valid. More...
 
bool GetError () const
 Checks if error is set by calling SetError() More...
 
void ClearError ()
 Sets that packet is valid. More...
 

Data Fields

MeshPacketHeader PacketHeader
 Mesh packet header. More...
 

Static Protected Member Functions

static char toHEXChar (OSTREAM &stream, uint8_t val)
 
static size_t printHex (OSTREAM &stream, uint8_t val)
 

Protected Attributes

uint8_t * Payload = NULL
 Packet payload. More...
 
uint16_t PayloadLength: 10
 Packet payload length. Maximum value can be 1023, because only 10 bits are used. More...
 
bool error: 1
 True when packet has error. More...
 

Detailed Description

Class, that stores mesh packet with it's data. The size of this class can be slightly bigger then real packet size. Fields that increasing size are:

See also
meshPacket.h

Constructor & Destructor Documentation

◆ MeshPacket() [1/3]

MeshPacket::MeshPacket ( )

◆ MeshPacket() [2/3]

MeshPacket::MeshPacket ( const MeshPacket mp)

Copy constructor.

◆ MeshPacket() [3/3]

MeshPacket::MeshPacket ( MeshPacket &&  mp)
noexcept

Move constructor.

◆ ~MeshPacket()

MeshPacket::~MeshPacket ( )

Destructor.

Member Function Documentation

◆ Clear()

void MeshPacket::Clear ( )
virtual

Clears all data in packet.

◆ ClearError()

void MeshPacket::ClearError ( )
inline

Sets that packet is valid.

◆ ClearPayload()

void MeshPacket::ClearPayload ( )

Clears payload data.

◆ copyFrom()

bool MeshPacket::copyFrom ( const MeshPacket another)
virtual

Copyies data from another packet to current packet.

Parameters
anotherPacket to copy data from.
Returns
Returns true when copying was done correctly.

◆ GetError()

bool MeshPacket::GetError ( ) const
inline

Checks if error is set by calling SetError()

◆ GetPayload() [1/2]

bool MeshPacket::GetPayload ( MeshVariableArray< uint8_t > &  payload) const
inline

Copyies payload data.

Parameters
[out]payloadPayload data.
Note
For better performance you can use TakePayload().
Returns
Returns true if data were copyied successfully.

◆ GetPayload() [2/2]

void MeshPacket::GetPayload ( uint8_t *  payload,
uint16_t &  payloadLength 
) const

Gets payload data.

Parameters
[out]payloadPayload data
[in/out]payloadLength Set length of your buffer. After data copying this value will contain copyied payload length.

◆ GetPayloadByteAt()

uint8_t MeshPacket::GetPayloadByteAt ( uint16_t  index) const

Reads payload byte at specified index.

Parameters
indexIndex, where to read payload byte.
Returns
Returns byte from payload at specified index or 0 when index is outside of range.

◆ getRawSize()

size_t MeshPacket::getRawSize ( ) const
overridevirtual

Calculates size of raw bytes.

Returns
Returns size of raw bytes.

Reimplemented from RawPrintable.

◆ GetSystemPacketType()

SystemPacketType MeshPacket::GetSystemPacketType ( ) const

Gets type of system packet.

Returns
Returns type of system packet or SPT_ERROR when curent packet has error or SPT_DATA is packet is not system packet.

◆ HasError()

virtual bool MeshPacket::HasError ( ) const
inlinevirtual

Checks if packet is not valid.

◆ Length()

uint16_t MeshPacket::Length ( ) const
inline

Length of payload.

◆ moveFrom()

void MeshPacket::moveFrom ( MeshPacket another)
virtual

Copyies data from another packet to current packet and clears data in another packet.

Note
This is more efficient than calling copyFrom.
Parameters
anotherPacket to move data from.
Returns
Returns true when moving was done correctly.

◆ operator=() [1/2]

MeshPacket & MeshPacket::operator= ( const MeshPacket mp)

Copy assignment operator.

◆ operator=() [2/2]

MeshPacket & MeshPacket::operator= ( MeshPacket &&  mp)
noexcept

Move assignment operator.

◆ operator[]() [1/2]

uint8_t& MeshPacket::operator[] ( uint16_t  i)
inline

◆ operator[]() [2/2]

uint8_t MeshPacket::operator[] ( uint16_t  i) const
inline

◆ p_ptr()

const uint8_t* MeshPacket::p_ptr ( ) const
inline

Pointer to payload.

◆ prettyPrint()

size_t MeshPacket::prettyPrint ( OSTREAM stream) const

Pretty prints packet to stream.

Parameters
streamStream, where packet will be printed.
Returns
Returns number of printed characters.

◆ printHeader()

size_t MeshPacket::printHeader ( OSTREAM stream) const
overridevirtual

Prints header of table.

Parameters
streamPonter to wtream, where header has to be print.
Returns
Returns number of printed characters.
Note
Print "\r\n" at the end of the header.

Reimplemented from InlinePrintable.

◆ printHex()

size_t MeshPacket::printHex ( OSTREAM stream,
uint8_t  val 
)
staticprotected

◆ printLine()

size_t MeshPacket::printLine ( OSTREAM stream) const
overridevirtual

Prints this data as row to table.

Parameters
streamPonter to wtream, where row has to be print.
Returns
Returns number of printed characters.
Note
Print "\r\n" at the end of the line.

Reimplemented from InlinePrintable.

◆ printRaw()

size_t MeshPacket::printRaw ( OSTREAM stream,
void(*)(uint8_t *, size_t)  CRC_calculation 
) const
overridevirtual

Prints current instance into stream in raw bytes.

Parameters
CRC_calculationPointer to function, which provides CRC calculation, every sent byte has to be passed to this function. First parameter is pointer to data, that were printed and second is number of printed bytes.
Returns
Number of printed characters.

Reimplemented from RawPrintable.

◆ printTo()

size_t MeshPacket::printTo ( Print &  p) const
override

Makes this class printable.

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

◆ ResizePayload()

bool MeshPacket::ResizePayload ( uint16_t  size,
bool  doNotCopy = false 
)

Resizes payload.

Parameters
sizeNew size. Allowed value from 0 to PAYLOAD_SIZE_LIMIT.
doNotCopyTrue to do not copy old data.
Returns
Returns true when resizing was sucessfull.

◆ SetError()

void MeshPacket::SetError ( )
inline

Sets that packet is not valid.

◆ SetPayload() [1/3]

bool MeshPacket::SetPayload ( const MeshVariableArray< uint8_t > &  va)
inline

Copyies payload data from variable array to current packet payload.

Parameters
vaVariable array which data will be copyied.
Returns
Returns true when copying was done correctly.

◆ SetPayload() [2/3]

bool MeshPacket::SetPayload ( const uint8_t *  payload,
const uint16_t  payloadLength 
)
virtual

Sets payload data.

Parameters
[in]payloadNew payload data.
[in]payloadLengthLength of new data.
Returns
Returns true when data was copyied.

◆ SetPayload() [3/3]

bool MeshPacket::SetPayload ( MeshVariableArray< uint8_t > &&  va)
virtual

Copyies payload data from variable array to current packet payload and clears data in that variable array.

Note
This is more efficient than calling copyFrom.
Parameters
vaVariable array which data will be moved.
Returns
Returns true when moving was done correctly.

◆ SetPayloadByteAt()

bool MeshPacket::SetPayloadByteAt ( uint16_t  index,
uint8_t  value 
)
virtual

Sets payload byte at specified index.

Parameters
indexIndex, where to set payload byte.
valueByte valeu to set.
Returns
Returns true when byte was set.

◆ sizeOf()

size_t MeshPacket::sizeOf ( ) const
inlineoverridevirtual

Gets size of the whole class in bytes including dynamically allocated part.

Returns
Returns size of the whole class in bytes.

Reimplemented from RawPrintable.

◆ TakePayload()

MeshVariableArray< uint8_t > MeshPacket::TakePayload ( )

Takes payload data. Payload will be cleared after this operation, because std::move was used. This method has a lot better performance than GetPayload() method, because there is no manual copying.

Returns
Returns payload as MeshVariableArray<uint8_t>.

◆ toHEXChar()

static char MeshPacket::toHEXChar ( OSTREAM stream,
uint8_t  val 
)
inlinestaticprotected

Field Documentation

◆ error

bool MeshPacket::error
protected

True when packet has error.

◆ PacketHeader

MeshPacketHeader MeshPacket::PacketHeader

Mesh packet header.

See also
MeshPacketHeader

◆ Payload

uint8_t* MeshPacket::Payload = NULL
protected

Packet payload.

◆ PayloadLength

uint16_t MeshPacket::PayloadLength
protected

Packet payload length. Maximum value can be 1023, because only 10 bits are used.


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