MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
mip_packet.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_field.hpp"
4 
5 #include <mip/mip_packet.h>
6 #include <mip/mip_offsets.h>
7 
9 
10 #include <assert.h>
11 #include <cstring>
12 
13 
14 namespace mip
15 {
19 
20 
36 {
37 public:
39  static constexpr size_t PACKET_SIZE_MIN = C::MIP_PACKET_LENGTH_MIN;
40  static constexpr size_t PACKET_SIZE_MAX = C::MIP_PACKET_LENGTH_MAX;
41 
42  class FieldIterator;
43 
44 public:
46  PacketView(uint8_t* buffer, size_t bufferSize, uint8_t descriptorSet) { C::mip_packet_create(this, buffer, bufferSize, descriptorSet); }
48  PacketView(const uint8_t* buffer, size_t length) { C::mip_packet_from_buffer(this, const_cast<uint8_t*>(buffer), length); }
50  PacketView(const C::mip_packet_view* other) { std::memcpy(static_cast<C::mip_packet_view*>(this), other, sizeof(*this)); }
52  PacketView(const C::mip_packet_view& other) { std::memcpy(static_cast<C::mip_packet_view*>(this), &other, sizeof(*this)); }
53 
57  PacketView(microstrain::Span<uint8_t> buffer, uint8_t descriptorSet) { C::mip_packet_create(this, buffer.data(), buffer.size(), descriptorSet); }
58 
62  PacketView(microstrain::Span<const uint8_t> buffer) { C::mip_packet_from_buffer(this, const_cast<uint8_t*>(buffer.data()), buffer.size()); }
63 
64  //
65  // C function wrappers
66  //
67 
68  uint8_t descriptorSet() const { return C::mip_packet_descriptor_set(this); }
69  uint_least16_t totalLength() const { return C::mip_packet_total_length(this); }
70  uint8_t payloadLength() const { return C::mip_packet_payload_length(this); }
71 
72  bool isData() const { return C::mip_packet_is_data(this); }
73 
74  const uint8_t* pointer() const { return C::mip_packet_pointer(this); }
75  const uint8_t* payload() const { return C::mip_packet_payload(this); }
76 
77  uint16_t checksumValue() const { return C::mip_packet_checksum_value(this); }
78  uint16_t computeChecksum() const { return C::mip_packet_compute_checksum(this); }
79 
80  bool isSane() const { return C::mip_packet_is_sane(this); }
81  bool isValid() const { return C::mip_packet_is_valid(this); }
82  bool isEmpty() const { return C::mip_packet_is_empty(this); }
83 
84  uint_least16_t bufferSize() const { return C::mip_packet_buffer_size(this); }
85  int remainingSpace() const { return C::mip_packet_remaining_space(this); }
86 
87  bool addField(uint8_t fieldDescriptor, const uint8_t* payload, uint8_t payloadLength) { return C::mip_packet_add_field(this, fieldDescriptor, payload, payloadLength); }
88  Serializer createField(uint8_t fieldDescriptor, uint8_t length) { uint8_t* ptr; if(C::mip_packet_create_field(this, fieldDescriptor, length, &ptr) < 0) length =0; return Serializer{ptr, length}; }
89  //std::tuple<uint8_t*, size_t> createField(uint8_t fieldDescriptor) { uint8_t* ptr; int max_size = C::mip_packet_alloc_field(this, fieldDescriptor, 0, &ptr); return max_size >= 0 ? std::make_tuple(ptr, max_size) : std::make_tuple(nullptr, 0); } ///<@copydoc mip::C::mip_packet_alloc_field
90  //int finishLastField(uint8_t* payloadPtr, uint8_t newPayloadLength) { return C::mip_packet_realloc_last_field(this, payloadPtr, newPayloadLength); } ///<@copydoc mip::C::mip_packet_realloc_last_field
91  //int cancelLastField(uint8_t* payloadPtr) { return C::mip_packet_cancel_last_field(this, payloadPtr); } ///<@copydoc mip::C::mip_packet_cancel_last_field
92 
93  void finalize() { C::mip_packet_finalize(this); }
94 
95  void reset(uint8_t descSet) { C::mip_packet_reset(this, descSet); }
96  void reset() { reset(descriptorSet()); }
97 
98  //
99  // C++ additions
100  //
101 
104  microstrain::Span<const uint8_t> totalSpan() const { return {pointer(), totalLength()}; }
105 
108  microstrain::Span<const uint8_t> payloadSpan() const { return {payload(), payloadLength()}; }
109 
110 
111  class AllocatedField : public Serializer
112  {
113  public:
114  AllocatedField(mip::PacketView& packet, uint8_t* buffer, size_t space) : Serializer(buffer, space), m_packet(packet) {}
115  //AllocatedField(const AllocatedField&) = delete;
116  AllocatedField& operator=(const AllocatedField&) = delete;
117 
118  uint8_t* allocateOrCancel(size_t length)
119  {
120  uint8_t* ptr = getPtrAndAdvance(length);
121  if(!ptr)
122  cancel();
123  return ptr;
124  }
125 
126  bool commit()
127  {
128  assert(capacity() <= FIELD_PAYLOAD_LENGTH_MAX);
129 
130  bool ok = isOk();
131 
132  if(ok)
133  ok &= C::mip_packet_update_last_field_length(&m_packet, basePointer(), (uint8_t) usedLength()) >= 0;
134 
135  if(!ok && basePointer())
136  C::mip_packet_cancel_last_field(&m_packet, basePointer());
137 
138  return ok;
139  }
140 
141  void cancel() { if(basePointer()) C::mip_packet_cancel_last_field(&m_packet, basePointer()); }
142 
143  private:
144  PacketView& m_packet;
145  };
146 
147  AllocatedField createField(uint8_t fieldDescriptor)
148  {
149  uint8_t* ptr;
150  size_t max_size = std::max<int>(0, C::mip_packet_create_field(this, fieldDescriptor, 0, &ptr));
151  return {*this, ptr, max_size};
152  }
153 
154  uint8_t operator[](unsigned int index) const { return pointer()[index]; }
155 
156  //
157  // Additional functions which have no C equivalent
158  //
159 
162  FieldIterator begin() const { return firstField(); }
163 
166 #if __cpp_range_based_for >= 201603
167  // After 201603, for loops allow different clases for begin and end.
168  // Using nullptr is simpler and more efficient than creating an end iterator.
169  std::nullptr_t end() const { return nullptr; }
170 #else
171  FieldIterator end() const { return FieldView(); }
172 #endif
173 
185 
195  template<class FieldType>
196  bool addField(const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
197  {
198  if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
199  fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
200 
201  AllocatedField buffer = createField(fieldDescriptor);
202  buffer.insert(field);
203  return buffer.commit();
204  }
205 
221  template<class FieldType>
222  static PacketView createFromField(uint8_t* buffer, size_t bufferSize, const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
223  {
224  if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
225  fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
226  PacketView packet(buffer, bufferSize, FieldType::DESCRIPTOR_SET);
227  packet.addField<FieldType>(field, fieldDescriptor);
228  packet.finalize();
229  return packet;
230  }
231 
232 
239  {
240  public:
243 
246  FieldIterator(const FieldView& first) : mField(first) {}
247 
251  bool operator==(const FieldIterator& other) const {
252  // Required to make invalid fields equivalent for range-based for loop
253  if( !mField.isValid() && !other.mField.isValid() )
254  return true;
255  return mField.descriptorSet() == other.mField.descriptorSet() && mField.fieldDescriptor() == other.mField.fieldDescriptor() && mField.payload() == other.mField.payload();
256  }
257  bool operator!=(const FieldIterator& other) const { return !(*this == other); }
258 
261  bool operator==(std::nullptr_t) const { return !mField.isValid(); }
262  bool operator!=(std::nullptr_t) const { return mField.isValid(); }
263 
265  const FieldView& operator*() const { return mField; }
266 
268  FieldIterator& operator++() { mField.next(); return *this; }
269 
270  private:
271  FieldView mField;
272  };
273 
284  bool copyPacketTo(uint8_t* buffer, size_t maxLength) { assert(isSane()); size_t copyLength = this->totalLength(); if(copyLength > maxLength) return false; std::memcpy(buffer, pointer(), copyLength); return true; }
285 
295  bool copyPacketTo(microstrain::Span<uint8_t> buffer) { return copyPacketTo(buffer.data(), buffer.size()); }
296 };
297 
298 
302 template<size_t BufferSize>
304 {
305  static_assert(BufferSize >= PACKET_LENGTH_MIN, "BufferSize must be at least PACKET_LENGTH_MIN bytes");
306 
307 public:
308  SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET) : PacketView(mData, sizeof(mData), descriptorSet) {}
309 
312  explicit SizedPacketBuf(const uint8_t* data, size_t length) : PacketView(mData, sizeof(mData)) { copyFrom(data, length); }
313  explicit SizedPacketBuf(const PacketView& packet) : PacketView(mData, sizeof(mData)) { copyFrom(packet); }
314 
316  explicit SizedPacketBuf(microstrain::Span<const uint8_t> data) : SizedPacketBuf(data.data(), data.size()) {}
317 
319  SizedPacketBuf(const SizedPacketBuf& other) : PacketView(mData, sizeof(mData)) { copyFrom(other); }
320 
321 
323  template<size_t OtherSize>
324  explicit SizedPacketBuf(const SizedPacketBuf<OtherSize>& other) : PacketView(mData, sizeof(mData)) { copyFrom(other); };
325 
327  SizedPacketBuf& operator=(const SizedPacketBuf& other) { copyFrom(other); return *this; }
328 
330  template<size_t OtherSize>
331  SizedPacketBuf& operator=(const SizedPacketBuf<OtherSize>& other) { copyFrom(other); return *this; }
332 
340  template<class FieldType>
342  const FieldType& field,
343  uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR,
344  typename std::enable_if<std::is_class<FieldType>::value, void>::type* = nullptr
345  ) : PacketView(mData, sizeof(mData))
346  {
347  createFromField<FieldType>(mData, sizeof(mData), field, fieldDescriptor);
348  }
349 
350 
353  PacketView ref() { return *this; }
354 
357  const PacketView& ref() const { return *this; }
358 
361  uint8_t* buffer() { return mData; }
362 
366 
372  void copyFrom(const uint8_t* data, size_t length) { assert(length <= sizeof(mData)); std::memcpy(mData, data, length); }
373 
378  void copyFrom(const PacketView& packet) { assert(packet.isSane()); copyFrom(packet.pointer(), packet.totalLength()); }
379 
380 private:
381  uint8_t mData[BufferSize];
382 };
383 
391 
392 
393 
396 } // namespace mip
mip_packet.h
mip::C::MIP_PACKET_LENGTH_MAX
@ MIP_PACKET_LENGTH_MAX
Definition: mip_offsets.h:28
microstrain::Span::data
constexpr pointer data() const noexcept
Definition: span.hpp:63
mip::C::mip_packet_checksum_value
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
mip::C::mip_packet_cancel_last_field
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
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::PacketView::PacketView
PacketView(const C::mip_packet_view &other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:52
mip::FieldView::next
bool next()
Updates the mip_field to refer to the next field in a packet.
Definition: mip_field.hpp:69
mip::C::mip_packet_from_buffer
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::PacketBuf
SizedPacketBuf< mip::PACKET_LENGTH_MAX > PacketBuf
Typedef for SizedPacketBuf of max possible size.
Definition: mip_packet.hpp:390
mip::PacketView::AllocatedField
Definition: mip_packet.hpp:111
mip::PacketView::FieldIterator
Definition: mip_packet.hpp:238
mip::C::mip_packet_create_field
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::C::MIP_PACKET_LENGTH_MIN
@ MIP_PACKET_LENGTH_MIN
Definition: mip_offsets.h:27
microstrain::Serializer
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:125
mip::PacketView::PacketView
PacketView(const uint8_t *buffer, size_t length)
Initializes a MIP packet from an existing buffer.
Definition: mip_packet.hpp:48
mip::PacketView::addField
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:196
mip::SizedPacketBuf::buffer
uint8_t * buffer()
Returns a pointer to the underlying buffer. This is technically the same as PacketRef::pointer but is...
Definition: mip_packet.hpp:361
mip::C::MIP_PACKET_PAYLOAD_LENGTH_MAX
@ MIP_PACKET_PAYLOAD_LENGTH_MAX
Definition: mip_offsets.h:26
mip::PacketView::FieldIterator::operator*
const FieldView & operator*() const
Dereference the iterator as a Field instance.
Definition: mip_packet.hpp:265
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const PacketView &packet)
Definition: mip_packet.hpp:313
mip::C::mip_packet_remaining_space
int mip_packet_remaining_space(const mip_packet_view *packet)
Returns the remaining space available for more payload data.
Definition: mip_packet.c:246
mip::SizedPacketBuf::copyFrom
void copyFrom(const PacketView &packet)
Copies an existing packet. The packet is assumed to be valid (undefined behavior otherwise).
Definition: mip_packet.hpp:378
mip::PacketView::createField
AllocatedField createField(uint8_t fieldDescriptor)
Definition: mip_packet.hpp:147
mip::PacketView::firstField
FieldView firstField() const
Returns the first field in the packet.
Definition: mip_packet.hpp:184
mip::PacketView::FieldIterator::operator==
bool operator==(const FieldIterator &other) const
Definition: mip_packet.hpp:251
mip::C::mip_packet_reset
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
mip::commands_filter::reset
TypedResult< Reset > reset(C::mip_interface &device)
Definition: commands_filter.cpp:32
mip::PacketView::end
FieldIterator end() const
Definition: mip_packet.hpp:171
mip::PacketView::FieldIterator::operator++
FieldIterator & operator++()
Advance to the next field.
Definition: mip_packet.hpp:268
mip::PacketView::AllocatedField::cancel
void cancel()
Definition: mip_packet.hpp:141
mip::C::mip_packet_pointer
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
mip::C::mip_packet_total_length
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
microstrain::Span::size
constexpr size_t size() const noexcept
Definition: span.hpp:65
mip::C::mip_packet_is_sane
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
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(microstrain::Span< const uint8_t > data)
Construct from a span.
Definition: mip_packet.hpp:316
microstrain::Span
Implementation of std::span from C++20.
Definition: span.hpp:40
serialization.hpp
mip::PacketView::FieldIterator::FieldIterator
FieldIterator()
Empty iterator, which represents the "end" iterator of a packet.
Definition: mip_packet.hpp:242
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
mip::PacketView::PacketView
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
mip::PacketView::copyPacketTo
bool copyPacketTo(uint8_t *buffer, size_t maxLength)
Copies this packet to an external buffer.
Definition: mip_packet.hpp:284
microstrain::SerializerBase::getPtrAndAdvance
uint8_t * getPtrAndAdvance(size_t size)
Obtains a pointer to the current offset for reading/writing a value of specified size,...
Definition: serializer.hpp:88
mip::SizedPacketBuf::SizedPacketBuf
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:341
mip::PacketView::PacketView
PacketView(microstrain::Span< const uint8_t > buffer)
Create a reference to an existing MIP packet.
Definition: mip_packet.hpp:62
mip::C::mip_packet_descriptor_set
uint8_t mip_packet_descriptor_set(const mip_packet_view *packet)
Returns the MIP descriptor set for this packet.
Definition: mip_packet.c:95
mip::C::mip_packet_is_valid
bool mip_packet_is_valid(const mip_packet_view *packet)
Returns true if the packet is valid.
Definition: mip_packet.c:200
mip::SizedPacketBuf
A mip packet with a self-contained buffer (useful with std::vector).
Definition: mip_packet.hpp:303
mip::PacketView::PacketView
PacketView(const C::mip_packet_view *other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:50
mip::C::mip_packet_buffer_size
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
mip::SizedPacketBuf::operator=
SizedPacketBuf & operator=(const SizedPacketBuf &other)
Copy assignment operator.
Definition: mip_packet.hpp:327
mip::commands_3dm::DESCRIPTOR_SET
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
mip::SizedPacketBuf::bufferSpan
microstrain::Span< uint8_t, BufferSize > bufferSpan()
Returns a Span covering the entire buffer.
Definition: mip_packet.hpp:365
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const SizedPacketBuf< OtherSize > &other)
Copy constructor (required to insert packets into std::vector in some cases).
Definition: mip_packet.hpp:324
mip::C::mip_packet_create
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::PacketView::PACKET_SIZE_MIN
static constexpr size_t PACKET_SIZE_MIN
Definition: mip_packet.hpp:39
mip::C::mip_packet_add_field
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
mip::C::mip_packet_update_last_field_length
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
mip::C::mip_packet_payload
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
mip::FieldView
C++ class representing a MIP field.
Definition: mip_field.hpp:25
mip::PacketView::PAYLOAD_LENGTH_MAX
static constexpr size_t PAYLOAD_LENGTH_MAX
Definition: mip_packet.hpp:38
mip::C::mip_packet_compute_checksum
uint16_t mip_packet_compute_checksum(const mip_packet_view *packet)
Computes the checksum of the MIP packet.
Definition: mip_packet.c:160
mip::PacketView::AllocatedField::allocateOrCancel
uint8_t * allocateOrCancel(size_t length)
Definition: mip_packet.hpp:118
mip::FieldView::fieldDescriptor
uint8_t fieldDescriptor() const
Returns the field descriptor.
Definition: mip_field.hpp:46
mip::SizedPacketBuf::operator=
SizedPacketBuf & operator=(const SizedPacketBuf< OtherSize > &other)
Assignment operator, copies data from another buffer to this one.
Definition: mip_packet.hpp:331
mip::PacketView::payloadSpan
microstrain::Span< const uint8_t > payloadSpan() const
Gets a span over just the payload.
Definition: mip_packet.hpp:108
mip::PacketView::copyPacketTo
bool copyPacketTo(microstrain::Span< uint8_t > buffer)
Copies this packet to an external buffer (span version).
Definition: mip_packet.hpp:295
mip::C::mip_field_first_from_packet
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:170
mip::SizedPacketBuf::ref
const PacketView & ref() const
Explicitly obtains a const reference to the packet data.
Definition: mip_packet.hpp:357
mip::PacketView::PACKET_SIZE_MAX
static constexpr size_t PACKET_SIZE_MAX
Definition: mip_packet.hpp:40
mip::PacketView::createFromField
static PacketView createFromField(uint8_t *buffer, size_t bufferSize, 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:222
mip::FieldView::isValid
bool isValid() const
Returns true if the field has a valid field descriptor.
Definition: mip_field.hpp:64
mip_field.hpp
mip::C::mip_packet_payload_length
uint8_t mip_packet_payload_length(const mip_packet_view *packet)
Returns the length of the payload (MIP fields).
Definition: mip_packet.c:103
mip::C::mip_packet_is_empty
bool mip_packet_is_empty(const mip_packet_view *packet)
Returns true if the mip packet contains no payload.
Definition: mip_packet.c:218
mip::PacketView::AllocatedField::operator=
AllocatedField & operator=(const AllocatedField &)=delete
mip::PacketView::FieldIterator::operator==
bool operator==(std::nullptr_t) const
Definition: mip_packet.hpp:261
mip::PacketView::AllocatedField::AllocatedField
AllocatedField(mip::PacketView &packet, uint8_t *buffer, size_t space)
Definition: mip_packet.hpp:114
mip::SizedPacketBuf::copyFrom
void copyFrom(const uint8_t *data, size_t length)
Copies the data from the pointer to this buffer. The data is not inspected.
Definition: mip_packet.hpp:372
mip::PacketView::AllocatedField::commit
bool commit()
Definition: mip_packet.hpp:126
mip::PacketView::FieldIterator::operator!=
bool operator!=(const FieldIterator &other) const
Definition: mip_packet.hpp:257
mip::PacketView::FieldIterator::operator!=
bool operator!=(std::nullptr_t) const
Definition: mip_packet.hpp:262
mip::C::mip_packet_finalize
void mip_packet_finalize(mip_packet_view *packet)
Prepares the packet for transmission by adding the checksum.
Definition: mip_packet.c:451
mip::PacketView::operator[]
uint8_t operator[](unsigned int index) const
Definition: mip_packet.hpp:154
mip::SizedPacketBuf::ref
PacketView ref()
Explicitly obtains a reference to the packet data.
Definition: mip_packet.hpp:353
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const SizedPacketBuf &other)
Copy constructor.
Definition: mip_packet.hpp:319
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET)
Definition: mip_packet.hpp:308
mip::PacketView::FieldIterator::FieldIterator
FieldIterator(const FieldView &first)
Definition: mip_packet.hpp:246
mip::PacketView
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:35
mip::PacketView::begin
FieldIterator begin() const
Definition: mip_packet.hpp:162
mip::PacketView::createField
Serializer createField(uint8_t fieldDescriptor, uint8_t length)
Definition: mip_packet.hpp:88
mip::PacketView::totalSpan
microstrain::Span< const uint8_t > totalSpan() const
Gets a span over the whole packet.
Definition: mip_packet.hpp:104
mip::PacketView::isData
bool isData() const
Definition: mip_packet.hpp:72
mip_offsets.h
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const uint8_t *data, size_t length)
Creates a PacketBuf by copying existing data.
Definition: mip_packet.hpp:312
mip::FieldView::descriptorSet
uint8_t descriptorSet() const
Returns the descriptor set of the packet containing this field._.
Definition: mip_field.hpp:44
microstrain::Serializer::insert
bool insert(const Ts &... values)
Serializes one or more values.
Definition: serializer.hpp:923
mip::C::mip_packet_is_data
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
mip::FieldView::payload
const uint8_t * payload() const
Returns the payload pointer for the field data.
Definition: mip_field.hpp:52
mip::PacketView::PacketView
PacketView(microstrain::Span< uint8_t > buffer, uint8_t descriptorSet)
Create a new MIP packet in an existing buffer.
Definition: mip_packet.hpp:57