MIP_SDK  v3.0.0-736-g212583cf
MicroStrain Communications Library for embedded systems
mip_packet.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_types.h"
4 
5 #ifdef __cplusplus
6 
7 namespace microstrain {
8 namespace C {
10 }
11 }
12 
13 namespace mip {
14 namespace C {
15 extern "C" {
16 #else
18 #endif
19 
20 
24 
52 
53 
63 typedef struct mip_packet_view
64 {
65  uint8_t* _buffer;
66  uint_least16_t _buffer_length;
68 
69 typedef enum mip_packet_index
70 {
77 
79 {
87 
89 {
90  MIP_SYNC_1 = 0x75,
91  MIP_SYNC_2 = 0x65
93 
104 
105 void mip_packet_create(mip_packet_view* packet, uint8_t* buffer, size_t buffer_size, uint8_t descriptor_set);
106 
107 bool mip_packet_add_field(mip_packet_view* packet, uint8_t field_descriptor, const uint8_t* payload, uint8_t payload_length);
108 int mip_packet_create_field(mip_packet_view* packet, uint8_t field_descriptor, uint8_t payload_length, uint8_t** payload_ptr_out);
109 int mip_packet_update_last_field_length(mip_packet_view* packet, uint8_t* payload_ptr, uint8_t new_payload_length);
110 int mip_packet_cancel_last_field(mip_packet_view* packet, uint8_t* payload_ptr);
111 
113 
114 void mip_packet_reset(mip_packet_view* packet, uint8_t descriptor_set);
115 
134 
135 void mip_packet_from_buffer(mip_packet_view* packet, const uint8_t* buffer, size_t length);
136 
137 uint8_t mip_packet_descriptor_set(const mip_packet_view* packet);
138 uint_least16_t mip_packet_total_length(const mip_packet_view* packet);
139 uint8_t mip_packet_payload_length(const mip_packet_view* packet);
140 const uint8_t* mip_packet_buffer(const mip_packet_view* packet);
141 uint8_t* mip_packet_buffer_w(mip_packet_view* packet);
142 const uint8_t* mip_packet_data(const mip_packet_view* packet);
143 const uint8_t* mip_packet_payload(const mip_packet_view* packet);
144 uint8_t* mip_packet_payload_w(mip_packet_view* packet);
145 uint16_t mip_packet_checksum_value(const mip_packet_view* packet);
146 uint16_t mip_packet_compute_checksum(const mip_packet_view* packet);
147 
148 
149 bool mip_packet_is_sane(const mip_packet_view* packet);
150 bool mip_packet_is_valid(const mip_packet_view* packet);
151 bool mip_packet_is_empty(const mip_packet_view* packet);
152 
153 uint_least16_t mip_packet_buffer_length(const mip_packet_view* packet);
155 
156 bool mip_packet_is_data(const mip_packet_view* packet);
157 
159 
163 
164 #ifdef __cplusplus
165 } // extern "C"
166 } // namespace C
167 } // namespace mip
168 #endif
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::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::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
mip::C::MIP_PACKET_LENGTH_MIN
@ MIP_PACKET_LENGTH_MIN
Definition: mip_packet.h:84
mip_types.h
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::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::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
microstrain::C::microstrain_serializer
struct microstrain::C::microstrain_serializer microstrain_serializer
Structure used for serialization.
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
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:63
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::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::C::MIP_PACKET_PAYLOAD_LENGTH_MAX
@ MIP_PACKET_PAYLOAD_LENGTH_MAX
Definition: mip_packet.h:83
mip::C::MIP_SYNC_1
@ MIP_SYNC_1
Definition: mip_packet.h:90
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::C::MIP_PACKET_INDEX_PAYLOAD
@ MIP_PACKET_INDEX_PAYLOAD
Definition: mip_packet.h:75
mip::C::mip_packet_index
mip_packet_index
Definition: mip_packet.h:69
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::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::C::MIP_PACKET_CHECKSUM_LENGTH
@ MIP_PACKET_CHECKSUM_LENGTH
Definition: mip_packet.h:81
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::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_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::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::C::mip_packet_sync_byte
mip_packet_sync_byte
Definition: mip_packet.h:88
mip::C::MIP_PACKET_PAYLOAD_LENGTH_MIN
@ MIP_PACKET_PAYLOAD_LENGTH_MIN
Definition: mip_packet.h:82
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::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::C::mip_packet_view
struct mip::C::mip_packet_view mip_packet_view
Structure representing a MIP Packet.
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
microstrain
Definition: embedded_time.h:8
mip::C::mip_packet_index_length
mip_packet_index_length
Definition: mip_packet.h:78