21 #ifndef __PLUGINS_ROBOTINO_DIRECT_COM_MESSAGE_H_ 22 #define __PLUGINS_ROBOTINO_DIRECT_COM_MESSAGE_H_ 24 #include <core/exception.h> 27 #include <boost/asio.hpp> 33 typedef std::shared_ptr<DirectRobotinoComMessage>
pointer;
38 CMDID_GET_HW_VERSION = 1,
40 CMDID_GET_SW_VERSION = 3,
42 CMDID_GET_DISTANCE_SENSOR_READINGS = 5,
43 CMDID_DISTANCE_SENSOR_READINGS = 6,
44 CMDID_GET_ADC_PARAMETERS = 7,
45 CMDID_ADC_PARAMETERS = 8,
46 CMDID_SET_MOTOR_SPEED = 9,
47 CMDID_GET_ALL_MOTOR_SPEEDS = 10,
48 CMDID_ALL_MOTOR_SPEEDS = 11,
49 CMDID_SET_MOTOR_POSITION = 12,
50 CMDID_GET_ALL_MOTOR_POSITIONS = 13,
51 CMDID_ALL_MOTOR_POSITIONS = 14,
52 CMDID_SET_MOTOR_PID_PARAMETERS = 15,
53 CMDID_GET_ALL_MOTOR_PID_PARAMETERS = 16,
54 CMDID_ALL_MOTOR_PID_PARAMETERS = 17,
55 CMDID_SET_ALL_DIGITAL_OUTPUTS = 18,
56 CMDID_SET_ALL_RELAYS = 19,
57 CMDID_SET_ODOMETRY = 20,
58 CMDID_SET_ODOMETRY_ROTATION = 21,
59 CMDID_GET_ODOMETRY = 22,
61 CMDID_GET_ALL_MOTOR_CURRENT_READINGS = 26,
62 CMDID_ALL_MOTOR_CURRENT_READINGS = 27,
63 CMDID_GET_ALL_ANALOG_INPUTS = 32,
64 CMDID_ALL_ANALOG_INPUTS = 33,
65 CMDID_GET_ALL_DIGITAL_INPUTS = 34,
66 CMDID_ALL_DIGITAL_INPUTS = 35,
67 CMDID_GET_BUMPER = 36,
69 CMDID_GET_POWER_BUTTON = 38,
70 CMDID_POWER_BUTTON = 39,
71 CMDID_SET_FPGA_POWER = 40,
72 CMDID_GET_FPGA_POWER = 41,
73 CMDID_FPGA_POWER = 42,
74 CMDID_GET_PWR_OK_STATE = 43,
75 CMDID_PWR_OK_STATE = 44,
76 CMDID_SET_PWR_OK_STATE = 45,
78 CMDID_SET_MOTOR_ON = 47,
79 CMDID_SET_PWRBTN = 48,
80 CMDID_SET_SYS_RESET = 49,
81 CMDID_GET_COM_EXPRESS_STATES = 50,
82 CMDID_COM_EXPRESS_STATES = 51,
83 CMDID_GET_ALL_MOTOR_READINGS = 52,
84 CMDID_ALL_MOTOR_READINGS = 53,
85 CMDID_GET_IP_ADDRESS = 54,
86 CMDID_IP_ADDRESS = 55,
87 CMDID_SET_IP_ADDRESS = 56,
88 CMDID_SET_EMERGENCY_BUMPER = 57,
89 CMDID_SET_MOTOR_MODE = 58,
92 CMDID_SET_SAFTEY_VELOCITY = 61,
93 CMDID_GET_SAFTEY_VELOCITY = 62,
94 CMDID_SAFTEY_VELOCITY = 63,
95 CMDID_POWER_SOURCE_READINGS = 65,
96 CMDID_SET_MOTOR_ACCEL_LIMITS = 66,
97 CMDID_MOTOR_ACCEL_LIMITS = 67,
98 CMDID_GET_MOTOR_ACCEL_LIMITS = 68,
99 CMDID_GET_GYRO_Z_ANGLE = 69,
100 CMDID_GYRO_Z_ANGLE = 70,
101 CMDID_GET_CAN_MSG = 71,
109 CMDID_CONFIG_RESET = 79,
110 CMDID_CHARGER_INFO = 80,
111 CMDID_CHARGER_EVENT = 81,
112 CMDID_CHARGER_VERSION = 82,
113 CMDID_CHARGER_GET_VERSION = 83,
114 CMDID_CHARGER_CLEAR_ERROR = 84,
115 CMDID_CHARGER_ERROR = 85,
116 CMDID_SET_BATTERY_MIN = 86,
117 CMDID_GET_BATTERY_MIN = 87,
118 CMDID_BATTERY_MIN = 88,
119 CMDID_GET_GYRODATA = 89,
121 CMDID_GET_GPAIN = 91,
123 CMDID_GET_VERSIONBITS = 93,
124 CMDID_VERSIONBITS = 94,
125 CMDID_GYRO_SET_PARAM = 95,
126 CMDID_GYRO_GET_PARAM = 96,
127 CMDID_GYRO_PARAM = 97,
141 static const unsigned char MSG_HEAD;
142 static const unsigned char MSG_DATA_ESCAPE;
143 static const unsigned char MSG_DATA_MANGLE;
144 static const unsigned int MSG_METADATA_SIZE;
151 unsigned char byte1,
unsigned char byte2);
189 boost::asio::const_buffer
buffer();
194 std::string
to_string(
bool escaped =
false);
196 static size_t unescape(
unsigned char *unescaped,
size_t unescaped_size,
197 const unsigned char *escaped,
size_t escaped_size);
207 void assert_mode(mode_t mode)
const;
208 void assert_command()
const;
209 void assert_command_data(uint8_t size)
const;
211 void inc_payload_by(uint16_t count);
213 size_t unescape_data();
214 void check_checksum()
const;
219 unsigned char *data_;
220 unsigned short data_size_;
221 unsigned short payload_size_;
222 unsigned char *escaped_data_;
223 unsigned short escaped_data_size_;
225 unsigned char *cur_cmd_;
226 unsigned char *cur_data_;
void add_uint32(uint32_t value)
Add 32-bit unsigned integer to current command.
int8_t get_int8()
Get 8-bit signed integer from current command.
void add_uint16(uint16_t value)
Add 16-bit unsigned integer to current command.
void add_command(command_id_t cmdid)
Add a command header.
ChecksumError(unsigned int expected, unsigned int received, unsigned char byte1, unsigned char byte2)
Constructor.
DirectRobotinoComMessage()
Constructor.
void add_uint8(uint8_t value)
Add 8-bit unsigned integer to current command.
void skip_uint16()
Skip 16-bit unsigned integer from current command.
void skip_int8()
Skip 8-bit signed integer from current command.
std::string to_string(bool escaped=false)
Generate string representation of message.
void rewind()
Rewind to read again from start.
std::string get_string()
Get string from current command.
void skip_float()
Skip float from current command.
virtual ~DirectRobotinoComMessage()
Destructor.
float get_float()
Get float from current command.
std::shared_ptr< DirectRobotinoComMessage > pointer
shared pointer to direct com message
boost::asio::const_buffer buffer()
Get access to buffer for sending.
Robotino communication message.
size_t data_size()
Get internal data buffer size.
size_t payload_size()
Get payload size.
void add_int16(int16_t value)
Add 16-bit signed integer to current command.
Base class for exceptions in Fawkes.
void add_int32(int32_t value)
Add 32-bit signed integer to current command.
void skip_int32()
Skip 32-bit signed integer from current command.
void skip_int16()
Skip 16-bit signed integer from current command.
uint32_t get_uint32()
Get 32-bit unsigned integer from current command.
uint16_t get_uint16()
Get 16-bit unsigned integer from current command.
int32_t get_int32()
Get 32-bit signed integer from current command.
command_id_t next_command()
Get next available command.
static uint16_t parse_uint16(const unsigned char *buf)
Parse 16-bit unsigned integer from given buffer.
static size_t unescape(unsigned char *unescaped, size_t unescaped_size, const unsigned char *escaped, size_t escaped_size)
Unescape a number of unescaped bytes.
void skip_uint8()
Skip 8-bit unsigned integer from current command.
uint16_t checksum() const
Get checksum of message.
command_id_t command_id() const
Get ID of current command.
void skip_uint32()
Skip 32-bit unsigned integer from current command.
void add_int8(int8_t value)
Add 8-bit signed integer to current command.
int16_t get_int16()
Get 16-bit signed integer from current command.
uint8_t get_uint8()
Get 8-bit unsigned integer from current command.
size_t escaped_data_size()
Size of escaped buffer.
void add_float(float value)
Add float to current command.
uint8_t command_length() const
Get length of current command.
Excpetion thrown on checksum errors.