69 MessageException::MessageException(
const char *msg,
enum errors ex_type)
89 memcpy(
data, input, msg_len);
102 uint32_t timestamp, uint8_t flags, uint8_t version) :
140 for (
int i = 0; i < 2; ++i)
162 CPR_WARN() <<
"Bad checksum twice in a row." << endl;
172 for (
int i = 0; i < 2; ++i)
194 CPR_WARN() <<
"Bad checksum twice in a row." << endl;
255 size_t new_total_len = len + 3;
334 if (whyNot) { strncpy(whyNot,
"SOH is not present.", strLen); }
340 if (whyNot) { strncpy(whyNot,
"STX is not present.", strLen); }
346 if (whyNot) { strncpy(whyNot,
"Length does not match complement.", strLen); }
352 if (whyNot) { strncpy(whyNot,
"Length is wrong.", strLen); }
358 if (whyNot) { strncpy(whyNot,
"CRC is wrong.", strLen); }
360 for (
int i=0; i<
crcOffset(); ++i) printf(
" %x", (
unsigned char)(this->
data[i]));
381 std::cout<<
"message data:";
383 printf(
" %x",(
unsigned char)(
data[i]));
385 std::cout<<
" !!"<<std::endl;
391 stream <<
"Message" << endl;
392 stream <<
"=======" << endl;
393 stream <<
"Length : " << (int) (
getLength()) << endl;
395 stream <<
"Version : " << (int) (
getVersion()) << endl;
396 stream <<
"Flags : " << hex << (int) (
getFlags()) << endl;
397 stream <<
"Type : " << hex << (int) (
getType()) << endl;
398 stream <<
"Checksum : " << hex << (int) (
getChecksum()) << endl;
407 stream << hex << uppercase;
408 for (
unsigned int i = 0; i <
total_len; i++)
410 stream << static_cast<short>(
data[i]) <<
" ";
465 return new DataEcho(input, msg_len);
528 return new Message(input, msg_len);
size_t getPayload(void *buf, size_t max_size)
static Message * waitNext(double timeout=0.0)
Message * sendRequest(Message *m)
static const size_t MAX_MSG_LENGTH
void setType(uint16_t type)
bool isValid(char *whyNot=NULL, size_t strLen=0)
void setFlags(uint8_t flags)
uint64_t btou(void *src, size_t src_len)
void utob(void *dest, size_t dest_len, uint64_t src)
static Transport & instance()
static Message * factory(void *input, size_t msg_len)
uint8_t * getPayloadPointer(size_t offset=0)
void setPayload(void *buf, size_t buf_size)
void printRaw(std::ostream &stream=std::cout)
size_t getPayloadLength()
void setVersion(uint8_t version)
size_t toBytes(void *buf, size_t buf_size)
void setLength(uint8_t len)
std::ostream & operator<<(std::ostream &stream, sawyer::Message &msg)
uint16_t crc16(int size, int init_val, uint8_t *data)
virtual std::ostream & printMessage(std::ostream &stream=std::cout)
void setPayloadLength(uint8_t len)
Message * waitNext(double timeout=0.0)
static Message * popNext()
static const size_t CRC_LENGTH
static const size_t HEADER_LENGTH
static const uint16_t CRC_INIT_VAL
uint8_t data[MAX_MSG_LENGTH]
enum sawyer::BadAckException::ackFlags ack_flag