Protocol.h
Go to the documentation of this file.
1 
37 #ifndef LibMultiSense_details_wire_protocol
38 #define LibMultiSense_details_wire_protocol
39 
40 #include <stdint.h>
41 
42 #include "../utility/Portability.hh"
43 
44 // Expose some configuration constants to the preprocessor (at least until C++17)
45 #ifndef MULTISENSE_WIRE_BITS_PER_PIXEL
46 #define MULTISENSE_WIRE_BITS_PER_PIXEL (12)
47 #endif
48 
49 #ifndef MULTISENSE_API_BITS_PER_PIXEL
50 #define MULTISENSE_API_BITS_PER_PIXEL (16)
51 #endif
52 
53 namespace crl {
54 namespace multisense {
55 namespace details {
56 namespace wire {
57 
58 //
59 // Some message headers are directly used by sensor firmware
60 
61 #ifdef SENSORPOD_FIRMWARE
62 #define WIRE_HEADER_ATTRIBS_ __attribute__ ((__packed__))
63 #else
64 #define WIRE_HEADER_ATTRIBS_
65 #endif // SENSORPOD_FIRMWARE
66 
67 //
68 // The size of the combined headers
69 
71 
72 //
73 // The magic number and version
74 
75 static CRL_CONSTEXPR uint16_t HEADER_MAGIC = 0xadad;
76 static CRL_CONSTEXPR uint16_t HEADER_VERSION = 0x0100;
77 
78 //
79 // The protocol group (TODO: define CRL-wide)
80 
81 static CRL_CONSTEXPR uint16_t HEADER_GROUP = 0x0001;
82 
83 //
84 // The packet header structure
85 
86 #if defined (_MSC_VER)
87 #pragma pack(push, 1)
88 typedef struct {
89 #else
90 typedef struct __attribute__ ((__packed__)) {
91 #endif
92  //
93  // The magic number
94 
95  uint16_t magic;
96 
97  //
98  // The protocol version
99 
100  uint16_t version;
101 
102  //
103  // The protocol group
104 
105  uint16_t group;
106 
107  //
108  // Protocol flags
109 
110  uint16_t flags;
111 
112  //
113  // The message sequence identifier
114 
115  uint16_t sequenceIdentifier;
116 
117  //
118  // The total size of the message
119 
120  uint32_t messageLength;
121 
122  //
123  // Offset of this packet's payload
124 
125  uint32_t byteOffset;
126 
128 #if defined (_MSC_VER)
129 #pragma pack(pop)
130 #endif
131 
132 //
133 // Types for message IDs and versions
134 
135 typedef uint16_t IdType;
136 typedef uint16_t VersionType;
137 
138 //
139 // Every command responsds with an ID_ACK message,
140 // regardless if a data message is also following.
141 
142 //
143 // TODO: this message set is still awkward in places:
144 // - Missing 1:1 get/set
145 // - Some "Data" messages are also commands
146 // - Duplicated information (CAM_GET_CONFIG, SYS_GET_CAMERA_CAL, etc.)
147 
148 //
149 // [N]acks
150 
151 static CRL_CONSTEXPR IdType ID_ACK = 0x0001;
152 
153 //
154 // Commands
155 
156 static CRL_CONSTEXPR IdType ID_CMD_GET_VERSION = 0x0002;
157 static CRL_CONSTEXPR IdType ID_CMD_GET_STATUS = 0x0003;
158 static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_CONFIG = 0x0004;
159 static CRL_CONSTEXPR IdType ID_CMD_CAM_CONTROL = 0x0007;
160 static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_HISTORY = 0x0008;
161 static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_HDR = 0x000b;
163 static CRL_CONSTEXPR IdType ID_CMD_LIDAR_GET_CONFIG = 0x000d;
164 static CRL_CONSTEXPR IdType ID_CMD_LIDAR_SET_MOTOR = 0x0010;
165 static CRL_CONSTEXPR IdType ID_CMD_LED_GET_STATUS = 0x0012;
166 static CRL_CONSTEXPR IdType ID_CMD_LED_SET = 0x0013;
167 static CRL_CONSTEXPR IdType ID_CMD_SYS_MTU = 0x0014;
168 static CRL_CONSTEXPR IdType ID_CMD_SYS_FLASH_OP = 0x0015;
169 static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_NETWORK = 0x0016;
173 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_MTU = 0x001a;
174 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_NETWORK = 0x001b;
175 static CRL_CONSTEXPR IdType ID_CMD_STREAM_CONTROL = 0x001c;
178 static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_INFO = 0x001f;
179 static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_CONFIG = 0x0020;
180 static CRL_CONSTEXPR IdType ID_CMD_SYS_TEST_MTU = 0x0021;
187 static CRL_CONSTEXPR IdType ID_CMD_SYS_MOTOR_POLL = 0x0028;
188 static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_PTP = 0x0029;
189 
190 //
191 // Data
192 
193 static CRL_CONSTEXPR IdType ID_DATA_VERSION = 0x0102;
194 static CRL_CONSTEXPR IdType ID_DATA_STATUS = 0x0103;
195 static CRL_CONSTEXPR IdType ID_DATA_CAM_CONFIG = 0x0104;
196 static CRL_CONSTEXPR IdType ID_DATA_CAM_HISTORY = 0x0105;
197 static CRL_CONSTEXPR IdType ID_DATA_LIDAR_CONFIG = 0x0108;
198 static CRL_CONSTEXPR IdType ID_DATA_LIDAR_SCAN = 0x0109;
199 static CRL_CONSTEXPR IdType ID_DATA_LED_STATUS = 0x010a;
201 static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_INFO = 0x010c;
202 static CRL_CONSTEXPR IdType ID_DATA_SYS_CAMERA_CAL = 0x010d;
203 static CRL_CONSTEXPR IdType ID_DATA_SYS_LIDAR_CAL = 0x010e;
204 static CRL_CONSTEXPR IdType ID_DATA_IMAGE_META = 0x010f;
205 static CRL_CONSTEXPR IdType ID_DATA_IMAGE = 0x0110;
206 static CRL_CONSTEXPR IdType ID_DATA_DISPARITY = 0x0111;
208 static CRL_CONSTEXPR IdType ID_DATA_SYS_PPS = 0x0113;
209 static CRL_CONSTEXPR IdType ID_DATA_IMU = 0x0114;
210 static CRL_CONSTEXPR IdType ID_DATA_IMU_INFO = 0x0115;
211 static CRL_CONSTEXPR IdType ID_DATA_IMU_CONFIG = 0x0116;
213 static CRL_CONSTEXPR IdType ID_DATA_JPEG_IMAGE = 0x0118;
215 static CRL_CONSTEXPR IdType ID_DATA_SYS_SENSOR_CAL = 0x011a;
218 static CRL_CONSTEXPR IdType ID_DATA_SYS_MOTOR_POLL = 0x011d;
219 
220 //
221 // Data sources
222 
223 typedef uint32_t SourceType;
224 
225 static CRL_CONSTEXPR SourceType SOURCE_UNKNOWN = 0;
226 static CRL_CONSTEXPR SourceType SOURCE_RAW_LEFT = (1U<<0);
227 static CRL_CONSTEXPR SourceType SOURCE_RAW_RIGHT = (1U<<1);
228 static CRL_CONSTEXPR SourceType SOURCE_LUMA_LEFT = (1U<<2);
229 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RIGHT = (1U<<3);
230 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_LEFT = (1U<<4);
231 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_RIGHT = (1U<<5);
232 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_LEFT = (1U<<6);
233 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RIGHT = (1U<<7);
234 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RECT_AUX = (1U<<8);
235 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY = (1U<<10);
236 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_LEFT = (1U<<10); // same as SOURCE_DISPARITY
237 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_RIGHT = (1U<<11);
238 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_COST = (1U<<12);
239 static CRL_CONSTEXPR SourceType SOURCE_JPEG_LEFT = (1U<<16);
240 static CRL_CONSTEXPR SourceType SOURCE_RGB_LEFT = (1U<<17);
241 static CRL_CONSTEXPR SourceType SOURCE_SLB_MOTOR = (1U<<23);
242 static CRL_CONSTEXPR SourceType SOURCE_LIDAR_SCAN = (1U<<24);
243 static CRL_CONSTEXPR SourceType SOURCE_IMU = (1U<<25);
244 static CRL_CONSTEXPR SourceType SOURCE_PPS = (1U<<26);
245 static CRL_CONSTEXPR SourceType SOURCE_RAW_AUX = (1U<<27);
246 static CRL_CONSTEXPR SourceType SOURCE_LUMA_AUX = (1U<<28);
247 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_AUX = (1U<<29);
248 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_AUX = (1U<<30);
249 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_AUX = (1U<<31);
250 static CRL_CONSTEXPR SourceType SOURCE_IMAGES = (SOURCE_RAW_LEFT |
251  SOURCE_RAW_RIGHT |
252  SOURCE_RAW_AUX |
253  SOURCE_LUMA_LEFT |
254  SOURCE_LUMA_RIGHT |
255  SOURCE_LUMA_AUX |
256  SOURCE_LUMA_RECT_LEFT |
257  SOURCE_LUMA_RECT_RIGHT |
258  SOURCE_LUMA_RECT_AUX |
259  SOURCE_CHROMA_LEFT |
260  SOURCE_CHROMA_RIGHT |
261  SOURCE_CHROMA_AUX |
262  SOURCE_CHROMA_RECT_AUX |
263  SOURCE_DISPARITY_LEFT |
264  SOURCE_DISPARITY_RIGHT |
265  SOURCE_DISPARITY_COST |
266  SOURCE_DISPARITY_AUX |
267  SOURCE_JPEG_LEFT |
269 
270 //
271 // Some helper macros
272 
273 #define MSG_ID(x) ((wire::IdType)(x))
274 #define MSG_VER(x) ((wire::VersionType)(x))
275 
276 #define SER_ARRAY_1(a_,n_) \
277  for(uint32_t i_=0; i_<(n_); i_++) \
278  message & (a_)[i_]; \
279 
280 #define SER_ARRAY_2(a_,n_,m_) \
281  for(uint32_t i_=0; i_<(n_); i_++) \
282  for(uint32_t j_=0; j_<(m_); j_++) \
283  message & (a_)[(i_)][(j_)]; \
284 
285 #define CPY_ARRAY_1(d_,s_,n_) \
286  for(uint32_t i_=0; i_<(n_); i_++) \
287  (d_)[i_] = (s_)[i_]; \
288 
289 #define CPY_ARRAY_2(d_,s_,n_,m_) \
290  for(uint32_t i_=0; i_<(n_); i_++) \
291  for(uint32_t j_=0; j_<(m_); j_++) \
292  (d_)[i_][j_] = (s_)[i_][j_]; \
293 
294 }}}} // namespaces
295 
296 #endif
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_CAMERA_CAL
Definition: Protocol.h:171
static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_HISTORY
Definition: Protocol.h:160
static CRL_CONSTEXPR IdType ID_DATA_LED_STATUS
Definition: Protocol.h:199
static CRL_CONSTEXPR IdType ID_CMD_STREAM_CONTROL
Definition: Protocol.h:175
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_AUX
Definition: Protocol.h:247
static CRL_CONSTEXPR SourceType SOURCE_LUMA_AUX
Definition: Protocol.h:246
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY
Definition: Protocol.h:235
struct __attribute__((__packed__))
Definition: Protocol.h:90
static CRL_CONSTEXPR SourceType SOURCE_SLB_MOTOR
Definition: Protocol.h:241
static CRL_CONSTEXPR SourceType SOURCE_RAW_AUX
Definition: Protocol.h:245
static CRL_CONSTEXPR IdType ID_CMD_LIDAR_SET_MOTOR
Definition: Protocol.h:164
static CRL_CONSTEXPR IdType ID_CMD_CAM_CONTROL
Definition: Protocol.h:159
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_AUX
Definition: Protocol.h:249
static CRL_CONSTEXPR IdType ID_DATA_SYS_TEST_MTU_RESPONSE
Definition: Protocol.h:212
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RECT_AUX
Definition: Protocol.h:234
static CRL_CONSTEXPR IdType ID_DATA_IMAGE
Definition: Protocol.h:205
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_TRANSMIT_DELAY
Definition: Protocol.h:185
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_RIGHT
Definition: Protocol.h:237
static CRL_CONSTEXPR IdType ID_DATA_IMU
Definition: Protocol.h:209
static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_INFO
Definition: Protocol.h:178
static CRL_CONSTEXPR IdType ID_CMD_LED_GET_SENSOR_STATUS
Definition: Protocol.h:184
static CRL_CONSTEXPR IdType ID_DATA_STATUS
Definition: Protocol.h:194
static CRL_CONSTEXPR IdType ID_DATA_SYS_EXTERNAL_CAL
Definition: Protocol.h:216
static CRL_CONSTEXPR IdType ID_DATA_SYS_DIRECTED_STREAMS
Definition: Protocol.h:214
static CRL_CONSTEXPR SourceType SOURCE_IMAGES
Definition: Protocol.h:250
static CRL_CONSTEXPR IdType ID_DATA_IMU_INFO
Definition: Protocol.h:210
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_LIDAR_CAL
Definition: Protocol.h:172
static CRL_CONSTEXPR IdType ID_DATA_SYS_SENSOR_CAL
Definition: Protocol.h:215
static CRL_CONSTEXPR uint8_t COMBINED_HEADER_LENGTH
Definition: Protocol.h:70
static CRL_CONSTEXPR SourceType SOURCE_LUMA_LEFT
Definition: Protocol.h:228
static CRL_CONSTEXPR IdType ID_CMD_GET_STATUS
Definition: Protocol.h:157
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_SENSOR_CAL
Definition: Protocol.h:182
static CRL_CONSTEXPR IdType ID_CMD_SYS_MOTOR_POLL
Definition: Protocol.h:187
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_LEFT
Definition: Protocol.h:236
static CRL_CONSTEXPR IdType ID_DATA_CAM_HISTORY
Definition: Protocol.h:196
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DIRECTED_STREAMS
Definition: Protocol.h:181
static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_INFO
Definition: Protocol.h:201
static CRL_CONSTEXPR uint16_t HEADER_VERSION
Definition: Protocol.h:76
static CRL_CONSTEXPR IdType ID_DATA_DISPARITY
Definition: Protocol.h:206
static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_CONFIG
Definition: Protocol.h:158
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RIGHT
Definition: Protocol.h:233
static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_HDR
Definition: Protocol.h:161
static CRL_CONSTEXPR IdType ID_DATA_LED_SENSOR_STATUS
Definition: Protocol.h:217
static CRL_CONSTEXPR IdType ID_CMD_LIDAR_GET_CONFIG
Definition: Protocol.h:163
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_RIGHT
Definition: Protocol.h:231
static CRL_CONSTEXPR IdType ID_DATA_JPEG_IMAGE
Definition: Protocol.h:213
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_EXTERNAL_CAL
Definition: Protocol.h:183
static CRL_CONSTEXPR IdType ID_DATA_CAM_CONFIG
Definition: Protocol.h:195
static CRL_CONSTEXPR IdType ID_DATA_VERSION
Definition: Protocol.h:193
Definition: channel.cc:56
static CRL_CONSTEXPR IdType ID_CMD_SYS_FLASH_OP
Definition: Protocol.h:168
static CRL_CONSTEXPR IdType ID_DATA_IMU_CONFIG
Definition: Protocol.h:211
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_LEFT
Definition: Protocol.h:232
static CRL_CONSTEXPR SourceType SOURCE_UNKNOWN
Definition: Protocol.h:225
static CRL_CONSTEXPR SourceType SOURCE_RAW_RIGHT
Definition: Protocol.h:227
static CRL_CONSTEXPR IdType ID_DATA_SYS_MOTOR_POLL
Definition: Protocol.h:218
static CRL_CONSTEXPR IdType ID_DATA_IMAGE_META
Definition: Protocol.h:204
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DEVICE_MODES
Definition: Protocol.h:176
static CRL_CONSTEXPR IdType ID_CMD_GET_VERSION
Definition: Protocol.h:156
static CRL_CONSTEXPR SourceType SOURCE_IMU
Definition: Protocol.h:243
static CRL_CONSTEXPR IdType ID_CMD_LED_GET_STATUS
Definition: Protocol.h:165
static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_MODES
Definition: Protocol.h:207
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_LEFT
Definition: Protocol.h:230
static CRL_CONSTEXPR uint16_t HEADER_MAGIC
Definition: Protocol.h:75
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_COST
Definition: Protocol.h:238
static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_RESOLUTION
Definition: Protocol.h:162
static CRL_CONSTEXPR IdType ID_DATA_SYS_PPS
Definition: Protocol.h:208
static CRL_CONSTEXPR SourceType SOURCE_RGB_LEFT
Definition: Protocol.h:240
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_NETWORK
Definition: Protocol.h:174
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_MTU
Definition: Protocol.h:173
static CRL_CONSTEXPR IdType ID_ACK
Definition: Protocol.h:151
static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_TRIGGER_SOURCE
Definition: Protocol.h:177
static CRL_CONSTEXPR IdType ID_DATA_SYS_CAMERA_CAL
Definition: Protocol.h:202
static CRL_CONSTEXPR IdType ID_CMD_LED_SET
Definition: Protocol.h:166
static CRL_CONSTEXPR uint16_t HEADER_GROUP
Definition: Protocol.h:81
static CRL_CONSTEXPR IdType ID_DATA_LIDAR_SCAN
Definition: Protocol.h:198
static CRL_CONSTEXPR IdType ID_CMD_SYS_TEST_MTU
Definition: Protocol.h:180
static CRL_CONSTEXPR SourceType SOURCE_RAW_LEFT
Definition: Protocol.h:226
static CRL_CONSTEXPR SourceType SOURCE_LIDAR_SCAN
Definition: Protocol.h:242
static CRL_CONSTEXPR SourceType SOURCE_PPS
Definition: Protocol.h:244
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RIGHT
Definition: Protocol.h:229
static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_CONFIG
Definition: Protocol.h:179
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DEVICE_INFO
Definition: Protocol.h:170
static CRL_CONSTEXPR IdType ID_DATA_LIDAR_CONFIG
Definition: Protocol.h:197
static CRL_CONSTEXPR IdType ID_DATA_SYS_LIDAR_CAL
Definition: Protocol.h:203
static CRL_CONSTEXPR IdType ID_DATA_SYS_FLASH_RESPONSE
Definition: Protocol.h:200
static CRL_CONSTEXPR IdType ID_CMD_SYS_MTU
Definition: Protocol.h:167
#define CRL_CONSTEXPR
Definition: Portability.hh:51
static CRL_CONSTEXPR SourceType SOURCE_JPEG_LEFT
Definition: Protocol.h:239
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_TRANSMIT_DELAY
Definition: Protocol.h:186
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_AUX
Definition: Protocol.h:248
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_PTP
Definition: Protocol.h:188
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_NETWORK
Definition: Protocol.h:169


multisense_lib
Author(s):
autogenerated on Sun Mar 14 2021 02:34:50