MIP SDK  0.0.1
MicroStrain Communications Library for embedded systems
Public Member Functions | Static Public Member Functions | List of all members
mip::Packet Class Reference

C++ class representing a MIP Packet. More...

#include <mip.hpp>

Inheritance diagram for mip::Packet:
Inheritance graph
[legend]
Collaboration diagram for mip::Packet:
Collaboration graph
[legend]

Public Member Functions

 Packet (uint8_t *buffer, size_t bufferSize, uint8_t descriptorSet)
 
 Packet (uint8_t *buffer, size_t length)
 Initializes a MIP packet from an existing buffer. More...
 
 Packet (const C::mip_packet *other)
 Constructs a C++ Packet class from the base C object. More...
 
 Packet (const C::mip_packet &other)
 Constructs a C++ Packet class from the base C object. More...
 
uint8_t descriptorSet () const
 
PacketLength totalLength () const
 
uint8_t payloadLength () const
 
bool isData () const
 
bool isCommand () const
 
const uint8_t * pointer () const
 
const uint8_t * payload () const
 
uint16_t checksumValue () const
 
uint16_t computeChecksum () const
 
bool isSane () const
 
bool isValid () const
 
bool isEmpty () const
 
PacketLength bufferSize () const
 
RemainingCount remainingSpace () const
 
bool addField (uint8_t fieldDescriptor, const uint8_t *payload, size_t payloadLength)
 
RemainingCount allocField (uint8_t fieldDescriptor, uint8_t payloadLength, uint8_t **payloadPtr_out)
 
RemainingCount reallocLastField (uint8_t *payloadPtr, uint8_t newPayloadLength)
 
RemainingCount cancelLastField (uint8_t *payloadPtr)
 
void finalize ()
 
void reset (uint8_t descSet)
 
void reset ()
 Resets the packet using the same descriptor set. More...
 
Field firstField () const
 Returns the first field in the packet. More...
 
FieldIterator begin () const
 
FieldIterator end () const
 
template<class Field >
bool addField (const Field &field, uint8_t fieldDescriptor=Field::FIELD_DESCRIPTOR)
 

Static Public Member Functions

template<class Field >
static Packet createFromField (uint8_t *buffer, size_t bufferSize, const Field &field, uint8_t fieldDescriptor=Field::FIELD_DESCRIPTOR)
 

Detailed Description

C++ class representing a MIP Packet.

Fields may be iterated over using the C-style method or with a range-based for loop:

for(Field field : packet) { ... }

Constructor & Destructor Documentation

◆ Packet() [1/4]

mip::Packet::Packet ( uint8_t *  buffer,
size_t  bufferSize,
uint8_t  descriptorSet 
)
inline

◆ Packet() [2/4]

mip::Packet::Packet ( uint8_t *  buffer,
size_t  length 
)
inline

Initializes a MIP packet from an existing buffer.

Use this when receiving or parsing MIP packets.

The data in the buffer should be a valid or suspected MIP packet.

Parameters
packet
bufferThe data buffer containing the bytes for a MIP packet. Must be at least MIP_PACKET_LENGTH_MIN bytes in size.
lengthThe length of the data pointed to by buffer.
Note
The data does not need to be a valid MIP packet, for instance to use the mip_packet_is_sane() or mip_packet_is_valid() functions. However, if it is NOT a valid MIP packet, the result of calling any accessor function is unpredictable. In particular, if length is less than MIP_PACKET_LENGTH_MIN bytes, calling the accessor functions is undefined behavior.

◆ Packet() [3/4]

mip::Packet::Packet ( const C::mip_packet other)
inline

Constructs a C++ Packet class from the base C object.

◆ Packet() [4/4]

mip::Packet::Packet ( const C::mip_packet other)
inline

Constructs a C++ Packet class from the base C object.

Member Function Documentation

◆ addField() [1/2]

template<class Field >
bool mip::Packet::addField ( const Field field,
uint8_t  fieldDescriptor = Field::FIELD_DESCRIPTOR 
)
inline

◆ addField() [2/2]

bool mip::Packet::addField ( uint8_t  fieldDescriptor,
const uint8_t *  payload,
size_t  payloadLength 
)
inline

◆ allocField()

RemainingCount mip::Packet::allocField ( uint8_t  fieldDescriptor,
uint8_t  payloadLength,
uint8_t **  payloadPtr_out 
)
inline

◆ begin()

FieldIterator mip::Packet::begin ( ) const
inline

Returns a forward iterator to the first field in the packet.

◆ bufferSize()

PacketLength mip::Packet::bufferSize ( ) const
inline

◆ cancelLastField()

RemainingCount mip::Packet::cancelLastField ( uint8_t *  payloadPtr)
inline

◆ checksumValue()

uint16_t mip::Packet::checksumValue ( ) const
inline

◆ computeChecksum()

uint16_t mip::Packet::computeChecksum ( ) const
inline

◆ createFromField()

template<class Field >
static Packet mip::Packet::createFromField ( uint8_t *  buffer,
size_t  bufferSize,
const Field field,
uint8_t  fieldDescriptor = Field::FIELD_DESCRIPTOR 
)
inlinestatic

◆ descriptorSet()

uint8_t mip::Packet::descriptorSet ( ) const
inline

◆ end()

FieldIterator mip::Packet::end ( ) const
inline

Returns a sentry object representing the end of fields in the packet.

◆ finalize()

void mip::Packet::finalize ( )
inline

◆ firstField()

Field mip::Packet::firstField ( ) const
inline

Returns the first field in the packet.

◆ isCommand()

bool mip::Packet::isCommand ( ) const
inline

◆ isData()

bool mip::Packet::isData ( ) const
inline

◆ isEmpty()

bool mip::Packet::isEmpty ( ) const
inline

◆ isSane()

bool mip::Packet::isSane ( ) const
inline

◆ isValid()

bool mip::Packet::isValid ( ) const
inline

◆ payload()

const uint8_t* mip::Packet::payload ( ) const
inline

◆ payloadLength()

uint8_t mip::Packet::payloadLength ( ) const
inline

◆ pointer()

const uint8_t* mip::Packet::pointer ( ) const
inline

◆ reallocLastField()

RemainingCount mip::Packet::reallocLastField ( uint8_t *  payloadPtr,
uint8_t  newPayloadLength 
)
inline

◆ remainingSpace()

RemainingCount mip::Packet::remainingSpace ( ) const
inline

◆ reset() [1/2]

void mip::Packet::reset ( )
inline

Resets the packet using the same descriptor set.

◆ reset() [2/2]

void mip::Packet::reset ( uint8_t  descSet)
inline

◆ totalLength()

PacketLength mip::Packet::totalLength ( ) const
inline


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