MIP_SDK  v3.0.0-736-g212583cf
MicroStrain Communications Library for embedded systems
Public Types | 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 Types

enum  Index : uint8_t { Index::LENGTH = C::MIP_FIELD_INDEX_LENGTH, Index::DESC = C::MIP_FIELD_INDEX_DESC, Index::PAYLOAD = C::MIP_FIELD_INDEX_PAYLOAD }
 

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...
 
 FieldView (CompositeDescriptor descriptor, microstrain::ConstU8ArrayView payload)
 Construct from descriptor and payload bytes. 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 totalLength () const
 Returns the total length of the field including the header. More...
 
uint8_t payloadLength () const
 Returns the length of the payload. More...
 
microstrain::ConstU8ArrayView payload () const
 Get a const view of the payload data. More...
 
uint8_t payload (size_t index) const
 Index the payload at the given location. More...
 
uint8_t operator[] (size_t index) const
 
microstrain::ConstU8ArrayView bytes () const
 Gets a view of the entire field, including the header. More...
 
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 HEADER_LENGTH = C::MIP_FIELD_HEADER_LENGTH
 
static constexpr size_t LENGTH_MIN = C::MIP_FIELD_LENGTH_MIN
 
static constexpr size_t LENGTH_MAX = C::MIP_FIELD_LENGTH_MAX
 
static constexpr size_t PAYLOAD_LENGTH_MIN = C::MIP_FIELD_PAYLOAD_LENGTH_MIN
 
static constexpr size_t PAYLOAD_LENGTH_MAX = C::MIP_FIELD_PAYLOAD_LENGTH_MAX
 

Detailed Description

This is a thin wrapper around the C mip_field struct.

Member Enumeration Documentation

◆ Index

enum mip::FieldView::Index : uint8_t
strong
Enumerator
LENGTH 
DESC 
PAYLOAD 

Constructor & Destructor Documentation

◆ FieldView() [1/5]

mip::FieldView::FieldView ( )
inline

◆ FieldView() [2/5]

mip::FieldView::FieldView ( uint8_t  descriptor_set,
uint8_t  field_descriptor,
const uint8_t *  payload,
uint8_t  payload_length 
)
inline
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/5]

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

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/5]

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

◆ FieldView() [5/5]

mip::FieldView::FieldView ( CompositeDescriptor  descriptor,
microstrain::ConstU8ArrayView  payload 
)
inline

Member Function Documentation

◆ descriptorSet()

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

◆ fieldDescriptor()

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

◆ descriptor()

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

◆ totalLength()

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

◆ payloadLength()

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

◆ payload() [1/2]

microstrain::ConstU8ArrayView mip::FieldView::payload ( ) const
inline

◆ payload() [2/2]

uint8_t mip::FieldView::payload ( size_t  index) const
inline
Parameters
indexByte index into payload. 0 <= index < payloadLength().
Returns
payload byte

◆ operator[]()

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

◆ bytes()

microstrain::ConstU8ArrayView mip::FieldView::bytes ( ) const
inline
Note
You want to use payload() instead if you're trying to extract parameters/data contained within a field.
Warning
FieldView contains a descriptor and payload pointer. It does not guarantee the descriptors are also stored in the same buffer as the payload. This function operates by using a negative index from the payload pointer, so it is up to the user to ensure such an index is safe. Generally, if the field was obtained from an existing packet then the header bytes will be available. E.g. the field was obtained via PacketView::firstField(), for(FieldView field : packet), etc. then the whole packet, including all fields and their headers, should exist in the buffer. Standalone FieldViews created from a descriptor and payload array may not have header bytes and this function isn't safe in that case.

◆ isValid()

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

◆ nextAfter()

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

◆ next()

bool mip::FieldView::next ( )
inline

◆ extract()

template<class FieldType >
bool mip::FieldView::extract ( FieldType &  field,
bool  exact_size = true 
) const
inline
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.

◆ isData()

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

◆ isCommandSet()

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

◆ isCommand()

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

◆ isReply()

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

◆ isResponse()

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

Member Data Documentation

◆ HEADER_LENGTH

constexpr size_t mip::FieldView::HEADER_LENGTH = C::MIP_FIELD_HEADER_LENGTH
staticconstexpr

◆ LENGTH_MIN

constexpr size_t mip::FieldView::LENGTH_MIN = C::MIP_FIELD_LENGTH_MIN
staticconstexpr

◆ LENGTH_MAX

constexpr size_t mip::FieldView::LENGTH_MAX = C::MIP_FIELD_LENGTH_MAX
staticconstexpr

◆ PAYLOAD_LENGTH_MIN

constexpr size_t mip::FieldView::PAYLOAD_LENGTH_MIN = C::MIP_FIELD_PAYLOAD_LENGTH_MIN
staticconstexpr

◆ PAYLOAD_LENGTH_MAX

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

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