MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
mip_parser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "mip_packet.h"
4 #include "mip_offsets.h"
5 
6 #include "utils/byte_ring.h"
7 #include "mip_types.h"
8 
9 #ifdef __cplusplus
10 namespace mip {
11 namespace C {
12 extern "C" {
13 #endif
14 
21 
22 
39 
40 
45 typedef bool (*mip_packet_callback)(void* user, const mip_packet_view* packet, mip_timestamp timestamp);
46 
47 
55 typedef struct mip_parser
56 {
57  mip_timestamp _start_time;
58  mip_timestamp _timeout;
59  uint8_t _result_buffer[MIP_PACKET_LENGTH_MAX];
60  uint16_t _expected_length;
61  byte_ring_state _ring;
62  mip_packet_callback _callback;
63  void* _callback_object;
64 
65 #ifdef MIP_ENABLE_DIAGNOSTICS
66  uint32_t _diag_bytes_read;
67  uint32_t _diag_bytes_skipped;
68  uint32_t _diag_packet_bytes;
69  uint32_t _diag_valid_packets;
70  uint32_t _diag_invalid_packets;
71  uint32_t _diag_timeouts;
72 #endif // MIP_ENABLE_DIAGNOSTICS
73 
74 } mip_parser;
75 
76 
77 
78 #define MIPPARSER_UNLIMITED_PACKETS 0
79 #define MIPPARSER_DEFAULT_TIMEOUT_MS 100
80 
81 
82 void mip_parser_init(mip_parser* parser, uint8_t* buffer, size_t buffer_size, mip_packet_callback callback, void* callback_object, mip_timestamp timeout);
84 size_t mip_parser_parse(mip_parser* parser, const uint8_t* input_buffer, size_t input_count, mip_timestamp timestamp, unsigned int max_packets);
85 
86 void mip_parser_reset(mip_parser* parser);
87 
88 size_t mip_parser_get_write_ptr(mip_parser* parser, uint8_t** ptr_out);
89 void mip_parser_process_written(mip_parser* parser, size_t count, mip_timestamp timestamp, unsigned int max_packets);
90 
91 //
92 // Accessors
93 //
94 
96 void mip_parser_set_timeout(mip_parser* parser, mip_timeout timeout);
97 
98 void mip_parser_set_callback(mip_parser* parser, mip_packet_callback callback, void* callback_object);
100 void* mip_parser_callback_object(const mip_parser* parser);
101 
103 
104 
105 //
106 // Diagnostics
107 //
108 
109 #ifdef MIP_ENABLE_DIAGNOSTICS
110 
111 uint32_t mip_parser_diagnostic_bytes_read(const mip_parser* parser);
112 uint32_t mip_parser_diagnostic_bytes_skipped(const mip_parser* parser);
113 uint32_t mip_parser_diagnostic_packet_bytes(const mip_parser* parser);
114 
115 uint32_t mip_parser_diagnostic_valid_packets(const mip_parser* parser);
116 uint32_t mip_parser_diagnostic_invalid_packets(const mip_parser* parser);
117 uint32_t mip_parser_diagnostic_timeouts(const mip_parser* parser);
118 
119 #endif // MIP_ENABLE_DIAGNOSTICS
120 
121 
122 //
123 // Misc
124 //
125 
126 mip_timeout mip_timeout_from_baudrate(uint32_t baudrate);
127 
131 
132 #ifdef __cplusplus
133 } // extern "C"
134 } // namespace C
135 } // namespace mip
136 #endif
mip_packet.h
mip::C::MIP_PACKET_LENGTH_MAX
@ MIP_PACKET_LENGTH_MAX
Definition: mip_offsets.h:28
mip
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
mip::C::mip_parser_process_written
void mip_parser_process_written(mip_parser *parser, size_t count, mip_timestamp timestamp, unsigned int max_packets)
Notify the parser that data has been written to the pointer previously obtained via mip_parser_get_wr...
Definition: mip_parser.c:387
mip::C::mip_parser_parse_one_packet_from_ring
bool mip_parser_parse_one_packet_from_ring(mip_parser *parser, mip_packet_view *packet_out, mip_timestamp timestamp)
Parses a single packet from the internal buffer.
Definition: mip_parser.c:188
mip::C::mip_parser_set_callback
void mip_parser_set_callback(mip_parser *parser, mip_packet_callback callback, void *callback_object)
mip_parser_set_callback
Definition: mip_parser.c:287
mip::C::mip_parser_timeout
mip_timestamp mip_parser_timeout(const mip_parser *parser)
Returns the packet timeout of the parser.
Definition: mip_parser.c:263
mip::C::mip_parser_parse
size_t mip_parser_parse(mip_parser *parser, const uint8_t *input_buffer, size_t input_count, mip_timestamp timestamp, unsigned int max_packets)
Parses packets from the input data buffer.
Definition: mip_parser.c:121
mip_types.h
mip::C::mip_parser_callback_object
void * mip_parser_callback_object(const mip_parser *parser)
mip_parser_callback
Definition: mip_parser.c:313
byte_ring.h
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
byte_ring_state
Definition: byte_ring.h:7
mip::C::mip_timeout
microstrain::C::microstrain_embedded_timestamp mip_timeout
Definition: mip_types.h:16
mip::C::mip_packet_callback
bool(* mip_packet_callback)(void *user, const mip_packet_view *packet, mip_timestamp timestamp)
Callback function which receives parsed MIP packets.
Definition: mip_parser.h:45
mip::C::mip_parser
MIP Parser state.
Definition: mip_parser.h:55
mip::C::mip_parser_get_write_ptr
size_t mip_parser_get_write_ptr(mip_parser *parser, uint8_t **const ptr_out)
Obtain a pointer into which data may be read for processing.
Definition: mip_parser.c:368
mip::C::mip_parser_callback
mip_packet_callback mip_parser_callback(const mip_parser *parser)
mip_parser_callback
Definition: mip_parser.c:300
mip::C::mip_parser_reset
void mip_parser_reset(mip_parser *parser)
Resets the MIP parser.
Definition: mip_parser.c:59
mip::C::mip_parser_init
void mip_parser_init(mip_parser *parser, uint8_t *buffer, size_t buffer_size, mip_packet_callback callback, void *callback_object, mip_timestamp timeout)
Initializes the MIP parser.
Definition: mip_parser.c:38
mip::C::mip_timeout_from_baudrate
mip_timeout mip_timeout_from_baudrate(uint32_t baudrate)
Computes an appropriate packet timeout for a given serial baud rate.
Definition: mip_parser.c:481
mip::C::mip_timestamp
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
mip::C::mip_parser_last_packet_timestamp
mip_timestamp mip_parser_last_packet_timestamp(const mip_parser *parser)
Gets the timestamp of the last parsed packet.
Definition: mip_parser.c:336
mip::C::mip_parser_set_timeout
void mip_parser_set_timeout(mip_parser *parser, mip_timestamp timeout)
Changes the timeout of the MIP parser.
Definition: mip_parser.c:275
mip::C::mip_parser
struct mip::C::mip_parser mip_parser
MIP Parser state.
mip_offsets.h
mip::C::mip_packet_view
struct mip::C::mip_packet_view mip_packet_view
Structure representing a MIP Packet.