MIP_SDK v2.0.0-141-g7a72ec3
MicroStrain Communications Library for embedded systems
|
Macros | |
#define | MIPPARSER_RESET_LENGTH 1 |
Functions | |
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. | |
void | mip_parser_reset (mip_parser *parser) |
Resets the MIP parser. | |
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. | |
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. | |
mip_timestamp | mip_parser_timeout (const mip_parser *parser) |
Returns the packet timeout of the parser. | |
void | mip_parser_set_timeout (mip_parser *parser, mip_timestamp timeout) |
Changes the timeout of the MIP parser. | |
void | mip_parser_set_callback (mip_parser *parser, mip_packet_callback callback, void *callback_object) |
mip_parser_set_callback | |
mip_packet_callback | mip_parser_callback (const mip_parser *parser) |
mip_parser_callback | |
void * | mip_parser_callback_object (const mip_parser *parser) |
mip_parser_callback | |
mip_timestamp | mip_parser_last_packet_timestamp (const mip_parser *parser) |
Gets the timestamp of the last parsed packet. | |
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. | |
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_write_ptr(). | |
mip_timeout | mip_timeout_from_baudrate (uint32_t baudrate) |
Computes an appropriate packet timeout for a given serial baud rate. | |
#define MIPPARSER_RESET_LENGTH 1 |
mip_packet_callback mip_parser_callback | ( | const mip_parser * | parser | ) |
mip_parser_callback
parser |
void * mip_parser_callback_object | ( | const mip_parser * | parser | ) |
mip_parser_callback
parser |
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.
Use this function when the source data stream (e.g. a file or serial port) requires that you pass in a buffer when reading data. This avoids the need for an intermediate buffer.
Call mip_parser_process_written() after the data has been read to update the buffer count and process any packets.
parser | |
ptr_out | A pointer to a pointer which will be set to the buffer where data should be written. Cannot be NULL. |
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.
parser | |
buffer | Scratch space for the parser to use internally; input data is consumed and fed to this buffer. Cannot be NULL. |
buffer_size | Size of buffer, in bytes. |
callback | A function to be called when a valid packet is identified. It will be passed an optional user-supplied parameter, a pointer to the packet, and the time the first byte was parsed. |
callback_object | An optional user-specified pointer which is directly passed to the callback as the first parameter. |
timeout | The timeout for receiving one packet. Depends on the serial baud rate and is typically 100 milliseconds. |
mip_timestamp mip_parser_last_packet_timestamp | ( | const mip_parser * | parser | ) |
Gets the timestamp of the last parsed packet.
This is only valid after a valid packet has been parsed.
This function is provided to allow additional calls to mip_parser_parse() with no input data (buffer=NULL and length=0) when max_packets > 0. The additional calls can use the same timestamp because no new data will be processed.
There are two possible situations after the last call to 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.
For every valid MIP packet, the callback function will be called with the packet and timestamp.
parser | |
input_buffer | Pointer to bytes received from the device or file. This buffer may contain non-mip data (e.g. NMEA 0183), which will be ignored. This buffer may be NULL if input_count is 0. |
input_count | The number of bytes in the input buffer. |
timestamp | The local time the data was received. This is used to check for timeouts and is passed to the callback as the packet timestamp. |
max_packets | The maximum number of packets to process. Unprocessed data is left in the internal buffer. If 0, processing runs until no complete packets remain in the buffer. |
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.
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_write_ptr().
The write pointer changes after calling this with count > 0. To write more data, call mip_parser_get_write_ptr again.
parser | |
count | |
timestamp | |
max_packets |
void mip_parser_reset | ( | mip_parser * | parser | ) |
Resets the MIP parser.
Clears the current packet and internal buffer. The parser will be restored as if mip_parser_init had just been called.
parser |
void mip_parser_set_callback | ( | mip_parser * | parser, |
mip_packet_callback | callback, | ||
void * | callback_object | ||
) |
mip_parser_set_callback
parser | |
callback | |
callback_object |
void mip_parser_set_timeout | ( | mip_parser * | parser, |
mip_timestamp | timeout | ||
) |
Changes the timeout of the MIP parser.
parser | |
timeout |
mip_timestamp mip_parser_timeout | ( | const mip_parser * | parser | ) |
Returns the packet timeout of the parser.
mip_timeout mip_timeout_from_baudrate | ( | uint32_t | baudrate | ) |
Computes an appropriate packet timeout for a given serial baud rate.
baudrate | Serial baud rate in bits per second |