protocol.h
Go to the documentation of this file.
1 //
2 // Created by ch on 24-11-23.
3 //
4 #pragma once
5 #define __packed __attribute__((packed))
6 
7 #include <cstdint>
8 namespace rm_vt
9 {
10 typedef enum
11 {
12  CUSTOM_CONTROLLER_CMD = 0x0302, // custom_controller
13  ROBOT_COMMAND_CMD = 0x0304, // keyboard_data
16 
17 typedef struct
18 {
19  uint8_t sof;
20  uint16_t data_length;
21  uint8_t seq;
22  uint8_t crc_8;
23 } __packed FrameHeader;
24 
25 typedef struct
26 {
27  uint8_t encoder1_data[2];
28  uint8_t encoder2_data[2];
29  uint8_t encoder3_data[2];
30  uint8_t encoder4_data[2];
31  uint8_t encoder5_data[2];
32  uint8_t encoder6_data[2];
33  uint8_t joystick_l_y_data[2];
34  uint8_t joystick_l_x_data[2];
35  uint8_t joystick_r_y_data[2];
36  uint8_t joystick_r_x_data[2];
37  uint8_t button1_data : 1;
38  uint8_t button2_data : 1;
39  uint8_t button3_data : 1;
40  uint8_t button4_data : 1;
41  uint8_t unused_button_data : 4;
42  uint8_t unused_data_1;
43  uint8_t unused_data_2;
44  uint8_t unused_data_3;
45  uint8_t unused_data_4;
46  uint8_t unused_data_5;
47  uint8_t unused_data_6;
48  uint8_t unused_data_7;
49  uint8_t unused_data_8;
50  uint8_t unused_data_9;
51 } __packed CustomControllerData;
52 
53 typedef struct
54 {
55  uint8_t data[30];
56 } __packed RobotToCustomData;
57 
58 typedef struct
59 {
60  int16_t mouse_x;
61  int16_t mouse_y;
62  int16_t mouse_z;
65  uint16_t key_w : 1;
66  uint16_t key_s : 1;
67  uint16_t key_a : 1;
68  uint16_t key_d : 1;
69  uint16_t key_shift : 1;
70  uint16_t key_ctrl : 1;
71  uint16_t key_q : 1;
72  uint16_t key_e : 1;
73  uint16_t key_r : 1;
74  uint16_t key_f : 1;
75  uint16_t key_g : 1;
76  uint16_t key_z : 1;
77  uint16_t key_x : 1;
78  uint16_t key_c : 1;
79  uint16_t key_v : 1;
80  uint16_t key_b : 1;
81  uint16_t reserved;
82 } __packed KeyboardMouseData;
83 
84 typedef struct
85 {
86  uint16_t joystick_r_x : 11;
87  uint16_t joystick_r_y : 11;
88  uint16_t joystick_l_y : 11;
89  uint16_t joystick_l_x : 11;
90  uint8_t mode_switch : 2;
91  uint8_t pause_button : 1;
92  uint8_t custom_button_l : 1;
93  uint8_t custom_button_r : 1;
94  uint16_t wheel : 11;
95  uint8_t trigger : 1;
96  uint8_t unused_1 : 3;
97  // mouse
98  int16_t mouse_x;
99  int16_t mouse_y;
100  int16_t mouse_wheel;
101  uint8_t mouse_left_down : 2;
102  uint8_t mouse_right_down : 2;
103  uint8_t mouse_mid_down : 2;
104  uint8_t unused_2 : 2;
105  // keyboard
106  uint16_t key_w : 1;
107  uint16_t key_s : 1;
108  uint16_t key_a : 1;
109  uint16_t key_d : 1;
110  uint16_t key_shift : 1;
111  uint16_t key_ctrl : 1;
112  uint16_t key_q : 1;
113  uint16_t key_e : 1;
114  uint16_t key_r : 1;
115  uint16_t key_f : 1;
116  uint16_t key_g : 1;
117  uint16_t key_z : 1;
118  uint16_t key_x : 1;
119  uint16_t key_c : 1;
120  uint16_t key_v : 1;
121  uint16_t key_b : 1;
122 } __packed ControlData;
123 /***********************Frame tail(CRC8_CRC16)********************************************/
124 const uint8_t kCrc8Init = 0xff;
125 const uint8_t kCrc8Table[256] = {
126  0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21,
127  0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c,
128  0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62, 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c,
129  0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff, 0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66,
130  0xe5, 0xbb, 0x59, 0x07, 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4,
131  0x9a, 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24, 0xf8, 0xa6,
132  0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, 0x8c, 0xd2, 0x30, 0x6e, 0xed,
133  0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd, 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92,
134  0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50, 0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1,
135  0x8f, 0x0c, 0x52, 0xb0, 0xee, 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf,
136  0x2d, 0x73, 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b, 0x57,
137  0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, 0xe9, 0xb7, 0x55, 0x0b,
138  0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8, 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9,
139  0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35,
140 };
141 const uint16_t kCrc16Init = 0xffff;
142 const uint16_t wCRC_table[256] = {
143  0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5,
144  0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52,
145  0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3,
146  0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
147  0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9,
148  0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e,
149  0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f,
150  0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
151  0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862,
152  0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb,
153  0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948,
154  0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
155  0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226,
156  0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497,
157  0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704,
158  0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
159  0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb,
160  0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c,
161  0x3de3, 0x2c6a, 0x1ef1, 0x0f78
162 };
163 } // namespace rm_vt
rm_vt::kCrc8Init
const uint8_t kCrc8Init
Definition: protocol.h:124
rm_vt::__packed::mouse_z
int16_t mouse_z
Definition: protocol.h:62
rm_vt::CUSTOM_CONTROLLER_CMD
@ CUSTOM_CONTROLLER_CMD
Definition: protocol.h:12
rm_vt::__packed::key_f
uint16_t key_f
Definition: protocol.h:74
rm_vt::__packed::pause_button
uint8_t pause_button
Definition: protocol.h:91
rm_vt
Definition: data.h:25
rm_vt::__packed::right_button_down
int8_t right_button_down
Definition: protocol.h:64
rm_vt::__packed::unused_data_5
uint8_t unused_data_5
Definition: protocol.h:46
rm_vt::__packed::unused_1
uint8_t unused_1
Definition: protocol.h:96
rm_vt::__packed::button1_data
uint8_t button1_data
Definition: protocol.h:37
rm_vt::__packed::key_r
uint16_t key_r
Definition: protocol.h:73
rm_vt::__packed::unused_data_4
uint8_t unused_data_4
Definition: protocol.h:45
rm_vt::__packed::sof
uint8_t sof
Definition: protocol.h:19
rm_vt::__packed::key_q
uint16_t key_q
Definition: protocol.h:71
rm_vt::__packed::button3_data
uint8_t button3_data
Definition: protocol.h:39
rm_vt::__packed::key_d
uint16_t key_d
Definition: protocol.h:68
rm_vt::__packed::key_w
uint16_t key_w
Definition: protocol.h:65
rm_vt::ROBOT_TO_CUSTOM_CMD
@ ROBOT_TO_CUSTOM_CMD
Definition: protocol.h:14
rm_vt::__packed::custom_button_l
uint8_t custom_button_l
Definition: protocol.h:92
rm_vt::__packed::unused_2
uint8_t unused_2
Definition: protocol.h:104
rm_vt::__packed::crc_8
uint8_t crc_8
Definition: protocol.h:22
rm_vt::__packed::joystick_r_x
uint16_t joystick_r_x
Definition: protocol.h:86
rm_vt::__packed::seq
uint8_t seq
Definition: protocol.h:21
rm_vt::__packed::unused_data_8
uint8_t unused_data_8
Definition: protocol.h:49
rm_vt::__packed::key_c
uint16_t key_c
Definition: protocol.h:78
rm_vt::wCRC_table
const uint16_t wCRC_table[256]
Definition: protocol.h:142
rm_vt::__packed::unused_data_6
uint8_t unused_data_6
Definition: protocol.h:47
rm_vt::__packed::wheel
uint16_t wheel
Definition: protocol.h:94
rm_vt::__packed::button2_data
uint8_t button2_data
Definition: protocol.h:38
rm_vt::__packed::key_ctrl
uint16_t key_ctrl
Definition: protocol.h:70
rm_vt::__packed::joystick_l_y
uint16_t joystick_l_y
Definition: protocol.h:88
rm_vt::__packed::reserved
uint16_t reserved
Definition: protocol.h:81
rm_vt::__packed::mouse_y
int16_t mouse_y
Definition: protocol.h:61
rm_vt::__packed::key_z
uint16_t key_z
Definition: protocol.h:76
rm_vt::__packed
Definition: protocol.h:17
rm_vt::__packed::unused_data_1
uint8_t unused_data_1
Definition: protocol.h:42
rm_vt::__packed::unused_button_data
uint8_t unused_button_data
Definition: protocol.h:41
rm_vt::__packed::button4_data
uint8_t button4_data
Definition: protocol.h:40
rm_vt::VideoTransmissionCmdId
VideoTransmissionCmdId
Definition: protocol.h:10
rm_vt::__packed::data_length
uint16_t data_length
Definition: protocol.h:20
rm_vt::ROBOT_COMMAND_CMD
@ ROBOT_COMMAND_CMD
Definition: protocol.h:13
rm_vt::__packed::key_b
uint16_t key_b
Definition: protocol.h:80
rm_vt::__packed::unused_data_7
uint8_t unused_data_7
Definition: protocol.h:48
rm_vt::__packed::mode_switch
uint8_t mode_switch
Definition: protocol.h:90
rm_vt::__packed::mouse_wheel
int16_t mouse_wheel
Definition: protocol.h:100
rm_vt::kCrc16Init
const uint16_t kCrc16Init
Definition: protocol.h:141
rm_vt::__packed::key_s
uint16_t key_s
Definition: protocol.h:66
rm_vt::__packed::mouse_right_down
uint8_t mouse_right_down
Definition: protocol.h:102
rm_vt::__packed::joystick_l_x
uint16_t joystick_l_x
Definition: protocol.h:89
rm_vt::__packed::trigger
uint8_t trigger
Definition: protocol.h:95
rm_vt::__packed::key_v
uint16_t key_v
Definition: protocol.h:79
rm_vt::__packed::mouse_left_down
uint8_t mouse_left_down
Definition: protocol.h:101
rm_vt::__packed::key_a
uint16_t key_a
Definition: protocol.h:67
rm_vt::__packed::mouse_mid_down
uint8_t mouse_mid_down
Definition: protocol.h:103
rm_vt::__packed::custom_button_r
uint8_t custom_button_r
Definition: protocol.h:93
rm_vt::__packed::key_g
uint16_t key_g
Definition: protocol.h:75
rm_vt::__packed::unused_data_2
uint8_t unused_data_2
Definition: protocol.h:43
rm_vt::__packed::key_x
uint16_t key_x
Definition: protocol.h:77
rm_vt::kCrc8Table
const uint8_t kCrc8Table[256]
Definition: protocol.h:125
rm_vt::__packed::mouse_x
int16_t mouse_x
Definition: protocol.h:60
rm_vt::__packed::left_button_down
int8_t left_button_down
Definition: protocol.h:63
rm_vt::__packed::key_e
uint16_t key_e
Definition: protocol.h:72
rm_vt::__packed::unused_data_9
uint8_t unused_data_9
Definition: protocol.h:50
rm_vt::__packed::key_shift
uint16_t key_shift
Definition: protocol.h:69
rm_vt::__packed::unused_data_3
uint8_t unused_data_3
Definition: protocol.h:44
rm_vt::__packed::joystick_r_y
uint16_t joystick_r_y
Definition: protocol.h:87


rm_vt
Author(s):
autogenerated on Tue May 6 2025 02:23:53