MIP_SDK  v3.0.0
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 
39 
40 
50 typedef struct mip_packet_view
51 {
52  uint8_t* _buffer;
53  uint_least16_t _buffer_length;
55 
56 
67 
68 void mip_packet_create(mip_packet_view* packet, uint8_t* buffer, size_t buffer_size, uint8_t descriptor_set);
69 
70 bool mip_packet_add_field(mip_packet_view* packet, uint8_t field_descriptor, const uint8_t* payload, uint8_t payload_length);
71 int mip_packet_create_field(mip_packet_view* packet, uint8_t field_descriptor, uint8_t payload_length, uint8_t** payload_ptr_out);
72 int mip_packet_update_last_field_length(mip_packet_view* packet, uint8_t* payload_ptr, uint8_t new_payload_length);
73 int mip_packet_cancel_last_field(mip_packet_view* packet, uint8_t* payload_ptr);
74 
76 
77 void mip_packet_reset(mip_packet_view* packet, uint8_t descriptor_set);
78 
97 
98 void mip_packet_from_buffer(mip_packet_view* packet, const uint8_t* buffer, size_t length);
99 
100 uint8_t mip_packet_descriptor_set(const mip_packet_view* packet);
101 uint_least16_t mip_packet_total_length(const mip_packet_view* packet);
102 uint8_t mip_packet_payload_length(const mip_packet_view* packet);
103 uint8_t* mip_packet_buffer(mip_packet_view* packet);
104 const uint8_t* mip_packet_pointer(const mip_packet_view* packet);
105 const uint8_t* mip_packet_payload(const mip_packet_view* packet);
106 uint16_t mip_packet_checksum_value(const mip_packet_view* packet);
107 uint16_t mip_packet_compute_checksum(const mip_packet_view* packet);
108 
109 
110 bool mip_packet_is_sane(const mip_packet_view* packet);
111 bool mip_packet_is_valid(const mip_packet_view* packet);
112 bool mip_packet_is_empty(const mip_packet_view* packet);
113 
114 uint_least16_t mip_packet_buffer_size(const mip_packet_view* packet);
116 
117 bool mip_packet_is_data(const mip_packet_view* packet);
118 
120 
124 
125 #ifdef __cplusplus
126 } // extern "C"
127 } // namespace C
128 } // namespace mip
129 #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: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::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_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_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:246
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
microstrain::C::microstrain_serializer
struct microstrain::C::microstrain_serializer microstrain_serializer
Structure used for serialization.
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
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
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::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::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_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::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::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::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::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:259
microstrain
Definition: embedded_time.h:8