mip_packet.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_types.h"
4 
5 #ifdef __cplusplus
6 namespace mip{
7 namespace C {
8 extern "C" {
9 #endif
10 
11 
15 
30 
31 
32 typedef uint_least16_t packet_length;
33 
43 typedef struct mip_packet
44 {
45  uint8_t* _buffer;
46  uint_least16_t _buffer_length;
47 } mip_packet;
48 
49 
59 
60 void mip_packet_create(mip_packet* packet, uint8_t* buffer, size_t buffer_size, uint8_t descriptor_set);
61 
62 bool mip_packet_add_field(mip_packet* packet, uint8_t field_descriptor, const uint8_t* payload, uint8_t payload_length);
63 remaining_count mip_packet_alloc_field(mip_packet* packet, uint8_t field_descriptor, uint8_t payload_length, uint8_t** payload_ptr_out);
64 remaining_count mip_packet_realloc_last_field(mip_packet* packet, uint8_t* payload_ptr, uint8_t new_payload_length);
65 remaining_count mip_packet_cancel_last_field(mip_packet* packet, uint8_t* payload_ptr);
66 
67 void mip_packet_finalize(mip_packet* packet);
68 
69 void mip_packet_reset(mip_packet* packet, uint8_t descriptor_set);
70 
84 
85 void mip_packet_from_buffer(mip_packet* packet, uint8_t* buffer, size_t length);
86 
87 uint8_t mip_packet_descriptor_set(const mip_packet* packet);
88 packet_length mip_packet_total_length(const mip_packet* packet);
89 uint8_t mip_packet_payload_length(const mip_packet* packet);
90 uint8_t* mip_packet_buffer(mip_packet* packet);
91 const uint8_t* mip_packet_pointer(const mip_packet* packet);
92 const uint8_t* mip_packet_payload(const mip_packet* packet);
93 uint16_t mip_packet_checksum_value(const mip_packet* packet);
94 uint16_t mip_packet_compute_checksum(const mip_packet* packet);
95 
96 
97 bool mip_packet_is_sane(const mip_packet* packet);
98 bool mip_packet_is_valid(const mip_packet* packet);
99 bool mip_packet_is_empty(const mip_packet* packet);
100 
101 packet_length mip_packet_buffer_size(const mip_packet* packet);
103 
104 bool mip_packet_is_data(const mip_packet* packet);
105 
110 
111 #ifdef __cplusplus
112 } // namespace mip
113 } // namespace C
114 } // extern "C"
115 #endif
packet_length mip_packet_total_length(const mip_packet *packet)
Returns the total length of the packet, in bytes.
Definition: mip_packet.c:105
uint16_t mip_packet_checksum_value(const mip_packet *packet)
Returns the value of the checksum as written in the packet.
Definition: mip_packet.c:140
void mip_packet_create(mip_packet *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:62
void mip_packet_from_buffer(mip_packet *packet, uint8_t *buffer, size_t length)
Initializes a MIP packet from an existing buffer.
Definition: mip_packet.c:36
uint_least16_t _buffer_length
Length of the buffer (NOT the packet length!).
Definition: mip_packet.h:46
bool mip_packet_is_data(const mip_packet *packet)
Returns true if the packet is from a data descriptor set.
Definition: mip_packet.c:247
struct mip_packet mip_packet
Structure representing a MIP Packet.
Definition: ping.cpp:12
packet_length mip_packet_buffer_size(const mip_packet *packet)
Returns the size of the buffer backing the MIP packet.
Definition: mip_packet.c:224
uint_least16_t packet_length
Type used for the length of a MIP packet.
Definition: mip_packet.h:32
Structure representing a MIP Packet.
Definition: mip_packet.h:43
const uint8_t * mip_packet_payload(const mip_packet *packet)
Returns a pointer to the packet's payload (the first field).
Definition: mip_packet.c:129
uint8_t * mip_packet_buffer(mip_packet *packet)
Returns a writable pointer to the data buffer.
Definition: mip_packet.c:113
void mip_packet_reset(mip_packet *packet, uint8_t descriptor_set)
Reinitialize the packet with the given descriptor set.
Definition: mip_packet.c:457
remaining_count mip_packet_alloc_field(mip_packet *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:327
bool mip_packet_add_field(mip_packet *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:285
int_least16_t remaining_count
Definition: mip_types.h:16
remaining_count mip_packet_realloc_last_field(mip_packet *packet, uint8_t *payload_ptr, uint8_t new_payload_length)
Changes the size of the last field in the packet.
Definition: mip_packet.c:374
void mip_packet_finalize(mip_packet *packet)
Prepares the packet for transmission by adding the checksum.
Definition: mip_packet.c:439
bool mip_packet_is_empty(const mip_packet *packet)
Returns true if the mip packet contains no payload.
Definition: mip_packet.c:210
uint8_t * _buffer
Pointer to the packet data.
Definition: mip_packet.h:45
uint8_t mip_packet_payload_length(const mip_packet *packet)
Returns the length of the payload (MIP fields).
Definition: mip_packet.c:95
remaining_count mip_packet_cancel_last_field(mip_packet *packet, uint8_t *payload_ptr)
Removes the last field from the packet after having allocated it.
Definition: mip_packet.c:410
uint16_t mip_packet_compute_checksum(const mip_packet *packet)
Computes the checksum of the MIP packet.
Definition: mip_packet.c:152
bool mip_packet_is_valid(const mip_packet *packet)
Returns true if the packet is valid.
Definition: mip_packet.c:192
bool mip_packet_is_sane(const mip_packet *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:179
remaining_count mip_packet_remaining_space(const mip_packet *packet)
Returns the remaining space available for more payload data.
Definition: mip_packet.c:234
uint8_t mip_packet_descriptor_set(const mip_packet *packet)
Returns the MIP descriptor set for this packet.
Definition: mip_packet.c:87
const uint8_t * mip_packet_pointer(const mip_packet *packet)
Returns a pointer to the data buffer containing the packet.
Definition: mip_packet.c:121


microstrain_inertial_driver
Author(s): Brian Bingham, Parker Hannifin Corp
autogenerated on Wed Mar 22 2023 02:35:06