MIP_SDK  v3.0.0-534-g6be5866
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::U8ArrayView buffer, uint8_t descriptorSet) { C::mip_packet_create(this, buffer.data(), buffer.size(), descriptorSet); }
58 
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* payloadPointer() const { return C::mip_packet_payload(this); }
76  uint8_t payload(size_t i) const { assert(i < payloadLength()); return payloadPointer()[i]; }
77 
78  uint16_t checksumValue() const { return C::mip_packet_checksum_value(this); }
79  uint16_t computeChecksum() const { return C::mip_packet_compute_checksum(this); }
80 
81  bool isSane() const { return C::mip_packet_is_sane(this); }
82  bool isValid() const { return C::mip_packet_is_valid(this); }
83  bool isEmpty() const { return C::mip_packet_is_empty(this); }
84 
85  const uint8_t* bufferPointer() const { return C::mip_packet_buffer(const_cast<PacketView*>(this)); }
86  uint8_t* bufferPointerWr() { return C::mip_packet_buffer(this); }
87  uint_least16_t bufferLength() const { return C::mip_packet_buffer_size(this); }
88  int remainingSpace() const { return C::mip_packet_remaining_space(this); }
89 
90  bool addField(uint8_t fieldDescriptor, const uint8_t* payload, uint8_t payloadLength) { return C::mip_packet_add_field(this, fieldDescriptor, payload, payloadLength); }
91  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}; }
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::ConstU8ArrayView data() const { return {pointer(), totalLength()}; }
105 
108  microstrain::ConstU8ArrayView payload() const { return {payloadPointer(), payloadLength()}; }
109 
111  microstrain::ConstU8ArrayView buffer() const { return {bufferPointer(), bufferLength()}; }
112 
115  microstrain::U8ArrayView bufferWr() { return {bufferPointerWr(), bufferLength()}; }
116 
119  bool addField(const FieldView& field) { return addField(field.fieldDescriptor(), field.payload()); }
120 
123  bool addField(uint8_t fieldDescriptor, microstrain::ConstU8ArrayView payload) { return addField(fieldDescriptor, payload.data(), uint8_t(payload.size())); }
124 
125 
126  class AllocatedField : public Serializer
127  {
128  public:
129  AllocatedField(mip::PacketView& packet, uint8_t* buffer, size_t space) : Serializer(buffer, space), m_packet(packet) {}
130  //AllocatedField(const AllocatedField&) = delete;
131  AllocatedField& operator=(const AllocatedField&) = delete;
132 
133  uint8_t* allocateOrCancel(size_t length)
134  {
135  uint8_t* ptr = getPtrAndAdvance(length);
136  if(!ptr)
137  cancel();
138  return ptr;
139  }
140 
141  bool commit()
142  {
143  assert(capacity() <= FIELD_PAYLOAD_LENGTH_MAX);
144 
145  bool ok = isOk();
146 
147  if(ok)
148  ok &= C::mip_packet_update_last_field_length(&m_packet, basePointer(), (uint8_t) usedLength()) >= 0;
149 
150  if(!ok && basePointer())
151  C::mip_packet_cancel_last_field(&m_packet, basePointer());
152 
153  return ok;
154  }
155 
156  void cancel() { if(basePointer()) C::mip_packet_cancel_last_field(&m_packet, basePointer()); }
157 
158  private:
159  PacketView& m_packet;
160  };
161 
162  AllocatedField createField(uint8_t fieldDescriptor)
163  {
164  uint8_t* ptr;
165  size_t max_size = std::max<int>(0, C::mip_packet_create_field(this, fieldDescriptor, 0, &ptr));
166  return {*this, ptr, max_size};
167  }
168 
169  uint8_t operator[](unsigned int index) const { return pointer()[index]; }
170 
171  //
172  // Additional functions which have no C equivalent
173  //
174 
177  FieldIterator begin() const { return firstField(); }
178 
181 #if __cpp_range_based_for >= 201603
182  // After 201603, for loops allow different clases for begin and end.
183  // Using nullptr is simpler and more efficient than creating an end iterator.
184  std::nullptr_t end() const { return nullptr; }
185 #else
186  FieldIterator end() const { return FieldView(); }
187 #endif
188 
200 
210  template<class FieldType>
211  bool addField(const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
212  {
213  if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
214  fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
215 
216  AllocatedField buffer = createField(fieldDescriptor);
217  buffer.insert(field);
218  return buffer.commit();
219  }
220 
235  template<class FieldType>
236  static PacketView createFromField(microstrain::ConstU8ArrayView packetBuffer, const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
237  {
238  if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
239  fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
240  PacketView packet(packetBuffer, FieldType::DESCRIPTOR_SET);
241  packet.addField<FieldType>(field, fieldDescriptor);
242  packet.finalize();
243  return packet;
244  }
245 
246 
253  {
254  public:
257 
260  FieldIterator(const FieldView& first) : mField(first) {}
261 
265  bool operator==(const FieldIterator& other) const {
266  // Required to make invalid fields equivalent for range-based for loop
267  if( !mField.isValid() && !other.mField.isValid() )
268  return true;
269  return (
270  mField.descriptorSet() == other.mField.descriptorSet() &&
271  mField.fieldDescriptor() == other.mField.fieldDescriptor() &&
272  mField.payloadPointer() == other.mField.payloadPointer()
273  );
274  }
275  bool operator!=(const FieldIterator& other) const { return !(*this == other); }
276 
279  bool operator==(std::nullptr_t) const { return !mField.isValid(); }
280  bool operator!=(std::nullptr_t) const { return mField.isValid(); }
281 
283  const FieldView& operator*() const { return mField; }
284 
286  FieldIterator& operator++() { mField.next(); return *this; }
287 
288  private:
289  FieldView mField;
290  };
291 
302  {
303  assert(isSane());
304  microstrain::ConstU8ArrayView packet = this->data();
305  if(packet.size() > buffer.size())
306  return false;
307  std::memcpy(buffer.data(), packet.data(), packet.size());
308  return true;
309  }
310 };
311 
312 
316 template<size_t BufferSize>
318 {
319  static_assert(BufferSize >= PACKET_LENGTH_MIN, "BufferSize must be at least PACKET_LENGTH_MIN bytes");
320 
321 public:
322  explicit SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET) : PacketView(mData, sizeof(mData), descriptorSet) {}
323 
326 
329  explicit SizedPacketBuf(const PacketView& packet) : PacketView(mData, sizeof(mData)) { copyFrom(packet); }
330 
332  SizedPacketBuf(const SizedPacketBuf& other) : PacketView(mData, sizeof(mData)) { copyFrom(other); }
333 
334 
336  template<size_t OtherSize>
337  explicit SizedPacketBuf(const SizedPacketBuf<OtherSize>& other) : PacketView(mData, sizeof(mData)) { copyFrom(other); };
338 
340  SizedPacketBuf& operator=(const SizedPacketBuf& other) { copyFrom(other); return *this; }
341 
343  template<size_t OtherSize>
344  SizedPacketBuf& operator=(const SizedPacketBuf<OtherSize>& other) { copyFrom(other); return *this; }
345 
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
358  ) : PacketView(mData, sizeof(mData))
359  {
360  createFromField<FieldType>(mData, sizeof(mData), field, fieldDescriptor);
361  }
362 
363 
366  PacketView ref() { return *this; }
367 
370  const PacketView& ref() const { return *this; }
371 
374  uint8_t* bufferPointer() { return mData; }
375 
379 
384  void copyFrom(microstrain::ConstU8ArrayView data) { assert(data.size() <= sizeof(mData)); std::memcpy(mData, data.data(), data.size()); }
385 
390  void copyFrom(const PacketView& packet) { assert(packet.isSane()); copyFrom(packet.data()); }
391 
392 private:
393  uint8_t mData[BufferSize];
394 };
395 
403 
404 
405 
408 } // namespace mip
mip::PacketView::copyPacketTo
bool copyPacketTo(microstrain::U8ArrayView buffer) const
Copies this packet to an external buffer (span version).
Definition: mip_packet.hpp:301
mip_packet.h
mip::C::MIP_PACKET_LENGTH_MAX
@ MIP_PACKET_LENGTH_MAX
Definition: mip_offsets.h:28
mip::PacketView::PacketView
PacketView(microstrain::U8ArrayView buffer, uint8_t descriptorSet)
Create a new MIP packet in an existing buffer.
Definition: mip_packet.hpp:57
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::C::mip_packet_buffer
uint8_t * mip_packet_buffer(mip_packet_view *packet)
Returns a writable pointer to the data buffer.
Definition: mip_packet.c:121
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:93
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(microstrain::ConstU8ArrayView data)
Construct by copying an existing buffer.
Definition: mip_packet.hpp:325
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:402
mip::PacketView::AllocatedField
Definition: mip_packet.hpp:126
mip::PacketView::FieldIterator
Definition: mip_packet.hpp:252
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
mip::PacketView::createFromField
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
microstrain::Serializer
Serializes or deserializes data to/from a byte buffer.
Definition: serializer.hpp:135
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:211
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:283
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const PacketView &packet)
Creates a PacketBuf by copying an existing packet.
Definition: mip_packet.hpp:329
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:390
mip::PacketView::createField
AllocatedField createField(uint8_t fieldDescriptor)
Definition: mip_packet.hpp:162
mip::PacketView::firstField
FieldView firstField() const
Returns the first field in the packet.
Definition: mip_packet.hpp:199
mip::PacketView::FieldIterator::operator==
bool operator==(const FieldIterator &other) const
Definition: mip_packet.hpp:265
mip::PacketView::addField
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
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:186
mip::PacketView::FieldIterator::operator++
FieldIterator & operator++()
Advance to the next field.
Definition: mip_packet.hpp:286
mip::PacketView::AllocatedField::cancel
void cancel()
Definition: mip_packet.hpp:156
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
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
serialization.hpp
mip::PacketView::FieldIterator::FieldIterator
FieldIterator()
Empty iterator, which represents the "end" iterator of a packet.
Definition: mip_packet.hpp:256
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::addField
bool addField(const FieldView &field)
Copies the given mip field to the packet.
Definition: mip_packet.hpp:119
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:98
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:354
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:317
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:340
mip::commands_3dm::DESCRIPTOR_SET
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const SizedPacketBuf< OtherSize > &other)
Copy constructor (required to insert packets into std::vector in some cases).
Definition: mip_packet.hpp:337
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::PacketView::bufferPointer
const uint8_t * bufferPointer() const
Definition: mip_packet.hpp:85
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::SizedPacketBuf::buffer
microstrain::ArrayView< uint8_t, BufferSize > buffer()
Returns a Span covering the entire buffer.
Definition: mip_packet.hpp:378
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::PacketView::bufferWr
microstrain::U8ArrayView bufferWr()
Gets a writeable view to the entire storage buffer (usually more than just the packet).
Definition: mip_packet.hpp:115
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::SizedPacketBuf::bufferPointer
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
mip::PacketView::payload
uint8_t payload(size_t i) const
Get a pointer to the payload data.
Definition: mip_packet.hpp:76
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:133
mip::FieldView::fieldDescriptor
uint8_t fieldDescriptor() const
Returns the field descriptor.
Definition: mip_field.hpp:49
mip::SizedPacketBuf::operator=
SizedPacketBuf & operator=(const SizedPacketBuf< OtherSize > &other)
Assignment operator, copies data from another buffer to this one.
Definition: mip_packet.hpp:344
mip::PacketView::bufferPointerWr
uint8_t * bufferPointerWr()
Returns a writable pointer to the data buffer.
Definition: mip_packet.hpp:86
mip::PacketView::payload
microstrain::ConstU8ArrayView payload() const
Gets a const byte view of just the payload.
Definition: mip_packet.hpp:108
mip::FieldView::payload
uint8_t payload(size_t index) const
Index the payload at the given location.
Definition: mip_field.hpp:62
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:178
microstrain::ArrayView::data
constexpr pointer data() const noexcept
Definition: array_view.hpp:69
mip::PacketView::PacketView
PacketView(microstrain::ConstU8ArrayView buffer)
Create a reference to an existing MIP packet.
Definition: mip_packet.hpp:62
mip::SizedPacketBuf::ref
const PacketView & ref() const
Explicitly obtains a const reference to the packet data.
Definition: mip_packet.hpp:370
mip::PacketView::PACKET_SIZE_MAX
static constexpr size_t PACKET_SIZE_MAX
Definition: mip_packet.hpp:40
mip::FieldView::isValid
bool isValid() const
Returns true if the field has a valid field descriptor.
Definition: mip_field.hpp:88
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
microstrain::ArrayView
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::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:279
mip::PacketView::AllocatedField::AllocatedField
AllocatedField(mip::PacketView &packet, uint8_t *buffer, size_t space)
Definition: mip_packet.hpp:129
mip::FieldView::payloadPointer
const uint8_t * payloadPointer() const
Returns the payload pointer for the field data.
Definition: mip_field.hpp:57
mip::PacketView::data
microstrain::ConstU8ArrayView data() const
Gets a const byte view for the whole packet.
Definition: mip_packet.hpp:104
mip::PacketView::AllocatedField::commit
bool commit()
Definition: mip_packet.hpp:141
mip::PacketView::FieldIterator::operator!=
bool operator!=(const FieldIterator &other) const
Definition: mip_packet.hpp:275
mip::PacketView::FieldIterator::operator!=
bool operator!=(std::nullptr_t) const
Definition: mip_packet.hpp:280
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:169
mip::SizedPacketBuf::ref
PacketView ref()
Explicitly obtains a reference to the packet data.
Definition: mip_packet.hpp:366
mip::PacketView::pointer
const uint8_t * pointer() const
Definition: mip_packet.hpp:74
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const SizedPacketBuf &other)
Copy constructor.
Definition: mip_packet.hpp:332
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET)
Definition: mip_packet.hpp:322
mip::PacketView::FieldIterator::FieldIterator
FieldIterator(const FieldView &first)
Definition: mip_packet.hpp:260
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:177
mip::PacketView::createField
Serializer createField(uint8_t fieldDescriptor, uint8_t length)
Definition: mip_packet.hpp:91
mip::SizedPacketBuf::copyFrom
void copyFrom(microstrain::ConstU8ArrayView data)
Copies the data from a U8ArrayView to this buffer. The data is not inspected.
Definition: mip_packet.hpp:384
microstrain::ArrayView::size
constexpr size_t size() const noexcept
Definition: array_view.hpp:71
mip::PacketView::isData
bool isData() const
Definition: mip_packet.hpp:72
mip_offsets.h
mip::FieldView::descriptorSet
uint8_t descriptorSet() const
Returns the descriptor set of the packet containing this field._.
Definition: mip_field.hpp:47
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::PacketView::buffer
microstrain::ConstU8ArrayView buffer() const
Gets a const view to the entire storage buffer (usually more than just the packet).
Definition: mip_packet.hpp:111
mip::PacketView::payloadPointer
const uint8_t * payloadPointer() const
Get a pointer to the entire packet data.
Definition: mip_packet.hpp:75