MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
Public Member Functions | Static Public Attributes | List of all members
mip::FieldView Class Reference

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

#include <mip_field.hpp>

Inheritance diagram for mip::FieldView:
mip::C::mip_field_view

Public Member Functions

 FieldView ()
 Construct an empty MIP field. More...
 
 FieldView (uint8_t descriptor_set, uint8_t field_descriptor, const uint8_t *payload, uint8_t payload_length)
 Constructs a field view given the parameters. More...
 
 FieldView (const uint8_t *header, uint8_t total_length, uint8_t descriptor_set)
 Constructs a mip_field from a pointer to the heaader. More...
 
 FieldView (const C::mip_field_view &other)
 Creates a Field class from the mip_field C struct. More...
 
uint8_t descriptorSet () const
 Returns the descriptor set of the packet containing this field._. More...
 
uint8_t fieldDescriptor () const
 Returns the field descriptor. More...
 
CompositeDescriptor descriptor () const
 Returns the descriptor set and field descriptor. More...
 
uint8_t payloadLength () const
 Returns the length of the payload. More...
 
const uint8_t * payload () const
 Returns the payload pointer for the field data. More...
 
uint8_t payload (unsigned int index) const
 Index the payload at the given location. More...
 
uint8_t operator[] (unsigned int index) const
 
microstrain::Span< const uint8_t > payloadSpan () const
 
bool isValid () const
 Returns true if the field has a valid field descriptor. More...
 
FieldView nextAfter () const
 Gets the next field after the specified field. More...
 
bool next ()
 Updates the mip_field to refer to the next field in a packet. More...
 
template<class FieldType >
bool extract (FieldType &field, bool exact_size=true) const
 Deserializes the field data to specific field struct. More...
 
bool isData () const
 Determines if the field holds data (and not a command, reply, or response). More...
 
bool isCommandSet () const
 Determines if the field is from a command descriptor set (a command, reply, or response field). More...
 
bool isCommand () const
 Determines if the field holds a command. More...
 
bool isReply () const
 Determines if the field holds an ack/nack reply code. More...
 
bool isResponse () const
 Determines if the field holds command response data (not an ack/nack reply). More...
 

Static Public Attributes

static constexpr size_t MAX_PAYLOAD_LENGTH = C::MIP_FIELD_PAYLOAD_LENGTH_MAX
 

Detailed Description

C++ class representing a MIP field.

This is a thin wrapper around the C mip_field struct.

Constructor & Destructor Documentation

◆ FieldView() [1/4]

mip::FieldView::FieldView ( )
inline

Construct an empty MIP field.

◆ FieldView() [2/4]

mip::FieldView::FieldView ( uint8_t  descriptor_set,
uint8_t  field_descriptor,
const uint8_t *  payload,
uint8_t  payload_length 
)
inline

Constructs a field view given the parameters.

Parameters
field
descriptor_setThe MIP descriptor set of the packet.
field_descriptorThe MIP field descriptor.
payloadA pointer to a buffer containing the field payload, not including the field header. The data must exist while the field is in use. Can be NULL if payload_length is 0.
payload_lengthThe length of the payload. Cannot exceed MIP_FIELD_PAYLOAD_LENGTH_MAX.

◆ FieldView() [3/4]

mip::FieldView::FieldView ( const uint8_t *  header,
uint8_t  total_length,
uint8_t  descriptor_set 
)
inline

Constructs a mip_field from a pointer to the heaader.

Generally you should use mip_field_from_packet() or mip_field_create() instead.

Parameters
headerA pointer to the header and payload. Usually inside of a MIP packet.
total_lengthThe total length of either the field or packet payload, starting from header_ptr and including the header bytes. If total_length is longer than the field (i.e. if it's the packet payload length) then mip_field_next() may be used to iterate fields.
descriptor_setThe descriptor set for the packet containing this field. May be 0x00 if not used by any function handling the field.
Returns
a mip_field struct with the field data.

◆ FieldView() [4/4]

mip::FieldView::FieldView ( const C::mip_field_view other)
inline

Creates a Field class from the mip_field C struct.

Member Function Documentation

◆ descriptor()

CompositeDescriptor mip::FieldView::descriptor ( ) const
inline

Returns the descriptor set and field descriptor.

◆ descriptorSet()

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

Returns the descriptor set of the packet containing this field._.

◆ extract()

template<class FieldType >
bool mip::FieldView::extract ( FieldType &  field,
bool  exact_size = true 
) const
inline

Deserializes the field data to specific field struct.

Template Parameters
FieldTypeAny field class from a file in the mip/definitions directory.
Parameters
[out]fieldA reference to the field struct to be filled out. Valid only if the function returns true.
exact_sizeIf true, the function fails if any bytes remain after deserialization.
Returns
True if the field was successfully deserialized, or false if the field contains too few bytes (or to many if exact_size is specified). The field data is not valid unless this function returns true.

◆ fieldDescriptor()

uint8_t mip::FieldView::fieldDescriptor ( ) const
inline

Returns the field descriptor.

◆ isCommand()

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

Determines if the field holds a command.

◆ isCommandSet()

bool mip::FieldView::isCommandSet ( ) const
inline

Determines if the field is from a command descriptor set (a command, reply, or response field).

◆ isData()

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

Determines if the field holds data (and not a command, reply, or response).

◆ isReply()

bool mip::FieldView::isReply ( ) const
inline

Determines if the field holds an ack/nack reply code.

◆ isResponse()

bool mip::FieldView::isResponse ( ) const
inline

Determines if the field holds command response data (not an ack/nack reply).

◆ isValid()

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

Returns true if the field has a valid field descriptor.

◆ next()

bool mip::FieldView::next ( )
inline

Updates the mip_field to refer to the next field in a packet.

◆ nextAfter()

FieldView mip::FieldView::nextAfter ( ) const
inline

Gets the next field after the specified field.

◆ operator[]()

uint8_t mip::FieldView::operator[] ( unsigned int  index) const
inline

◆ payload() [1/2]

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

Returns the payload pointer for the field data.

◆ payload() [2/2]

uint8_t mip::FieldView::payload ( unsigned int  index) const
inline

Index the payload at the given location.

Parameters
index
Returns
payload byte

◆ payloadLength()

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

Returns the length of the payload.

◆ payloadSpan()

microstrain::Span<const uint8_t> mip::FieldView::payloadSpan ( ) const
inline

Member Data Documentation

◆ MAX_PAYLOAD_LENGTH

constexpr size_t mip::FieldView::MAX_PAYLOAD_LENGTH = C::MIP_FIELD_PAYLOAD_LENGTH_MAX
staticconstexpr

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