|
MIP_SDK
v4.0.0
MicroStrain Communications Library for embedded systems
|
Go to the documentation of this file.
121 uint8_t
dataAt(
const size_t i)
const { assert(i < totalLength());
return payload()[i]; }
162 if(!ok && basePointer())
178 return {*
this, ptr, max_size};
194 #if __cpp_range_based_for >= 201603
197 std::nullptr_t
end()
const {
return nullptr; }
223 template<
class FieldType>
227 fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
248 template<
class FieldType>
252 fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
254 packet.
addField<FieldType>(field, fieldDescriptor);
329 template<
size_t BufferSize>
332 static_assert(BufferSize >=
LENGTH_MIN,
"BufferSize must be at least PacketView::LENGTH_MIN bytes");
349 template<
size_t OtherSize>
356 template<
size_t OtherSize>
366 template<
class FieldType>
368 const FieldType& field,
370 typename std::enable_if<std::is_class<FieldType>::value,
void>::type* =
nullptr
373 createFromField<FieldType>({mData,
sizeof(mData)}, field, fieldDescriptor);
402 uint8_t mData[BufferSize];
bool copyPacketTo(microstrain::U8ArrayView buffer) const
Copies this packet to an external buffer (span version).
Definition: mip_packet.hpp:314
static constexpr size_t LENGTH_MAX
Definition: mip_packet.hpp:52
static constexpr size_t HEADER_LENGTH
Definition: mip_packet.hpp:49
PacketView(microstrain::U8ArrayView buffer, uint8_t descriptorSet)
Create a new MIP packet in an existing buffer.
Definition: mip_packet.hpp:70
uint16_t mip_packet_checksum_value(const mip_packet_view *packet)
Returns the value of the checksum as written in the packet.
Definition: mip_packet.c:164
int mip_packet_cancel_last_field(mip_packet_view *packet, uint8_t *payload_ptr)
Removes the last field from the packet after having allocated it.
Definition: mip_packet.c:438
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
PacketView(const C::mip_packet_view &other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:65
static constexpr uint8_t SYNC_1
Definition: mip_packet.hpp:46
bool next()
Updates the mip_field to refer to the next field in a packet.
Definition: mip_field.hpp:106
microstrain::ConstU8ArrayView payload() const
Get a const view of the payload data.
Definition: mip_field.hpp:70
SizedPacketBuf(microstrain::ConstU8ArrayView data)
Construct by copying an existing buffer.
Definition: mip_packet.hpp:338
void mip_packet_from_buffer(mip_packet_view *packet, const uint8_t *buffer, size_t length)
Initializes a MIP packet from an existing buffer.
Definition: mip_packet.c:44
@ MIP_PACKET_HEADER_LENGTH
Definition: mip_packet.h:80
Definition: mip_packet.hpp:138
Definition: mip_packet.hpp:265
int mip_packet_create_field(mip_packet_view *packet, uint8_t field_descriptor, uint8_t payload_length, uint8_t **payload_ptr_out)
Allocate a MIP field within the packet and return the payload pointer.
Definition: mip_packet.c:355
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:135
PacketView(const uint8_t *buffer, size_t length)
Initializes a MIP packet from an existing buffer.
Definition: mip_packet.hpp:61
@ MIP_PACKET_LENGTH_MIN
Definition: mip_packet.h:84
bool addField(const FieldType &field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
Adds a field of the given type to the packet.
Definition: mip_packet.hpp:224
const FieldView & operator*() const
Dereference the iterator as a Field instance.
Definition: mip_packet.hpp:296
SizedPacketBuf(const PacketView &packet)
Creates a PacketBuf by copying an existing packet.
Definition: mip_packet.hpp:342
int mip_packet_remaining_space(const mip_packet_view *packet)
Returns the remaining space available for more payload data.
Definition: mip_packet.c:262
void copyFrom(const PacketView &packet)
Copies an existing packet. The packet is assumed to be valid (undefined behavior otherwise).
Definition: mip_packet.hpp:399
AllocatedField createField(uint8_t fieldDescriptor)
Definition: mip_packet.hpp:174
FieldView firstField() const
Returns the first field in the packet.
Definition: mip_packet.hpp:212
bool operator==(const FieldIterator &other) const
Definition: mip_packet.hpp:278
bool addField(uint8_t fieldDescriptor, microstrain::ConstU8ArrayView payload)
Get writable payload byte at index i.
Definition: mip_packet.hpp:131
void mip_packet_reset(mip_packet_view *packet, uint8_t descriptor_set)
Reinitialize the packet with the given descriptor set.
Definition: mip_packet.c:485
TypedResult< Reset > reset(C::mip_interface &device)
Definition: commands_filter.cpp:32
FieldIterator end() const
Definition: mip_packet.hpp:199
FieldIterator & operator++()
Advance to the next field.
Definition: mip_packet.hpp:299
void cancel()
Definition: mip_packet.hpp:168
@ MIP_PACKET_INDEX_SYNC_1
Definition: mip_packet.h:71
@ MIP_SYNC_2
Definition: mip_packet.h:91
uint8_t * mip_packet_payload_w(mip_packet_view *packet)
Returns a writable pointer to the packet's payload (the first field).
Definition: mip_packet.c:153
uint_least16_t mip_packet_total_length(const mip_packet_view *packet)
Returns the total length of the packet, in bytes.
Definition: mip_packet.c:113
@ MIP_PACKET_INDEX_LENGTH
Definition: mip_packet.h:74
bool mip_packet_is_sane(const mip_packet_view *packet)
Returns true if the packet buffer is not NULL and is at least the minimum size (MIP_PACKET_LENGTH_MIN...
Definition: mip_packet.c:203
FieldIterator()
Empty iterator, which represents the "end" iterator of a packet.
Definition: mip_packet.hpp:269
Structure representing a MIP Packet.
Definition: mip_packet.h:63
uint8_t payloadAt(const size_t i) const
Definition: mip_packet.hpp:126
PacketView(uint8_t *buffer, size_t bufferSize, uint8_t descriptorSet)
Create a brand-new MIP packet in the given buffer.
Definition: mip_packet.hpp:59
bool addField(const FieldView &field)
Copies the given mip field to the packet.
Definition: mip_packet.hpp:135
const uint8_t * mip_packet_buffer(const mip_packet_view *packet)
Returns a read-only pointer to the data buffer.
Definition: mip_packet.c:121
@ MIP_PACKET_INDEX_DESC_SET
Definition: mip_packet.h:73
static constexpr size_t PAYLOAD_LENGTH_MAX
Definition: mip_field.hpp:38
uint8_t * getPtrAndAdvance(size_t size)
Obtains a pointer to the current offset for reading/writing a value of specified size,...
Definition: serializer.hpp:98
SizedPacketBuf(const FieldType &field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR, typename std::enable_if< std::is_class< FieldType >::value, void >::type *=nullptr)
Create a packet containing just the given field.
Definition: mip_packet.hpp:367
uint8_t * mip_packet_buffer_w(mip_packet_view *packet)
Returns a writable pointer to the data buffer.
Definition: mip_packet.c:129
uint8_t mip_packet_descriptor_set(const mip_packet_view *packet)
Returns the MIP descriptor set for this packet.
Definition: mip_packet.c:95
bool mip_packet_is_valid(const mip_packet_view *packet)
Returns true if the packet is valid.
Definition: mip_packet.c:216
A mip packet with a self-contained buffer (useful with std::vector).
Definition: mip_packet.hpp:330
PacketView(const C::mip_packet_view *other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:63
@ MIP_PACKET_PAYLOAD_LENGTH_MAX
Definition: mip_packet.h:83
SizedPacketBuf & operator=(const SizedPacketBuf &other)
Copy assignment operator.
Definition: mip_packet.hpp:353
@ MIP_SYNC_1
Definition: mip_packet.h:90
SizedPacketBuf(const SizedPacketBuf< OtherSize > &other)
Copy constructor (required to insert packets into std::vector in some cases).
Definition: mip_packet.hpp:350
void mip_packet_create(mip_packet_view *packet, uint8_t *buffer, size_t buffer_size, uint8_t descriptor_set)
Create a brand-new MIP packet in the given buffer.
Definition: mip_packet.c:70
@ MIP_PACKET_INDEX_SYNC_2
Definition: mip_packet.h:72
bool mip_packet_add_field(mip_packet_view *packet, uint8_t field_descriptor, const uint8_t *payload, uint8_t payload_length)
Adds a pre-constructed MIP field to the packet.
Definition: mip_packet.c:313
static constexpr uint8_t INVALID_FIELD_DESCRIPTOR
Definition: mip_descriptors.hpp:75
@ MIP_PACKET_INDEX_PAYLOAD
Definition: mip_packet.h:75
Index
Definition: mip_packet.hpp:37
uint8_t dataAt(const size_t i) const
Definition: mip_packet.hpp:121
static constexpr uint8_t SYNC_2
Definition: mip_packet.hpp:47
int mip_packet_update_last_field_length(mip_packet_view *packet, uint8_t *payload_ptr, uint8_t new_payload_length)
Changes the size of the last field in the packet.
Definition: mip_packet.c:402
microstrain::ArrayView< uint8_t, BufferSize > buffer()
Returns an ArrayView covering the entire buffer.
Definition: mip_packet.hpp:387
microstrain::U8ArrayView payload_w()
Get the payload as raw bytes.
Definition: mip_packet.hpp:101
const uint8_t * mip_packet_payload(const mip_packet_view *packet)
Returns a pointer to the packet's payload (the first field).
Definition: mip_packet.c:145
static constexpr size_t PAYLOAD_LENGTH_MIN
Definition: mip_packet.hpp:53
C++ class representing a MIP field.
Definition: mip_field.hpp:24
microstrain::U8ArrayView buffer_w()
Gets the entire storage buffer for the packet.
Definition: mip_packet.hpp:91
static constexpr size_t PAYLOAD_LENGTH_MAX
Definition: mip_packet.hpp:54
@ MIP_PACKET_CHECKSUM_LENGTH
Definition: mip_packet.h:81
SizedPacketBuf< PacketView::LENGTH_MAX > PacketBuf
Typedef for SizedPacketBuf of max possible size.
Definition: mip_packet.hpp:411
static constexpr size_t CHECKSUM_LENGTH
Definition: mip_packet.hpp:50
uint16_t mip_packet_compute_checksum(const mip_packet_view *packet)
Computes the checksum of the MIP packet.
Definition: mip_packet.c:176
uint8_t * allocateOrCancel(size_t length)
Definition: mip_packet.hpp:145
uint8_t fieldDescriptor() const
Returns the field descriptor.
Definition: mip_field.hpp:59
SizedPacketBuf & operator=(const SizedPacketBuf< OtherSize > &other)
Assignment operator, copies data from another buffer to this one.
Definition: mip_packet.hpp:357
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
microstrain::ConstU8ArrayView payload() const
Definition: mip_packet.hpp:100
uint8_t dataAt(const Index i) const
Definition: mip_packet.hpp:123
uint8_t & dataAt(const Index i)
Definition: mip_packet.hpp:124
mip_field_view mip_field_first_from_packet(const mip_packet_view *packet)
Extracts the first field from a MIP packet.
Definition: mip_field.c:177
constexpr pointer data() const noexcept
Definition: array_view.hpp:69
static constexpr size_t LENGTH_MIN
Definition: mip_packet.hpp:51
PacketView(microstrain::ConstU8ArrayView buffer)
Create a reference to an existing MIP packet.
Definition: mip_packet.hpp:75
const PacketView & ref() const
Explicitly obtains a const reference to the packet data.
Definition: mip_packet.hpp:383
bool isValid() const
Returns true if the field has a valid field descriptor.
Definition: mip_field.hpp:101
uint8_t mip_packet_payload_length(const mip_packet_view *packet)
Returns the length of the payload (MIP fields).
Definition: mip_packet.c:103
Represents a view over a contiguous array of objects, similar to std::span, and is implemented as a p...
Definition: array_view.hpp:44
@ MIP_PACKET_LENGTH_MAX
Definition: mip_packet.h:85
bool mip_packet_is_empty(const mip_packet_view *packet)
Returns true if the mip packet contains no payload.
Definition: mip_packet.c:234
AllocatedField & operator=(const AllocatedField &)=delete
bool operator==(std::nullptr_t) const
Definition: mip_packet.hpp:292
AllocatedField(mip::PacketView &packet, uint8_t *buffer, size_t space)
Definition: mip_packet.hpp:141
microstrain::ConstU8ArrayView data() const
Definition: mip_packet.hpp:96
bool commit()
Definition: mip_packet.hpp:153
uint8_t & payloadAt(const size_t i)
Get payload byte at index i.
Definition: mip_packet.hpp:127
uint_least16_t mip_packet_buffer_length(const mip_packet_view *packet)
Returns the size of the buffer backing the MIP packet.
Definition: mip_packet.c:248
bool operator!=(const FieldIterator &other) const
Definition: mip_packet.hpp:288
static PacketView createFromField(microstrain::U8ArrayView packetBuffer, const FieldType &field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
Creates a new PacketRef containing a single MIP field from an instance of the field type.
Definition: mip_packet.hpp:249
static constexpr uint8_t INVALID_DESCRIPTOR_SET
Definition: mip_descriptors.hpp:76
@ MIP_PACKET_PAYLOAD_LENGTH_MIN
Definition: mip_packet.h:82
bool operator!=(std::nullptr_t) const
Definition: mip_packet.hpp:293
void mip_packet_finalize(mip_packet_view *packet)
Prepares the packet for transmission by adding the checksum.
Definition: mip_packet.c:467
PacketView ref()
Explicitly obtains a reference to the packet data.
Definition: mip_packet.hpp:379
SizedPacketBuf(const SizedPacketBuf &other)
Copy constructor.
Definition: mip_packet.hpp:345
SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET)
Definition: mip_packet.hpp:335
const uint8_t * mip_packet_data(const mip_packet_view *packet)
Returns a pointer to the data buffer containing the packet.
Definition: mip_packet.c:137
FieldIterator(const FieldView &first)
Definition: mip_packet.hpp:273
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:34
FieldIterator begin() const
Definition: mip_packet.hpp:190
Serializer createField(uint8_t fieldDescriptor, uint8_t length)
Definition: mip_packet.hpp:110
uint8_t & dataAt(const size_t i)
Definition: mip_packet.hpp:122
void copyFrom(microstrain::ConstU8ArrayView data)
Copies the data from a U8ArrayView to this buffer. The data is not inspected.
Definition: mip_packet.hpp:393
constexpr size_t size() const noexcept
Definition: array_view.hpp:71
uint8_t descriptorSet() const
Returns the descriptor set of the packet containing this field._.
Definition: mip_field.hpp:57
bool mip_packet_is_data(const mip_packet_view *packet)
Returns true if the packet is from a data descriptor set.
Definition: mip_packet.c:275
microstrain::ConstU8ArrayView buffer() const
Definition: mip_packet.hpp:90