38 #ifndef SAWYER_MESSAGE_H 39 #define SAWYER_MESSAGE_H 70 static const size_t MAX_MSG_LENGTH = 256;
72 uint8_t
data[MAX_MSG_LENGTH];
77 static const size_t CRC_LENGTH = 2;
78 static const uint16_t CRC_INIT_VAL = 0xFFFF;
80 static const size_t HEADER_LENGTH = 8;
102 static const size_t MIN_MSG_LENGTH = HEADER_LENGTH + CRC_LENGTH;
103 static const uint8_t SOH = 0xAA;
104 static const uint8_t STX = 0x55;
109 return total_len - CRC_LENGTH;
112 void setLength(uint8_t len);
114 void setVersion(uint8_t version);
117 void setFlags(uint8_t flags);
119 void setType(uint16_t
type);
121 uint8_t *getPayloadPointer(
size_t offset = 0);
123 void setPayload(
void *buf,
size_t buf_size);
125 void setPayloadLength(uint8_t len);
132 Message(
void *input,
size_t msg_len);
136 Message(uint16_t type, uint8_t *payload,
size_t payload_len,
137 uint32_t timestamp = 0, uint8_t flags = 0, uint8_t version = 0);
145 uint8_t getLengthComp();
147 uint8_t getVersion();
152 size_t getType(
void *buf,
size_t max_size);
154 uint16_t getChecksum();
158 return ((total_len - HEADER_LENGTH - CRC_LENGTH));
163 return ((total_len - HEADER_LENGTH - CRC_LENGTH));
166 size_t getPayload(
void *buf,
size_t max_size);
173 size_t toBytes(
void *buf,
size_t buf_size);
175 bool isValid(
char *whyNot = NULL,
size_t strLen = 0);
179 return getType() < 0x4000;
184 return (getType() >= 0x4000) && (getType() < 0x8000);
189 return (getType() >= 0x8000) && (getType() < 0xC000);
192 virtual std::ostream &printMessage(std::ostream &stream = std::cout);
196 void printRaw(std::ostream &stream = std::cout);
199 static Message *factory(
void *input,
size_t msg_len);
203 static Message *waitNext(
double timeout = 0.0);
324 #endif // sawyer_MESSAGE_H
MessageException(const char *msg, enum errors ex_type=ERROR_BASE)
std::ostream & operator<<(std::ostream &stream, sawyer::Message &msg)
size_t getPayloadLength()
bool isValid(const trajectory_msgs::JointTrajectoryPoint &point, const unsigned int joint_dim)