MIP_SDK  latest-2-g34f3e39
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 (void(*callback)(void *, const PacketView *, Timestamp), void *callbackObject, Timeout timeout)
 Initializes the MIP parser. More...
 
 Parser (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...
 
void parse (const uint8_t *inputBuffer, size_t inputCount, Timestamp timestamp)
 Parse packets from a buffer. More...
 
void parse (microstrain::Span< const uint8_t > data, Timestamp timestamp)
 Parse packets from a buffer (span version). 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 ( 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 ( void(*)(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)
inline

Member Function Documentation

◆ parse() [1/2]

void 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.
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]

void 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.
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

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