MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
Public Member Functions | List of all members
mip::Parser Class Reference

C++ class representing a MIP parser. More...

#include <mip_parser.hpp>

Inheritance diagram for mip::Parser:
mip::C::mip_parser

Public Member Functions

 Parser (uint8_t *buffer, size_t bufferSize, C::mip_packet_callback callback, void *callbackObject, Timeout timeout)
 Initializes the MIP parser. More...
 
 Parser (uint8_t *buffer, size_t bufferSize, bool(*callback)(void *, const PacketView *, Timestamp), void *callbackObject, Timeout timeout)
 Initializes the MIP parser. More...
 
 Parser (uint8_t *buffer, size_t bufferSize, Timeout timeout)
 
template<class T , bool(T::*)(const PacketView &, Timestamp) Callback>
void setCallback (T &object)
 Initializes the MIP Parser. More...
 
void reset ()
 Resets the MIP parser. More...
 
size_t parse (const uint8_t *inputBuffer, size_t inputCount, Timestamp timestamp, unsigned int maxPackets=0)
 Parses packets from the input data buffer. More...
 
Timeout timeout () const
 Returns the packet timeout of the parser. More...
 
void setTimeout (Timeout timeout)
 Changes the timeout of the MIP parser. More...
 

Detailed Description

C++ class representing a MIP parser.

See Mip Parser

Constructor & Destructor Documentation

◆ Parser() [1/3]

mip::Parser::Parser ( uint8_t *  buffer,
size_t  bufferSize,
C::mip_packet_callback  callback,
void *  callbackObject,
Timeout  timeout 
)
inline

Initializes the MIP parser.

Parameters
parser
bufferScratch space for the parser to use internally; input data is consumed and fed to this buffer. Cannot be NULL.
buffer_sizeSize of buffer, in bytes.
callbackA 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_objectAn optional user-specified pointer which is directly passed to the callback as the first parameter.
timeoutThe timeout for receiving one packet. Depends on the serial baud rate and is typically 100 milliseconds.

◆ Parser() [2/3]

mip::Parser::Parser ( uint8_t *  buffer,
size_t  bufferSize,
bool(*)(void *, const PacketView *, Timestamp callback,
void *  callbackObject,
Timeout  timeout 
)
inline

Initializes the MIP parser.

Parameters
parser
bufferScratch space for the parser to use internally; input data is consumed and fed to this buffer. Cannot be NULL.
buffer_sizeSize of buffer, in bytes.
callbackA 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_objectAn optional user-specified pointer which is directly passed to the callback as the first parameter.
timeoutThe timeout for receiving one packet. Depends on the serial baud rate and is typically 100 milliseconds.

◆ Parser() [3/3]

mip::Parser::Parser ( uint8_t *  buffer,
size_t  bufferSize,
Timeout  timeout 
)
inline

Member Function Documentation

◆ parse()

size_t mip::Parser::parse ( const uint8_t *  inputBuffer,
size_t  inputCount,
Timestamp  timestamp,
unsigned int  maxPackets = 0 
)
inline

Parses packets from the input data buffer.

For every valid MIP packet, the callback function will be called with the packet and timestamp.

Parameters
parser
input_bufferPointer 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_countThe number of bytes in the input buffer.
timestampThe local time the data was received. This is used to check for timeouts and is passed to the callback as the packet timestamp.
max_packetsThe 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.
Returns
The number of bytes left unprocessed from the input buffer. If max_packets is 0, this will also be zero as all of the data will be consumed. Data may still remain in the internal buffer.
Note
If max_packets is 0, then this function is guaranteed to consume all of the input data and the buffer can be reused or discarded afterward. However, if max_packets is nonzero (meaning the number of packets parsed will be limited), then this is no longer guaranteed as the excess data may fill up the internal bufffer. In this case, you must process packets faster than they arrive on average. For bursty data (e.g. GNSS data), use a large internal buffer (see mip_parser_init) to help average out the packet processing load.
The timestamp of parsed packets is based on the time the packet was parsed. When max_packets==0, this is the same as the input timestamp. When max_packets!=0, packets received during an earlier parse call may be timestamped with the time from a later parse call. Therefore, if packet timestamping is critical to your application, avoid using max_packets > 0.
The parser will do its best to ignore non-MIP data. However, it is possible for some binary data to appear to be a MIP packet if it conntains 0x75,0x65, has at least 6 bytes, and has a valid checksum. A 16-bit checksum has a 1 in 65,536 chance of appearing to be valid.

◆ reset()

void mip::Parser::reset ( )
inline

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.

Parameters
parser

◆ setTimeout()

void mip::Parser::setTimeout ( Timeout  timeout)
inline

Changes the timeout of the MIP parser.

Parameters
parser
timeout

◆ timeout()

Timeout mip::Parser::timeout ( ) const
inline

Returns the packet timeout of the parser.


The documentation for this class was generated from the following file: