MIP_SDK  latest-2-g34f3e39
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 "mip_types.h"
7 
8 #ifdef __cplusplus
9 namespace mip {
10 namespace C {
11 extern "C" {
12 #endif
13 
20 
21 
37 
38 
43 typedef void (*mip_packet_callback)(void* user, const mip_packet_view* packet, mip_timestamp timestamp);
44 
45 
53 typedef struct mip_parser
54 {
55  mip_timestamp _start_time;
56  mip_timeout _timeout;
57 
58  mip_packet_callback _callback;
59  void* _callback_object;
60 
61 #ifdef MIP_ENABLE_DIAGNOSTICS
62  uint32_t _diag_bytes_read;
63  uint32_t _diag_bytes_skipped;
64  uint32_t _diag_packet_bytes;
65  uint32_t _diag_valid_packets;
66  uint32_t _diag_invalid_packets;
67  uint32_t _diag_timeouts;
68 #endif // MIP_ENABLE_DIAGNOSTICS
69 
70  uint16_t _buffered_length;
71  uint8_t _buffer[MIP_PACKET_LENGTH_MAX];
72 
73 } mip_parser;
74 
75 
76 
77 #define MIP_PARSER_DEFAULT_TIMEOUT_MS 100
78 
79 
80 void mip_parser_init(mip_parser* parser, mip_packet_callback callback, void* callback_object, mip_timeout timeout);
81 void mip_parser_parse(mip_parser* parser, const uint8_t* input_buffer, size_t input_length, mip_timestamp timestamp);
82 void mip_parser_flush(mip_parser* parser);
83 
84 void mip_parser_reset(mip_parser* parser);
85 
86 uint_least16_t mip_parser_get_write_ptr(mip_parser* parser, uint8_t** ptr_out);
87 
88 //
89 // Accessors
90 //
91 
93 void mip_parser_set_timeout(mip_parser* parser, mip_timeout timeout);
94 
95 void mip_parser_set_callback(mip_parser* parser, mip_packet_callback callback, void* callback_object);
97 void* mip_parser_callback_object(const mip_parser* parser);
98 
100 
101 
102 //
103 // Diagnostics
104 //
105 
106 #ifdef MIP_ENABLE_DIAGNOSTICS
107 
108 uint32_t mip_parser_diagnostic_bytes_read(const mip_parser* parser);
109 uint32_t mip_parser_diagnostic_bytes_skipped(const mip_parser* parser);
110 uint32_t mip_parser_diagnostic_packet_bytes(const mip_parser* parser);
111 
112 uint32_t mip_parser_diagnostic_valid_packets(const mip_parser* parser);
113 uint32_t mip_parser_diagnostic_invalid_packets(const mip_parser* parser);
114 uint32_t mip_parser_diagnostic_timeouts(const mip_parser* parser);
115 
116 #endif // MIP_ENABLE_DIAGNOSTICS
117 
118 
119 //
120 // Misc
121 //
122 
123 mip_timeout mip_timeout_from_baudrate(uint32_t baudrate);
124 
128 
129 #ifdef __cplusplus
130 } // extern "C"
131 } // namespace C
132 } // namespace mip
133 #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_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:440
mip::C::mip_parser_timeout
mip_timeout mip_parser_timeout(const mip_parser *parser)
Returns the packet timeout of the parser.
Definition: mip_parser.c:416
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:466
mip::C::mip_parser_set_timeout
void mip_parser_set_timeout(mip_parser *parser, mip_timeout timeout)
Changes the timeout of the MIP parser.
Definition: mip_parser.c:428
mip::C::mip_parser_current_timestamp
mip_timestamp mip_parser_current_timestamp(const mip_parser *parser)
Gets the timestamp of the last parsed packet.
Definition: mip_parser.c:489
mip::C::mip_parser_parse
void mip_parser_parse(mip_parser *parser, const uint8_t *input_buffer, size_t input_length, mip_timestamp timestamp)
Parse packets from a buffer.
Definition: mip_parser.c:183
mip::C::mip_packet_view
Structure representing a MIP Packet.
Definition: mip_packet.h:50
mip::C::mip_timeout
microstrain::C::microstrain_embedded_timestamp mip_timeout
Definition: mip_types.h:16
mip::C::mip_parser_flush
void mip_parser_flush(mip_parser *parser)
Processes all previously buffered data.
Definition: mip_parser.c:370
mip::C::mip_parser
MIP Parser state.
Definition: mip_parser.h:53
mip::C::mip_parser_callback
mip_packet_callback mip_parser_callback(const mip_parser *parser)
mip_parser_callback
Definition: mip_parser.c:453
mip::C::mip_parser_init
void mip_parser_init(mip_parser *parser, mip_packet_callback callback, void *callback_object, mip_timeout timeout)
Initializes the MIP parser.
Definition: mip_parser.c:32
mip::C::mip_parser_get_write_ptr
uint_least16_t mip_parser_get_write_ptr(mip_parser *parser, uint8_t **ptr_out)
Gets a pointer into which a small amount of data may be written for parsing.
Definition: mip_parser.c:403
mip::C::mip_parser_reset
void mip_parser_reset(mip_parser *parser)
Resets the MIP parser.
Definition: mip_parser.c:51
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:580
mip::C::mip_timestamp
microstrain::C::microstrain_embedded_timestamp mip_timestamp
Definition: mip_types.h:15
mip::C::mip_parser
struct mip::C::mip_parser mip_parser
MIP Parser state.
mip::C::mip_packet_callback
void(* mip_packet_callback)(void *user, const mip_packet_view *packet, mip_timestamp timestamp)
Callback function which receives parsed MIP packets.
Definition: mip_parser.h:43
mip_offsets.h