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.
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.
|rcv||If a message is read, it will be put in this object. |
|raw||The raw byte stream to analyze. |
- A MessageLocation object that describes what was found.
- 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.
Definition at line 58 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.