MRPT  1.9.9
ProtocolHandler Class Reference

Detailed Description

Message protocol handling class.

This class' purpose is to get valid messages according to its protocol from the raw data that is supplied to it. The default implementation (ProtocolHandler) implements the Xsens message protocol. To use a different protocol, overload the findMessage function.

The class is intended to be state-less with respect to the data it handles.

Definition at line 16 of file protocolhandler.h.

#include <xSens_MT4/xcommunication/include/xsens/protocolhandler.h>

Inheritance diagram for ProtocolHandler:

Public Member Functions

 ProtocolHandler ()
 Default constructor. More...
 
 ~ProtocolHandler () override
 Destructor. More...
 
MessageLocation findMessage (XsMessage &rcv, const XsByteArray &raw) const override
 Find the first message in the raw byte stream. More...
 
int minimumMessageSize () const override
 Returns the minimum size of a valid message of this protocol including preambles and checksums. More...
 
int maximumMessageSize () const override
 Returns the maximum size of a valid message of this protocol including preambles and checksums. More...
 
int type () const override
 Returns the type of the protocol handler. More...
 

Static Public Member Functions

static int composeMessage (XsByteArray &raw, const XsMessage &msg)
 Compose a message for transmission. More...
 

Constructor & Destructor Documentation

◆ ProtocolHandler()

ProtocolHandler::ProtocolHandler ( )

Default constructor.

Definition at line 28 of file protocolhandler.cpp.

◆ ~ProtocolHandler()

ProtocolHandler::~ProtocolHandler ( )
override

Destructor.

Definition at line 30 of file protocolhandler.cpp.

Member Function Documentation

◆ composeMessage()

int ProtocolHandler::composeMessage ( XsByteArray raw,
const XsMessage msg 
)
static

Compose a message for transmission.

Parameters
rawThe raw byte array to be constructed from the message
msgThe message to translate into a raw byte array
Returns
The size of the generated byte array
Todo:
Generalize this method -> IProtocolHandler

Definition at line 211 of file protocolhandler.cpp.

◆ findMessage()

MessageLocation ProtocolHandler::findMessage ( XsMessage rcv,
const XsByteArray raw 
) const
overridevirtual

Find the first message in the raw byte stream.

This function scans raw for a sequence of bytes that it can convert into an XsMessage object. It returns the location and total byte size of the message so that the caller can remove those bytes from the stream. The return value can also describe that a partial message has been found. Return values:

  • startpos >= 0 and size > 0: A full message with size has been found at startpos.
  • startpos >= 0 and size == 0: The start of a message has been found at startpos, but the size could not yet be determined.
  • startpos >= 0 and size < 0: The start of a message has been found at startpos, and the size of the full message is at least -size.
  • startpos < 0: No messages have been found.
Parameters
rcvIf a message is read, it will be put in this object.
rawThe raw byte stream to analyze.
Returns
A MessageLocation object that describes what was found.
Todo:
Since the assumption is that we receive a stream of valid messages without garbage, the scan is implemented in a rather naive and simple way. If we can expect lots of garbage in the data stream, this should probably be looked into.

Implements IProtocolHandler.

Definition at line 67 of file protocolhandler.cpp.

References expectedMessageSize(), JLALERT, JLTRACE, MessageLocation::m_size, MessageLocation::m_startPos, XS_EXTLENCODE, XS_LEN_MSGEXTHEADERCS, XS_LEN_MSGHEADERCS, XS_MAXDATALEN, and XS_PREAMBLE.

Here is the call graph for this function:

◆ maximumMessageSize()

int ProtocolHandler::maximumMessageSize ( ) const
overridevirtual

Returns the maximum size of a valid message of this protocol including preambles and checksums.

Implements IProtocolHandler.

Definition at line 199 of file protocolhandler.cpp.

References XS_LEN_MSGEXTHEADERCS, and XS_MAXDATALEN.

◆ minimumMessageSize()

int ProtocolHandler::minimumMessageSize ( ) const
overridevirtual

Returns the minimum size of a valid message of this protocol including preambles and checksums.

Implements IProtocolHandler.

Definition at line 192 of file protocolhandler.cpp.

References XS_LEN_MSGHEADERCS.

◆ type()

int ProtocolHandler::type ( ) const
overridevirtual

Returns the type of the protocol handler.

Each protocol handler has a locally unique id that can be used for instantiation of the correct protocol handler.

Returns
The type id of the protocol handler.

Implements IProtocolHandler.

Definition at line 221 of file protocolhandler.cpp.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019