MIP_SDK
v3.0.0-534-g6be5866
MicroStrain Communications Library for embedded systems
|
Go to the documentation of this file.
143 assert(capacity() <= FIELD_PAYLOAD_LENGTH_MAX);
150 if(!ok && basePointer())
166 return {*
this, ptr, max_size};
181 #if __cpp_range_based_for >= 201603
184 std::nullptr_t
end()
const {
return nullptr; }
210 template<
class FieldType>
211 bool addField(
const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
213 if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
214 fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
235 template<
class FieldType>
238 if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
239 fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
241 packet.
addField<FieldType>(field, fieldDescriptor);
316 template<
size_t BufferSize>
319 static_assert(BufferSize >= PACKET_LENGTH_MIN,
"BufferSize must be at least PACKET_LENGTH_MIN bytes");
336 template<
size_t OtherSize>
343 template<
size_t OtherSize>
353 template<
class FieldType>
355 const FieldType& field,
356 uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR,
357 typename std::enable_if<std::is_class<FieldType>::value,
void>::type* =
nullptr
360 createFromField<FieldType>(mData,
sizeof(mData), field, fieldDescriptor);
393 uint8_t mData[BufferSize];
bool copyPacketTo(microstrain::U8ArrayView buffer) const
Copies this packet to an external buffer (span version).
Definition: mip_packet.hpp:301
@ MIP_PACKET_LENGTH_MAX
Definition: mip_offsets.h:28
PacketView(microstrain::U8ArrayView buffer, uint8_t descriptorSet)
Create a new MIP packet in an existing buffer.
Definition: mip_packet.hpp:57
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:148
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:422
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
uint8_t * mip_packet_buffer(mip_packet_view *packet)
Returns a writable pointer to the data buffer.
Definition: mip_packet.c:121
PacketView(const C::mip_packet_view &other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:52
bool next()
Updates the mip_field to refer to the next field in a packet.
Definition: mip_field.hpp:93
SizedPacketBuf(microstrain::ConstU8ArrayView data)
Construct by copying an existing buffer.
Definition: mip_packet.hpp:325
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
SizedPacketBuf< mip::PACKET_LENGTH_MAX > PacketBuf
Typedef for SizedPacketBuf of max possible size.
Definition: mip_packet.hpp:402
Definition: mip_packet.hpp:126
Definition: mip_packet.hpp:252
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:339
@ MIP_PACKET_LENGTH_MIN
Definition: mip_offsets.h:27
static PacketView createFromField(microstrain::ConstU8ArrayView 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:236
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:48
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:211
@ MIP_PACKET_PAYLOAD_LENGTH_MAX
Definition: mip_offsets.h:26
const FieldView & operator*() const
Dereference the iterator as a Field instance.
Definition: mip_packet.hpp:283
SizedPacketBuf(const PacketView &packet)
Creates a PacketBuf by copying an existing packet.
Definition: mip_packet.hpp:329
int mip_packet_remaining_space(const mip_packet_view *packet)
Returns the remaining space available for more payload data.
Definition: mip_packet.c:246
void copyFrom(const PacketView &packet)
Copies an existing packet. The packet is assumed to be valid (undefined behavior otherwise).
Definition: mip_packet.hpp:390
AllocatedField createField(uint8_t fieldDescriptor)
Definition: mip_packet.hpp:162
FieldView firstField() const
Returns the first field in the packet.
Definition: mip_packet.hpp:199
bool operator==(const FieldIterator &other) const
Definition: mip_packet.hpp:265
bool addField(uint8_t fieldDescriptor, microstrain::ConstU8ArrayView payload)
Creates a mip field with the given descriptor and copies the given payload.
Definition: mip_packet.hpp:123
void mip_packet_reset(mip_packet_view *packet, uint8_t descriptor_set)
Reinitialize the packet with the given descriptor set.
Definition: mip_packet.c:469
TypedResult< Reset > reset(C::mip_interface &device)
Definition: commands_filter.cpp:32
FieldIterator end() const
Definition: mip_packet.hpp:186
FieldIterator & operator++()
Advance to the next field.
Definition: mip_packet.hpp:286
void cancel()
Definition: mip_packet.hpp:156
const uint8_t * mip_packet_pointer(const mip_packet_view *packet)
Returns a pointer to the data buffer containing the packet.
Definition: mip_packet.c:129
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
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:187
FieldIterator()
Empty iterator, which represents the "end" iterator of a packet.
Definition: mip_packet.hpp:256
Structure representing a MIP Packet.
Definition: mip_packet.h:50
PacketView(uint8_t *buffer, size_t bufferSize, uint8_t descriptorSet)
Create a brand-new MIP packet in the given buffer.
Definition: mip_packet.hpp:46
bool addField(const FieldView &field)
Copies the given mip field to the packet.
Definition: mip_packet.hpp:119
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:354
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:200
A mip packet with a self-contained buffer (useful with std::vector).
Definition: mip_packet.hpp:317
PacketView(const C::mip_packet_view *other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:50
uint_least16_t mip_packet_buffer_size(const mip_packet_view *packet)
Returns the size of the buffer backing the MIP packet.
Definition: mip_packet.c:232
SizedPacketBuf & operator=(const SizedPacketBuf &other)
Copy assignment operator.
Definition: mip_packet.hpp:340
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
SizedPacketBuf(const SizedPacketBuf< OtherSize > &other)
Copy constructor (required to insert packets into std::vector in some cases).
Definition: mip_packet.hpp:337
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
static constexpr size_t PACKET_SIZE_MIN
Definition: mip_packet.hpp:39
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:297
const uint8_t * bufferPointer() const
Definition: mip_packet.hpp:85
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:386
microstrain::ArrayView< uint8_t, BufferSize > buffer()
Returns a Span covering the entire buffer.
Definition: mip_packet.hpp:378
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:137
microstrain::U8ArrayView bufferWr()
Gets a writeable view to the entire storage buffer (usually more than just the packet).
Definition: mip_packet.hpp:115
C++ class representing a MIP field.
Definition: mip_field.hpp:25
static constexpr size_t PAYLOAD_LENGTH_MAX
Definition: mip_packet.hpp:38
uint8_t * bufferPointer()
Returns a pointer to the underlying buffer. This is technically the same as PacketRef::pointer but is...
Definition: mip_packet.hpp:374
uint8_t payload(size_t i) const
Get a pointer to the payload data.
Definition: mip_packet.hpp:76
uint16_t mip_packet_compute_checksum(const mip_packet_view *packet)
Computes the checksum of the MIP packet.
Definition: mip_packet.c:160
uint8_t * allocateOrCancel(size_t length)
Definition: mip_packet.hpp:133
uint8_t fieldDescriptor() const
Returns the field descriptor.
Definition: mip_field.hpp:49
SizedPacketBuf & operator=(const SizedPacketBuf< OtherSize > &other)
Assignment operator, copies data from another buffer to this one.
Definition: mip_packet.hpp:344
uint8_t * bufferPointerWr()
Returns a writable pointer to the data buffer.
Definition: mip_packet.hpp:86
microstrain::ConstU8ArrayView payload() const
Gets a const byte view of just the payload.
Definition: mip_packet.hpp:108
uint8_t payload(size_t index) const
Index the payload at the given location.
Definition: mip_field.hpp:62
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:178
constexpr pointer data() const noexcept
Definition: array_view.hpp:69
PacketView(microstrain::ConstU8ArrayView buffer)
Create a reference to an existing MIP packet.
Definition: mip_packet.hpp:62
const PacketView & ref() const
Explicitly obtains a const reference to the packet data.
Definition: mip_packet.hpp:370
static constexpr size_t PACKET_SIZE_MAX
Definition: mip_packet.hpp:40
bool isValid() const
Returns true if the field has a valid field descriptor.
Definition: mip_field.hpp:88
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
bool mip_packet_is_empty(const mip_packet_view *packet)
Returns true if the mip packet contains no payload.
Definition: mip_packet.c:218
AllocatedField & operator=(const AllocatedField &)=delete
bool operator==(std::nullptr_t) const
Definition: mip_packet.hpp:279
AllocatedField(mip::PacketView &packet, uint8_t *buffer, size_t space)
Definition: mip_packet.hpp:129
const uint8_t * payloadPointer() const
Returns the payload pointer for the field data.
Definition: mip_field.hpp:57
microstrain::ConstU8ArrayView data() const
Gets a const byte view for the whole packet.
Definition: mip_packet.hpp:104
bool commit()
Definition: mip_packet.hpp:141
bool operator!=(const FieldIterator &other) const
Definition: mip_packet.hpp:275
bool operator!=(std::nullptr_t) const
Definition: mip_packet.hpp:280
void mip_packet_finalize(mip_packet_view *packet)
Prepares the packet for transmission by adding the checksum.
Definition: mip_packet.c:451
uint8_t operator[](unsigned int index) const
Definition: mip_packet.hpp:169
PacketView ref()
Explicitly obtains a reference to the packet data.
Definition: mip_packet.hpp:366
const uint8_t * pointer() const
Definition: mip_packet.hpp:74
SizedPacketBuf(const SizedPacketBuf &other)
Copy constructor.
Definition: mip_packet.hpp:332
SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET)
Definition: mip_packet.hpp:322
FieldIterator(const FieldView &first)
Definition: mip_packet.hpp:260
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:35
FieldIterator begin() const
Definition: mip_packet.hpp:177
Serializer createField(uint8_t fieldDescriptor, uint8_t length)
Definition: mip_packet.hpp:91
void copyFrom(microstrain::ConstU8ArrayView data)
Copies the data from a U8ArrayView to this buffer. The data is not inspected.
Definition: mip_packet.hpp:384
constexpr size_t size() const noexcept
Definition: array_view.hpp:71
bool isData() const
Definition: mip_packet.hpp:72
uint8_t descriptorSet() const
Returns the descriptor set of the packet containing this field._.
Definition: mip_field.hpp:47
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:259
microstrain::ConstU8ArrayView buffer() const
Gets a const view to the entire storage buffer (usually more than just the packet).
Definition: mip_packet.hpp:111
const uint8_t * payloadPointer() const
Get a pointer to the entire packet data.
Definition: mip_packet.hpp:75