54 ((
uint32_t)hdr->m_datlen.m_extended.m_length.m_high * 256 +
55 (
uint32_t)hdr->m_datlen.m_extended.m_length.m_low);
74 int bufferSize = (int)raw.size();
75 if (bufferSize == 0)
return rv;
77 const unsigned char*
buffer = raw.data();
80 for (
int pre = 0; pre < bufferSize; ++pre)
84 JLTRACE(gJournal,
"Preamble found at " << pre);
93 JLTRACE(gJournal,
"Not enough header data read");
106 JLTRACE(gJournal,
"Not enough extended header data read");
112 else if (hdr->m_busId == 0 && hdr->m_messageId == 0)
124 gJournal,
"Bytes in buffer=" << remaining
125 <<
", full target = " << target);
129 JLALERT(gJournal,
"Invalid message length: " << target);
134 if (remaining < target)
139 "Not enough data read: " << remaining <<
" / " << target);
148 if (rcv.loadFromString(msgStart, (
uint16_t)target))
152 "OK, size = " << (
int)rcv.getTotalMessageSize() << std::hex
153 << std::setfill(
'0') <<
" First bytes " 154 << std::setw(2) << (int)msgStart[0] <<
" " 155 << std::setw(2) << (int)msgStart[1] <<
" " 156 << std::setw(2) << (int)msgStart[2] <<
" " 157 << std::setw(2) << (int)msgStart[3] <<
" " 158 << std::setw(2) << (int)msgStart[4]
159 << std::dec << std::setfill(
' '));
160 rv.
m_size = (int)rcv.getTotalMessageSize();
175 gJournal,
"Invalid checksum" 176 << std::hex << std::setfill(
'0')
177 <<
" First bytes " << std::setw(2)
178 << (
int)msgStart[0] <<
" " << std::setw(2)
179 << (
int)msgStart[1] <<
" " << std::setw(2)
180 << (
int)msgStart[2] <<
" " << std::setw(2)
181 << (
int)msgStart[3] <<
" " << std::setw(2)
182 << (
int)msgStart[4] << std::dec
183 << std::setfill(
' '));
213 if (msg.getTotalMessageSize() <
217 raw.assign(msg.getTotalMessageSize(), msg.getMessageStart());
218 return (
int)raw.size();
unsigned __int16 uint16_t
struct XsByteArray XsByteArray
int minimumMessageSize() const override
Returns the minimum size of a valid message of this protocol including preambles and checksums...
~ProtocolHandler() override
Destructor.
#define XS_LEN_MSGEXTHEADERCS
Stores the location of a message in a buffer using a start position and a size.
Structure for storing a single message.
int m_startPos
The offset of the first byte of the message or -1 if no message.
MessageLocation findMessage(XsMessage &rcv, const XsByteArray &raw) const override
Find the first message in the raw byte stream.
int type() const override
Returns the type of the protocol handler.
static int composeMessage(XsByteArray &raw, const XsMessage &msg)
Compose a message for transmission.
int maximumMessageSize() const override
Returns the maximum size of a valid message of this protocol including preambles and checksums...
int m_size
The size of the message, when less than 0 it indicates the expected message size. ...
int expectedMessageSize(const unsigned char *buffer, int sz)
Compute the expected message size given a possibly incomplete message.
#define XS_LEN_MSGHEADERCS
ProtocolHandler()
Default constructor.
unsigned __int32 uint32_t