MIP_SDK  v3.0.0-425-g6df21bd
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 (C::mip_packet_callback callback, void *callbackObject, Timeout timeout)
 Initializes the MIP parser. More...
 
 Parser (bool(*callback)(void *, const PacketView *, Timestamp), void *callbackObject, Timeout timeout)
 Initializes the MIP parser. More...
 
 Parser (Timeout timeout)
 Construct without a callback. More...
 
void setCallback (C::mip_packet_callback callback, void *callbackObject)
 
template<class Lambda >
void setCallback (Lambda lambda)
 
template<class T , bool(T::*)(const PacketView &, Timestamp) Callback>
void setCallback (T &object)
 Initializes the MIP Parser. More...
 
template<class T , bool(*)(T &, const PacketView &, Timestamp) Callback>
void setCallback (T &object)
 
void reset ()
 Resets the MIP parser. More...
 
size_t parse (const uint8_t *inputBuffer, size_t inputCount, Timestamp timestamp)
 Parse packets from a buffer. More...
 
size_t parse (microstrain::Span< const uint8_t > data, Timestamp timestamp)
 Parse packets from a buffer (span version). More...
 
void flush ()
 Processes all previously buffered data. More...
 
microstrain::Span< uint8_t > getWritePtr ()
 Gets a pointer into which a small amount of data may be written for parsing. More...
 
Timeout timeout () const
 Returns the packet timeout of the parser. More...
 
void setTimeout (Timeout timeout)
 Changes the timeout of the MIP parser. More...
 
template<class FunctionOrLambda >
void setCallback (FunctionOrLambda function)
 

Detailed Description

C++ class representing a MIP parser.

See Mip Parser

Constructor & Destructor Documentation

◆ Parser() [1/3]

mip::Parser::Parser ( C::mip_packet_callback  callback,
void *  callbackObject,
Timeout  timeout 
)
inline

Initializes the MIP parser.

Parameters
parser
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 ( bool(*)(void *, const PacketView *, Timestamp callback,
void *  callbackObject,
Timeout  timeout 
)
inline

Initializes the MIP parser.

Parameters
parser
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 ( Timeout  timeout)
inlineexplicit

Construct without a callback.

Member Function Documentation

◆ flush()

void mip::Parser::flush ( )
inline

Processes all previously buffered data.

Call this at the end of reading a binary file to ensure that any trailing packets are fully processed.

Parameters
parser

◆ getWritePtr()

microstrain::Span<uint8_t> mip::Parser::getWritePtr ( )
inline

Gets a pointer into which a small amount of data may be written for parsing.

Returns
a buffer into which data can be written.

◆ parse() [1/2]

size_t mip::Parser::parse ( const uint8_t *  inputBuffer,
size_t  inputCount,
Timestamp  timestamp 
)
inline

Parse packets from a buffer.

The buffer may contain non-mip data (e.g. NMEA 0183) which will be ignored.

Parameters
parser
input_bufferBuffer from which to parse packets. If NULL, parses from the internal buffer instead (see mip_parser_get_write_ptr).
input_lengthLength of data in the buffer.
timestampTime of arrival of the data to be parsed. This is used to set packets' timestamp and to time out incomplete packets.
Returns
The number of bytes processed from input_buffer. This will always be equal to input_length except when the packet callback is NULL or it returns false to stop parsing early.
Note
The timestamp of a packet is based on the time the packet was parsed. Packets received during an earlier parse call may be timestamped with the time from a later parse call, but will never be timestamped before they were actually received.
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 contains the two-byte sequence 0x75, 0x65. This may cause temporary stalls in parsed data if the following bytes suggest that more data is needed to complete the "packet". Once the fake packet times out or enough data is received, real MIP packets received in the meantime will be properly parsed. Note that the 16-bit checksum has a 1 in 65,536 chance of appearing to be valid at random.

◆ parse() [2/2]

size_t mip::Parser::parse ( microstrain::Span< const uint8_t >  data,
Timestamp  timestamp 
)
inline

Parse packets from a buffer (span version).

The buffer may contain non-mip data (e.g. NMEA 0183) which will be ignored.

Parameters
parser
input_bufferBuffer from which to parse packets. If NULL, parses from the internal buffer instead (see mip_parser_get_write_ptr).
input_lengthLength of data in the buffer.
timestampTime of arrival of the data to be parsed. This is used to set packets' timestamp and to time out incomplete packets.
Returns
The number of bytes processed from input_buffer. This will always be equal to input_length except when the packet callback is NULL or it returns false to stop parsing early.
Note
The timestamp of a packet is based on the time the packet was parsed. Packets received during an earlier parse call may be timestamped with the time from a later parse call, but will never be timestamped before they were actually received.
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 contains the two-byte sequence 0x75, 0x65. This may cause temporary stalls in parsed data if the following bytes suggest that more data is needed to complete the "packet". Once the fake packet times out or enough data is received, real MIP packets received in the meantime will be properly parsed. Note that the 16-bit checksum has a 1 in 65,536 chance of appearing to be valid at random.

◆ 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

◆ setCallback() [1/3]

void mip::Parser::setCallback ( C::mip_packet_callback  callback,
void *  callbackObject 
)
inline

◆ setCallback() [2/3]

template<class Lambda >
void mip::Parser::setCallback ( Lambda  lambda)

◆ setCallback() [3/3]

template<class T , bool(*)(T &, const PacketView &, Timestamp) Callback>
void mip::Parser::setCallback ( T &  object)

◆ 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: