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");
124 gJournal,
"Bytes in buffer=" << remaining
125 <<
", full target = " << target);
129 JLALERT(gJournal,
"Invalid message length: " << target);
134 if (remaining < target)
138 gJournal,
"Not enough data read: " << remaining <<
" / " 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
virtual ~ProtocolHandler()
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.
virtual MessageLocation findMessage(XsMessage &rcv, const XsByteArray &raw) const
Find the first message in the raw byte stream.
virtual int minimumMessageSize() const
Returns the minimum size of a valid message of this protocol including preambles and checksums...
static int composeMessage(XsByteArray &raw, const XsMessage &msg)
Compose a message for transmission.
virtual int maximumMessageSize() const
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.
virtual int type() const
Returns the type of the protocol handler.
#define XS_LEN_MSGHEADERCS
ProtocolHandler()
Default constructor.
unsigned __int32 uint32_t