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:
Inheritance graph

Public Member Functions

 ProtocolHandler ()
 Default constructor. More...
 
virtual ~ProtocolHandler ()
 Destructor. More...
 
virtual MessageLocation findMessage (XsMessage &rcv, const XsByteArray &raw) const
 Find the first message in the raw byte stream. More...
 
virtual int minimumMessageSize () const
 Returns the minimum size of a valid message of this protocol including preambles and checksums. More...
 
virtual int maximumMessageSize () const
 Returns the maximum size of a valid message of this protocol including preambles and checksums. More...
 
virtual int type () const
 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 ( )
virtual

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
virtual

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, XsMessageHeader::m_busId, XsMessageHeader::m_length, XsMessageHeader::m_messageId, MessageLocation::m_size, MessageLocation::m_startPos, XS_EXTLENCODE, XS_LEN_MSGEXTHEADERCS, XS_LEN_MSGHEADERCS, XS_MAXDATALEN, and XS_PREAMBLE.

◆ maximumMessageSize()

int ProtocolHandler::maximumMessageSize ( ) const
virtual

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
virtual

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
virtual

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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020