MIP SDK  0.0.1
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* packet, timestamp_type timestamp);
46 
47 
55 typedef struct mip_parser
56 {
57  timestamp_type _start_time;
58  timestamp_type _timeout;
59  uint8_t _result_buffer[MIP_PACKET_LENGTH_MAX];
60  packet_length _expected_length;
61  byte_ring_state _ring;
62  mip_packet_callback _callback;
63  void* _callback_object;
65 
66 
67 
68 #define MIPPARSER_UNLIMITED_PACKETS 0
69 #define MIPPARSER_DEFAULT_TIMEOUT_MS 100
70 
71 
72 void mip_parser_init(mip_parser* parser, uint8_t* buffer, size_t buffer_size, mip_packet_callback callback, void* callback_object, timestamp_type timeout);
74 remaining_count mip_parser_parse(mip_parser* parser, const uint8_t* input_buffer, size_t input_count, timestamp_type timestamp, unsigned int max_packets);
75 
77 
78 size_t mip_parser_get_write_ptr(mip_parser* parser, uint8_t** ptr_out);
79 void mip_parser_process_written(mip_parser* parser, size_t count, timestamp_type timestamp, unsigned int max_packets);
80 
81 //
82 // Accessors
83 //
84 
87 
88 void mip_parser_set_callback(mip_parser* parser, mip_packet_callback callback, void* callback_object);
91 
93 
94 //
95 // Misc
96 //
97 
99 
103 
104 #ifdef __cplusplus
105 } // namespace mip
106 } // namespace C
107 } // extern "C"
108 #endif
uint_least16_t packet_length
Type used for the length of a MIP packet.
Definition: mip_packet.h:32
void mip_parser_reset(mip_parser *parser)
timestamp_type mip_parser_last_packet_timestamp(const mip_parser *parser)
void mip_parser_init(mip_parser *parser, uint8_t *buffer, size_t buffer_size, mip_packet_callback callback, void *callback_object, timestamp_type timeout)
void mip_parser_process_written(mip_parser *parser, size_t count, timestamp_type timestamp, unsigned int max_packets)
size_t mip_parser_get_write_ptr(mip_parser *parser, uint8_t **ptr_out)
bool mip_parser_parse_one_packet_from_ring(mip_parser *parser, mip_packet *packet_out, timestamp_type timestamp)
timeout_type mip_timeout_from_baudrate(uint32_t baudrate)
bool(* mip_packet_callback)(void *user, const mip_packet *packet, timestamp_type timestamp)
Callback function which receives parsed MIP packets.
Definition: mip_parser.h:45
struct mip::C::mip_parser mip_parser
MIP Parser state.
timeout_type mip_parser_timeout(const mip_parser *parser)
mip_packet_callback mip_parser_callback(const mip_parser *parser)
void * mip_parser_callback_object(const mip_parser *parser)
remaining_count mip_parser_parse(mip_parser *parser, const uint8_t *input_buffer, size_t input_count, timestamp_type timestamp, unsigned int max_packets)
void mip_parser_set_callback(mip_parser *parser, mip_packet_callback callback, void *callback_object)
void mip_parser_set_timeout(mip_parser *parser, timeout_type timeout)
timestamp_type timeout_type
Definition: mip_types.h:35
int_least16_t remaining_count
Definition: mip_types.h:16
@ MIP_PACKET_LENGTH_MAX
Definition: mip_offsets.h:28
uint64_t timestamp_type
Type used for packet timestamps and timeouts.
Definition: mip_types.h:32
A collection of C++ classes and functions covering the full mip api.
Definition: commands_3dm.c:11
Definition: byte_ring.h:8
Structure representing a MIP Packet.
Definition: mip_packet.h:44
MIP Parser state.
Definition: mip_parser.h:56