MIP_SDK  v4.0.0
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 
8 
9 #include <assert.h>
10 #include <cstring>
11 
12 
13 namespace mip
14 {
18 
19 
35 {
36 public:
37  enum class Index : uint8_t
38  {
44  };
45 
46  static constexpr uint8_t SYNC_1 = C::MIP_SYNC_1;
47  static constexpr uint8_t SYNC_2 = C::MIP_SYNC_2;
48 
49  static constexpr size_t HEADER_LENGTH = C::MIP_PACKET_HEADER_LENGTH;
51  static constexpr size_t LENGTH_MIN = C::MIP_PACKET_LENGTH_MIN;
52  static constexpr size_t LENGTH_MAX = C::MIP_PACKET_LENGTH_MAX;
55 
56  class FieldIterator;
57 
59  PacketView(uint8_t* buffer, size_t bufferSize, uint8_t descriptorSet) { C::mip_packet_create(this, buffer, bufferSize, descriptorSet); }
61  PacketView(const uint8_t* buffer, size_t length) { C::mip_packet_from_buffer(this, const_cast<uint8_t*>(buffer), length); }
63  PacketView(const C::mip_packet_view* other) { std::memcpy(static_cast<C::mip_packet_view*>(this), other, sizeof(*this)); }
65  PacketView(const C::mip_packet_view& other) { std::memcpy(static_cast<C::mip_packet_view*>(this), &other, sizeof(*this)); }
66 
70  PacketView(microstrain::U8ArrayView buffer, uint8_t descriptorSet) { C::mip_packet_create(this, buffer.data(), buffer.size(), descriptorSet); }
71 
76 
77  //
78  // C function wrappers
79  //
80 
81  // General
82  bool isSane() const { return C::mip_packet_is_sane(this); }
83  bool isValid() const { return C::mip_packet_is_valid(this); }
84  bool isEmpty() const { return C::mip_packet_is_empty(this); }
85  bool isData() const { return C::mip_packet_is_data(this); }
86 
87  uint8_t descriptorSet() const { return C::mip_packet_descriptor_set(this); }
88 
89  // Entire buffer
92  uint_least16_t bufferLength() const { return C::mip_packet_buffer_length(this); }
93  int remainingSpace() const { return C::mip_packet_remaining_space(this); }
94 
95  // Entire packet
97  uint_least16_t totalLength() const { return C::mip_packet_total_length(this); }
98 
99  // Payload
102  uint8_t payloadLength() const { return C::mip_packet_payload_length(this); }
103 
104  // Checksum
105  uint16_t checksumValue() const { return C::mip_packet_checksum_value(this); }
106  uint16_t computeChecksum() const { return C::mip_packet_compute_checksum(this); }
107 
108  // Packet building
109  bool addField(uint8_t fieldDescriptor, const uint8_t* payload, uint8_t payloadLength) { return C::mip_packet_add_field(this, fieldDescriptor, payload, payloadLength); }
110  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}; }
111 
112  void finalize() { C::mip_packet_finalize(this); }
113 
114  void reset(uint8_t descSet) { C::mip_packet_reset(this, descSet); }
115  void reset() { reset(descriptorSet()); }
116 
117  //
118  // C++ additions
119  //
120 
121  uint8_t dataAt(const size_t i) const { assert(i < totalLength()); return payload()[i]; }
122  uint8_t& dataAt(const size_t i) { assert(i < totalLength()); return payload_w()[i]; }
123  uint8_t dataAt(const Index i) const { return dataAt(static_cast<size_t>(i)); }
124  uint8_t& dataAt(const Index i) { return dataAt(static_cast<size_t>(i)); }
125 
126  uint8_t payloadAt(const size_t i) const { assert(i < payloadLength()); return C::mip_packet_payload(this)[i]; }
127  uint8_t& payloadAt(const size_t i) { assert(i < payloadLength()); return const_cast<uint8_t&>(C::mip_packet_payload(this)[i]); }
128 
131  bool addField(uint8_t fieldDescriptor, microstrain::ConstU8ArrayView payload) { return addField(fieldDescriptor, payload.data(), uint8_t(payload.size())); }
132 
135  bool addField(const FieldView& field) { return addField(field.fieldDescriptor(), field.payload()); }
136 
137 
138  class AllocatedField : public Serializer
139  {
140  public:
141  AllocatedField(mip::PacketView& packet, uint8_t* buffer, size_t space) : Serializer(buffer, space), m_packet(packet) {}
142  //AllocatedField(const AllocatedField&) = delete;
143  AllocatedField& operator=(const AllocatedField&) = delete;
144 
145  uint8_t* allocateOrCancel(size_t length)
146  {
147  uint8_t* ptr = getPtrAndAdvance(length);
148  if(!ptr)
149  cancel();
150  return ptr;
151  }
152 
153  bool commit()
154  {
155  assert(capacity() <= FieldView::PAYLOAD_LENGTH_MAX);
156 
157  bool ok = isOk();
158 
159  if(ok)
160  ok &= C::mip_packet_update_last_field_length(&m_packet, basePointer(), (uint8_t) usedLength()) >= 0;
161 
162  if(!ok && basePointer())
163  C::mip_packet_cancel_last_field(&m_packet, basePointer());
164 
165  return ok;
166  }
167 
168  void cancel() { if(basePointer()) C::mip_packet_cancel_last_field(&m_packet, basePointer()); }
169 
170  private:
171  PacketView& m_packet;
172  };
173 
174  AllocatedField createField(uint8_t fieldDescriptor)
175  {
176  uint8_t* ptr;
177  size_t max_size = std::max<int>(0, C::mip_packet_create_field(this, fieldDescriptor, 0, &ptr));
178  return {*this, ptr, max_size};
179  }
180 
181  //uint8_t operator[](unsigned int index) const { return payloadAt(index); }
182  //uint8_t& operator[](unsigned int index) { return payloadAt(index); }
183 
184  //
185  // Additional functions which have no C equivalent
186  //
187 
190  FieldIterator begin() const { return firstField(); }
191 
194 #if __cpp_range_based_for >= 201603
195  // After 201603, for loops allow different classes for begin and end.
196  // Using nullptr is simpler and more efficient than creating an end iterator.
197  std::nullptr_t end() const { return nullptr; }
198 #else
199  FieldIterator end() const { return FieldView(); }
200 #endif
201 
213 
223  template<class FieldType>
224  bool addField(const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
225  {
226  if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
227  fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
228 
229  AllocatedField buffer = createField(fieldDescriptor);
230  buffer.insert(field);
231  return buffer.commit();
232  }
233 
248  template<class FieldType>
249  static PacketView createFromField(microstrain::U8ArrayView packetBuffer, const FieldType& field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR)
250  {
251  if( fieldDescriptor == INVALID_FIELD_DESCRIPTOR )
252  fieldDescriptor = FieldType::FIELD_DESCRIPTOR;
253  PacketView packet(packetBuffer, FieldType::DESCRIPTOR_SET);
254  packet.addField<FieldType>(field, fieldDescriptor);
255  packet.finalize();
256  return packet;
257  }
258 
259 
266  {
267  public:
270 
273  FieldIterator(const FieldView& first) : mField(first) {}
274 
278  bool operator==(const FieldIterator& other) const {
279  // Required to make invalid fields equivalent for range-based for loop
280  if( !mField.isValid() && !other.mField.isValid() )
281  return true;
282  return (
283  mField.descriptorSet() == other.mField.descriptorSet() &&
284  mField.fieldDescriptor() == other.mField.fieldDescriptor() &&
285  mField.payload() == other.mField.payload()
286  );
287  }
288  bool operator!=(const FieldIterator& other) const { return !(*this == other); }
289 
292  bool operator==(std::nullptr_t) const { return !mField.isValid(); }
293  bool operator!=(std::nullptr_t) const { return mField.isValid(); }
294 
296  const FieldView& operator*() const { return mField; }
297 
299  FieldIterator& operator++() { mField.next(); return *this; }
300 
301  private:
302  FieldView mField;
303  };
304 
315  {
316  assert(isSane());
317  microstrain::ConstU8ArrayView packet = this->data();
318  if(packet.size() > buffer.size())
319  return false;
320  std::memcpy(buffer.data(), packet.data(), packet.size());
321  return true;
322  }
323 };
324 
325 
329 template<size_t BufferSize>
331 {
332  static_assert(BufferSize >= LENGTH_MIN, "BufferSize must be at least PacketView::LENGTH_MIN bytes");
333 
334 public:
335  explicit SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET) : PacketView(mData, sizeof(mData), descriptorSet) {}
336 
339 
342  explicit SizedPacketBuf(const PacketView& packet) : PacketView(mData, sizeof(mData)) { copyFrom(packet); }
343 
345  SizedPacketBuf(const SizedPacketBuf& other) : PacketView(mData, sizeof(mData)) { copyFrom(other); }
346 
347 
349  template<size_t OtherSize>
350  explicit SizedPacketBuf(const SizedPacketBuf<OtherSize>& other) : PacketView(mData, sizeof(mData)) { copyFrom(other); };
351 
353  SizedPacketBuf& operator=(const SizedPacketBuf& other) { copyFrom(other); return *this; }
354 
356  template<size_t OtherSize>
357  SizedPacketBuf& operator=(const SizedPacketBuf<OtherSize>& other) { copyFrom(other); return *this; }
358 
366  template<class FieldType>
368  const FieldType& field,
369  uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR,
370  typename std::enable_if<std::is_class<FieldType>::value, void>::type* = nullptr
371  ) : PacketView(mData, sizeof(mData))
372  {
373  createFromField<FieldType>({mData, sizeof(mData)}, field, fieldDescriptor);
374  }
375 
376 
379  PacketView ref() { return *this; }
380 
383  const PacketView& ref() const { return *this; }
384 
388 
393  void copyFrom(microstrain::ConstU8ArrayView data) { assert(data.size() <= sizeof(mData)); std::memcpy(mData, data.data(), data.size()); }
394 
399  void copyFrom(const PacketView& packet) { assert(packet.isSane()); copyFrom(packet.data()); }
400 
401 private:
402  uint8_t mData[BufferSize];
403 };
404 
412 
413 
414 
417 } // namespace mip
mip::PacketView::copyPacketTo
bool copyPacketTo(microstrain::U8ArrayView buffer) const
Copies this packet to an external buffer (span version).
Definition: mip_packet.hpp:314
mip_packet.h
mip::PacketView::LENGTH_MAX
static constexpr size_t LENGTH_MAX
Definition: mip_packet.hpp:52
mip::PacketView::HEADER_LENGTH
static constexpr size_t HEADER_LENGTH
Definition: mip_packet.hpp:49
mip::PacketView::PacketView
PacketView(microstrain::U8ArrayView buffer, uint8_t descriptorSet)
Create a new MIP packet in an existing buffer.
Definition: mip_packet.hpp:70
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:164
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:438
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:65
mip::PacketView::SYNC_1
static constexpr uint8_t SYNC_1
Definition: mip_packet.hpp:46
mip::FieldView::next
bool next()
Updates the mip_field to refer to the next field in a packet.
Definition: mip_field.hpp:106
mip::FieldView::payload
microstrain::ConstU8ArrayView payload() const
Get a const view of the payload data.
Definition: mip_field.hpp:70
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(microstrain::ConstU8ArrayView data)
Construct by copying an existing buffer.
Definition: mip_packet.hpp:338
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::C::MIP_PACKET_HEADER_LENGTH
@ MIP_PACKET_HEADER_LENGTH
Definition: mip_packet.h:80
mip::PacketView::AllocatedField
Definition: mip_packet.hpp:138
mip::PacketView::FieldIterator
Definition: mip_packet.hpp:265
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:355
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:61
mip::C::MIP_PACKET_LENGTH_MIN
@ MIP_PACKET_LENGTH_MIN
Definition: mip_packet.h:84
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:224
mip::PacketView::Index::SYNC_1
@ SYNC_1
mip::PacketView::FieldIterator::operator*
const FieldView & operator*() const
Dereference the iterator as a Field instance.
Definition: mip_packet.hpp:296
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const PacketView &packet)
Creates a PacketBuf by copying an existing packet.
Definition: mip_packet.hpp:342
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:262
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:399
mip::PacketView::createField
AllocatedField createField(uint8_t fieldDescriptor)
Definition: mip_packet.hpp:174
mip::PacketView::firstField
FieldView firstField() const
Returns the first field in the packet.
Definition: mip_packet.hpp:212
mip::PacketView::FieldIterator::operator==
bool operator==(const FieldIterator &other) const
Definition: mip_packet.hpp:278
mip::PacketView::addField
bool addField(uint8_t fieldDescriptor, microstrain::ConstU8ArrayView payload)
Get writable payload byte at index i.
Definition: mip_packet.hpp:131
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:485
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:199
mip::PacketView::FieldIterator::operator++
FieldIterator & operator++()
Advance to the next field.
Definition: mip_packet.hpp:299
mip::PacketView::AllocatedField::cancel
void cancel()
Definition: mip_packet.hpp:168
mip::C::MIP_PACKET_INDEX_SYNC_1
@ MIP_PACKET_INDEX_SYNC_1
Definition: mip_packet.h:71
mip::C::MIP_SYNC_2
@ MIP_SYNC_2
Definition: mip_packet.h:91
mip::C::mip_packet_payload_w
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
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_INDEX_LENGTH
@ MIP_PACKET_INDEX_LENGTH
Definition: mip_packet.h:74
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:203
serialization.hpp
mip::PacketView::FieldIterator::FieldIterator
FieldIterator()
Empty iterator, which represents the "end" iterator of a packet.
Definition: mip_packet.hpp:269
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:63
mip::PacketView::payloadAt
uint8_t payloadAt(const size_t i) const
Definition: mip_packet.hpp:126
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:59
mip::PacketView::addField
bool addField(const FieldView &field)
Copies the given mip field to the packet.
Definition: mip_packet.hpp:135
mip::C::mip_packet_buffer
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::C::MIP_PACKET_INDEX_DESC_SET
@ MIP_PACKET_INDEX_DESC_SET
Definition: mip_packet.h:73
mip::FieldView::PAYLOAD_LENGTH_MAX
static constexpr size_t PAYLOAD_LENGTH_MAX
Definition: mip_field.hpp:38
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:367
mip::C::mip_packet_buffer_w
uint8_t * mip_packet_buffer_w(mip_packet_view *packet)
Returns a writable pointer to the data buffer.
Definition: mip_packet.c:129
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:216
mip::SizedPacketBuf
A mip packet with a self-contained buffer (useful with std::vector).
Definition: mip_packet.hpp:330
mip::PacketView::PacketView
PacketView(const C::mip_packet_view *other)
Constructs a C++ PacketRef class from the base C object.
Definition: mip_packet.hpp:63
mip::C::MIP_PACKET_PAYLOAD_LENGTH_MAX
@ MIP_PACKET_PAYLOAD_LENGTH_MAX
Definition: mip_packet.h:83
mip::SizedPacketBuf::operator=
SizedPacketBuf & operator=(const SizedPacketBuf &other)
Copy assignment operator.
Definition: mip_packet.hpp:353
mip::C::MIP_SYNC_1
@ MIP_SYNC_1
Definition: mip_packet.h:90
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const SizedPacketBuf< OtherSize > &other)
Copy constructor (required to insert packets into std::vector in some cases).
Definition: mip_packet.hpp:350
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::C::MIP_PACKET_INDEX_SYNC_2
@ MIP_PACKET_INDEX_SYNC_2
Definition: mip_packet.h:72
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:313
mip::INVALID_FIELD_DESCRIPTOR
static constexpr uint8_t INVALID_FIELD_DESCRIPTOR
Definition: mip_descriptors.hpp:75
mip::C::MIP_PACKET_INDEX_PAYLOAD
@ MIP_PACKET_INDEX_PAYLOAD
Definition: mip_packet.h:75
mip::PacketView::Index
Index
Definition: mip_packet.hpp:37
mip::PacketView::dataAt
uint8_t dataAt(const size_t i) const
Definition: mip_packet.hpp:121
mip::PacketView::SYNC_2
static constexpr uint8_t SYNC_2
Definition: mip_packet.hpp:47
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:402
mip::SizedPacketBuf::buffer
microstrain::ArrayView< uint8_t, BufferSize > buffer()
Returns an ArrayView covering the entire buffer.
Definition: mip_packet.hpp:387
mip::PacketView::payload_w
microstrain::U8ArrayView payload_w()
Get the payload as raw bytes.
Definition: mip_packet.hpp:101
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:145
mip::PacketView::PAYLOAD_LENGTH_MIN
static constexpr size_t PAYLOAD_LENGTH_MIN
Definition: mip_packet.hpp:53
mip::FieldView
C++ class representing a MIP field.
Definition: mip_field.hpp:24
mip::PacketView::buffer_w
microstrain::U8ArrayView buffer_w()
Gets the entire storage buffer for the packet.
Definition: mip_packet.hpp:91
mip::PacketView::PAYLOAD_LENGTH_MAX
static constexpr size_t PAYLOAD_LENGTH_MAX
Definition: mip_packet.hpp:54
mip::C::MIP_PACKET_CHECKSUM_LENGTH
@ MIP_PACKET_CHECKSUM_LENGTH
Definition: mip_packet.h:81
mip::PacketBuf
SizedPacketBuf< PacketView::LENGTH_MAX > PacketBuf
Typedef for SizedPacketBuf of max possible size.
Definition: mip_packet.hpp:411
mip::PacketView::CHECKSUM_LENGTH
static constexpr size_t CHECKSUM_LENGTH
Definition: mip_packet.hpp:50
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:176
mip::PacketView::Index::SYNC_2
@ SYNC_2
mip::PacketView::AllocatedField::allocateOrCancel
uint8_t * allocateOrCancel(size_t length)
Definition: mip_packet.hpp:145
mip::FieldView::fieldDescriptor
uint8_t fieldDescriptor() const
Returns the field descriptor.
Definition: mip_field.hpp:59
mip::SizedPacketBuf::operator=
SizedPacketBuf & operator=(const SizedPacketBuf< OtherSize > &other)
Assignment operator, copies data from another buffer to this one.
Definition: mip_packet.hpp:357
mip::commands_3dm::DESCRIPTOR_SET
@ DESCRIPTOR_SET
Definition: commands_3dm.hpp:31
mip::PacketView::Index::LENGTH
@ LENGTH
mip::PacketView::payload
microstrain::ConstU8ArrayView payload() const
Definition: mip_packet.hpp:100
mip::PacketView::dataAt
uint8_t dataAt(const Index i) const
Definition: mip_packet.hpp:123
mip::PacketView::dataAt
uint8_t & dataAt(const Index i)
Definition: mip_packet.hpp:124
mip::PacketView::Index::DESC_SET
@ DESC_SET
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:177
microstrain::ArrayView::data
constexpr pointer data() const noexcept
Definition: array_view.hpp:69
mip::PacketView::LENGTH_MIN
static constexpr size_t LENGTH_MIN
Definition: mip_packet.hpp:51
mip::PacketView::PacketView
PacketView(microstrain::ConstU8ArrayView buffer)
Create a reference to an existing MIP packet.
Definition: mip_packet.hpp:75
mip::SizedPacketBuf::ref
const PacketView & ref() const
Explicitly obtains a const reference to the packet data.
Definition: mip_packet.hpp:383
mip::FieldView::isValid
bool isValid() const
Returns true if the field has a valid field descriptor.
Definition: mip_field.hpp:101
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_LENGTH_MAX
@ MIP_PACKET_LENGTH_MAX
Definition: mip_packet.h:85
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:234
mip::PacketView::AllocatedField::operator=
AllocatedField & operator=(const AllocatedField &)=delete
mip::PacketView::FieldIterator::operator==
bool operator==(std::nullptr_t) const
Definition: mip_packet.hpp:292
mip::PacketView::AllocatedField::AllocatedField
AllocatedField(mip::PacketView &packet, uint8_t *buffer, size_t space)
Definition: mip_packet.hpp:141
mip::PacketView::data
microstrain::ConstU8ArrayView data() const
Definition: mip_packet.hpp:96
mip::PacketView::AllocatedField::commit
bool commit()
Definition: mip_packet.hpp:153
mip::PacketView::payloadAt
uint8_t & payloadAt(const size_t i)
Get payload byte at index i.
Definition: mip_packet.hpp:127
mip::C::mip_packet_buffer_length
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
mip::PacketView::FieldIterator::operator!=
bool operator!=(const FieldIterator &other) const
Definition: mip_packet.hpp:288
mip::PacketView::Index::PAYLOAD
@ PAYLOAD
mip::PacketView::createFromField
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
mip::INVALID_DESCRIPTOR_SET
static constexpr uint8_t INVALID_DESCRIPTOR_SET
Definition: mip_descriptors.hpp:76
mip::C::MIP_PACKET_PAYLOAD_LENGTH_MIN
@ MIP_PACKET_PAYLOAD_LENGTH_MIN
Definition: mip_packet.h:82
mip::PacketView::FieldIterator::operator!=
bool operator!=(std::nullptr_t) const
Definition: mip_packet.hpp:293
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:467
mip::SizedPacketBuf::ref
PacketView ref()
Explicitly obtains a reference to the packet data.
Definition: mip_packet.hpp:379
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(const SizedPacketBuf &other)
Copy constructor.
Definition: mip_packet.hpp:345
mip::SizedPacketBuf::SizedPacketBuf
SizedPacketBuf(uint8_t descriptorSet=INVALID_DESCRIPTOR_SET)
Definition: mip_packet.hpp:335
mip::C::mip_packet_data
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
mip::PacketView::FieldIterator::FieldIterator
FieldIterator(const FieldView &first)
Definition: mip_packet.hpp:273
mip::PacketView
C++ class representing a view of a MIP packet.
Definition: mip_packet.hpp:34
mip::PacketView::begin
FieldIterator begin() const
Definition: mip_packet.hpp:190
mip::PacketView::createField
Serializer createField(uint8_t fieldDescriptor, uint8_t length)
Definition: mip_packet.hpp:110
mip::PacketView::dataAt
uint8_t & dataAt(const size_t i)
Definition: mip_packet.hpp:122
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:393
microstrain::ArrayView::size
constexpr size_t size() const noexcept
Definition: array_view.hpp:71
mip::FieldView::descriptorSet
uint8_t descriptorSet() const
Returns the descriptor set of the packet containing this field._.
Definition: mip_field.hpp:57
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:275
mip::PacketView::buffer
microstrain::ConstU8ArrayView buffer() const
Definition: mip_packet.hpp:90