LibMultiSense
LibMultiSense Documentation
Loading...
Searching...
No Matches
Protocol.hh
Go to the documentation of this file.
1
38#ifndef LibMultiSense_details_wire_protocol
39#define LibMultiSense_details_wire_protocol
40
41#include <stdint.h>
42
43#include "../utility/Portability.hh"
44
45// Expose some configuration constants to the preprocessor (at least until C++17)
46#ifndef MULTISENSE_WIRE_BITS_PER_PIXEL
47#define MULTISENSE_WIRE_BITS_PER_PIXEL (12)
48#endif
49
50#ifndef MULTISENSE_API_BITS_PER_PIXEL
51#define MULTISENSE_API_BITS_PER_PIXEL (16)
52#endif
53
54namespace crl {
55namespace multisense {
56namespace details {
57namespace wire {
58
59//
60// Some message headers are directly used by sensor firmware
61
62#ifdef SENSORPOD_FIRMWARE
63#define WIRE_HEADER_ATTRIBS_ __attribute__ ((__packed__))
64#else
65#define WIRE_HEADER_ATTRIBS_
66#endif // SENSORPOD_FIRMWARE
67
68//
69// The size of the combined headers
70
72
73//
74// The magic number and version
75
76static CRL_CONSTEXPR uint16_t HEADER_MAGIC = 0xadad;
77static CRL_CONSTEXPR uint16_t HEADER_VERSION = 0x0100;
78
79//
80// The protocol group (TODO: define CRL-wide)
81
82static CRL_CONSTEXPR uint16_t HEADER_GROUP = 0x0001;
83
84//
85// The packet header structure
86
87#if defined (_MSC_VER) || defined(__MINGW64__)
88#pragma pack(push, 1)
89typedef struct {
90#else
91typedef struct __attribute__ ((__packed__)) {
92#endif
93 //
94 // The magic number
95
96 uint16_t magic;
97
98 //
99 // The protocol version
100
101 uint16_t version;
102
103 //
104 // The protocol group
105
106 uint16_t group;
107
108 //
109 // Protocol flags
110
111 uint16_t flags;
112
113 //
114 // The message sequence identifier
115
116 uint16_t sequenceIdentifier;
117
118 //
119 // The total size of the message
120
121 uint32_t messageLength;
122
123 //
124 // Offset of this packet's payload
125
126 uint32_t byteOffset;
127
129#if defined (_MSC_VER) || defined(__MINGW64__)
130#pragma pack(pop)
131#endif
132
133//
134// Types for message IDs and versions
135
136typedef uint16_t IdType;
137typedef uint16_t VersionType;
138
139//
140// Every command responds with an ID_ACK message,
141// regardless if a data message is also following.
142
143//
144// TODO: this message set is still awkward in places:
145// - Missing 1:1 get/set
146// - Some "Data" messages are also commands
147// - Duplicated information (CAM_GET_CONFIG, SYS_GET_CAMERA_CAL, etc.)
148
149//
150// [N]acks
151
153
154//
155// Commands
156
201
202//
203// Data
204
245
246
247//
248// Data sources
249
250typedef uint64_t SourceType;
251
263static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_LEFT = (1ull<<10); // same as SOURCE_DISPARITY
284static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_RECTIFIED_RIGHT = (1ull<<16); // same as SOURCE_JPEG_LEFT
285static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_RECTIFIED_AUX = (1ull<<17); // same as SOURCE_RGB_LEFT
292
299
327 );
328
329//
330// Exposure config
331
334static CRL_CONSTEXPR float Default_Gamma = 2.0f;
335static CRL_CONSTEXPR float Default_Gain = 1.0f;
336
337static CRL_CONSTEXPR uint32_t MAX_LIGHTS = 8;
338
339static CRL_CONSTEXPR float WIRE_IMAGER_GAIN_MAX = 1000.0f;
340
341//
342// Some helper macros
343
344#define MSG_ID(x) ((crl::multisense::details::wire::IdType)(x))
345#define MSG_VER(x) ((crl::multisense::details::wire::VersionType)(x))
346
347#define SER_ARRAY_1(a_,n_) \
348 for(uint32_t i_=0; i_<(n_); i_++) \
349 message & (a_)[i_]; \
350
351#define SER_ARRAY_2(a_,n_,m_) \
352 for(uint32_t i_=0; i_<(n_); i_++) \
353 for(uint32_t j_=0; j_<(m_); j_++) \
354 message & (a_)[(i_)][(j_)]; \
355
356#define CPY_ARRAY_1(d_,s_,n_) \
357 for(uint32_t i_=0; i_<(n_); i_++) \
358 (d_)[i_] = (s_)[i_]; \
359
360#define CPY_ARRAY_2(d_,s_,n_,m_) \
361 for(uint32_t i_=0; i_<(n_); i_++) \
362 for(uint32_t j_=0; j_<(m_); j_++) \
363 (d_)[i_][j_] = (s_)[i_][j_]; \
364
365}}}} // namespaces
366
367#endif
#define CRL_CONSTEXPR
static CRL_CONSTEXPR IdType ID_CMD_GET_VERSION
Definition Protocol.hh:157
static CRL_CONSTEXPR uint16_t HEADER_MAGIC
Definition Protocol.hh:76
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_RIGHT
Definition Protocol.hh:258
static CRL_CONSTEXPR IdType ID_DATA_SECONDARY_APP
Definition Protocol.hh:242
static CRL_CONSTEXPR SourceType SOURCE_RGB_LEFT
Definition Protocol.hh:267
static CRL_CONSTEXPR IdType ID_ACK
Definition Protocol.hh:152
static CRL_CONSTEXPR IdType ID_DATA_IMU_CONFIG
Definition Protocol.hh:223
static CRL_CONSTEXPR IdType ID_CMD_LIDAR_SET_MOTOR
Definition Protocol.hh:165
static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_CONFIG
Definition Protocol.hh:180
static CRL_CONSTEXPR IdType ID_DATA_SYS_DIRECTED_STREAMS
Definition Protocol.hh:226
static CRL_CONSTEXPR IdType ID_DATA_COMPRESSED_IMAGE
Definition Protocol.hh:233
static CRL_CONSTEXPR SourceType SOURCE_GROUND_SURFACE_SPLINE_DATA
Definition Protocol.hh:268
static CRL_CONSTEXPR IdType ID_DATA_SYS_CAMERA_CAL
Definition Protocol.hh:214
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY
Definition Protocol.hh:262
static CRL_CONSTEXPR SourceType Default_Exposure_Source
Definition Protocol.hh:332
static CRL_CONSTEXPR IdType ID_DATA_APRILTAG_DETECTIONS_MESSAGE
Definition Protocol.hh:235
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_PTP
Definition Protocol.hh:189
static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_AUX
Definition Protocol.hh:282
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA_1
Definition Protocol.hh:287
static CRL_CONSTEXPR IdType ID_DATA_SYS_EXTERNAL_CAL
Definition Protocol.hh:228
static CRL_CONSTEXPR IdType ID_DATA_SYS_LIDAR_CAL
Definition Protocol.hh:215
static CRL_CONSTEXPR SourceType SOURCE_RAW_AUX
Definition Protocol.hh:275
static CRL_CONSTEXPR IdType ID_DATA_IMAGE
Definition Protocol.hh:217
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DIRECTED_STREAMS
Definition Protocol.hh:182
static CRL_CONSTEXPR uint16_t HEADER_GROUP
Definition Protocol.hh:82
static CRL_CONSTEXPR IdType ID_DATA_EXPOSURE_CONFIG
Definition Protocol.hh:231
static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_HISTORY
Definition Protocol.hh:161
static CRL_CONSTEXPR IdType ID_DATA_IMU_INFO
Definition Protocol.hh:222
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_TRANSMIT_DELAY
Definition Protocol.hh:187
static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_RECTIFIED_AUX
Definition Protocol.hh:285
static CRL_CONSTEXPR IdType ID_CMD_STREAM_CONTROL
Definition Protocol.hh:176
static CRL_CONSTEXPR SourceType SOURCE_SLB_MOTOR
Definition Protocol.hh:271
static CRL_CONSTEXPR IdType ID_DATA_CAM_HISTORY
Definition Protocol.hh:208
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DEVICE_INFO
Definition Protocol.hh:171
static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_TRIGGER_SOURCE
Definition Protocol.hh:178
static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_RIGHT
Definition Protocol.hh:281
static CRL_CONSTEXPR SourceType SOURCE_APRILTAG_DETECTIONS
Definition Protocol.hh:270
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_LIDAR_CAL
Definition Protocol.hh:173
static CRL_CONSTEXPR SourceType SOURCE_RAW_RIGHT
Definition Protocol.hh:254
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_CAMERA_CAL
Definition Protocol.hh:172
static CRL_CONSTEXPR uint32_t MAX_LIGHTS
Definition Protocol.hh:337
static CRL_CONSTEXPR float Default_Gain
Definition Protocol.hh:335
static CRL_CONSTEXPR uint8_t COMBINED_HEADER_LENGTH
Definition Protocol.hh:71
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RECT_AUX
Definition Protocol.hh:261
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_EXTERNAL_CAL
Definition Protocol.hh:184
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA_4
Definition Protocol.hh:290
static CRL_CONSTEXPR IdType ID_DATA_SYS_GROUND_SURFACE_PARAM
Definition Protocol.hh:234
static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_RECTIFIED_LEFT
Definition Protocol.hh:283
static CRL_CONSTEXPR IdType ID_DATA_CAM_AUX_CONFIG
Definition Protocol.hh:237
static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_RESOLUTION
Definition Protocol.hh:163
static CRL_CONSTEXPR uint16_t HEADER_VERSION
Definition Protocol.hh:77
static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_MODES
Definition Protocol.hh:219
static CRL_CONSTEXPR IdType ID_DATA_IMAGE_META
Definition Protocol.hh:216
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_RIGHT
Definition Protocol.hh:264
static CRL_CONSTEXPR IdType ID_DATA_PTP_STATUS
Definition Protocol.hh:239
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA_0
Definition Protocol.hh:286
static CRL_CONSTEXPR IdType ID_CMD_SECONDARY_APP_GET_CONFIG
Definition Protocol.hh:197
static CRL_CONSTEXPR IdType ID_DATA_DISPARITY
Definition Protocol.hh:218
struct __attribute__((__packed__))
Definition Protocol.hh:91
static CRL_CONSTEXPR SourceType SOURCE_GROUND_SURFACE_CLASS_IMAGE
Definition Protocol.hh:269
static CRL_CONSTEXPR IdType ID_CMD_SECONDARY_APP_ACTIVATE
Definition Protocol.hh:200
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RIGHT
Definition Protocol.hh:260
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_PACKET_DELAY
Definition Protocol.hh:196
static CRL_CONSTEXPR IdType ID_CMD_CAM_AUX_CONTROL
Definition Protocol.hh:190
static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_INFO
Definition Protocol.hh:213
static CRL_CONSTEXPR IdType ID_DATA_LIDAR_CONFIG
Definition Protocol.hh:209
static CRL_CONSTEXPR IdType ID_DATA_VERSION
Definition Protocol.hh:205
static CRL_CONSTEXPR SourceType SOURCE_JPEG_LEFT
Definition Protocol.hh:266
static CRL_CONSTEXPR IdType ID_DATA_SYS_APRILTAG_PARAM
Definition Protocol.hh:236
static CRL_CONSTEXPR IdType ID_CMD_SYS_FLASH_OP
Definition Protocol.hh:169
static CRL_CONSTEXPR IdType ID_DATA_SYS_MOTOR_POLL
Definition Protocol.hh:230
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_SENSOR_CAL
Definition Protocol.hh:183
static CRL_CONSTEXPR IdType ID_CMD_SYS_MTU
Definition Protocol.hh:168
static CRL_CONSTEXPR IdType ID_DATA_SECONDARY_APP_META
Definition Protocol.hh:241
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_TRANSMIT_DELAY
Definition Protocol.hh:186
static CRL_CONSTEXPR IdType ID_CMD_LED_SET
Definition Protocol.hh:167
static CRL_CONSTEXPR IdType ID_CMD_LED_GET_STATUS
Definition Protocol.hh:166
static CRL_CONSTEXPR IdType ID_DATA_IMU
Definition Protocol.hh:221
static CRL_CONSTEXPR IdType ID_DATA_SYS_SENSOR_CAL
Definition Protocol.hh:227
static CRL_CONSTEXPR IdType ID_DATA_SYS_TEST_MTU_RESPONSE
Definition Protocol.hh:224
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_PACKET_DELAY
Definition Protocol.hh:195
static CRL_CONSTEXPR IdType ID_DATA_GROUND_SURFACE_SPLINE_DATA_MESSAGE
Definition Protocol.hh:232
static CRL_CONSTEXPR IdType ID_CMD_SECONDARY_APP_GET_REGISTERED_APPS
Definition Protocol.hh:199
static CRL_CONSTEXPR IdType ID_DATA_SECONDARY_APP_REGISTERED_APPS
Definition Protocol.hh:244
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA_3
Definition Protocol.hh:289
static CRL_CONSTEXPR SourceType SOURCE_LUMA_LEFT
Definition Protocol.hh:255
static CRL_CONSTEXPR IdType ID_CMD_REMOTE_HEAD_CONFIG
Definition Protocol.hh:238
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_AUX
Definition Protocol.hh:278
static CRL_CONSTEXPR IdType ID_CMD_LIDAR_GET_CONFIG
Definition Protocol.hh:164
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_COST
Definition Protocol.hh:265
static CRL_CONSTEXPR IdType ID_DATA_SECONDARY_APP_CONFIG
Definition Protocol.hh:243
static CRL_CONSTEXPR IdType ID_DATA_LED_SENSOR_STATUS
Definition Protocol.hh:229
static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_INFO
Definition Protocol.hh:179
static CRL_CONSTEXPR IdType ID_CMD_GET_STATUS
Definition Protocol.hh:158
static CRL_CONSTEXPR IdType ID_DATA_SYS_FLASH_RESPONSE
Definition Protocol.hh:212
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA
Definition Protocol.hh:293
static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_LEFT
Definition Protocol.hh:280
static CRL_CONSTEXPR IdType ID_DATA_CAM_CONFIG
Definition Protocol.hh:207
static CRL_CONSTEXPR SourceType SOURCE_IMU
Definition Protocol.hh:273
static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_NETWORK
Definition Protocol.hh:170
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_AUX
Definition Protocol.hh:277
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA_2
Definition Protocol.hh:288
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_MTU
Definition Protocol.hh:174
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_NETWORK
Definition Protocol.hh:175
static CRL_CONSTEXPR IdType ID_DATA_LIDAR_SCAN
Definition Protocol.hh:210
static CRL_CONSTEXPR SourceType SOURCE_PPS
Definition Protocol.hh:274
static CRL_CONSTEXPR SourceType SOURCE_SECONDARY_APP_DATA_5
Definition Protocol.hh:291
static CRL_CONSTEXPR SourceType SOURCE_RAW_LEFT
Definition Protocol.hh:253
static CRL_CONSTEXPR IdType ID_DATA_SYS_PACKET_DELAY
Definition Protocol.hh:240
static CRL_CONSTEXPR IdType ID_CMD_REMOTE_HEAD_GET_CONFIG
Definition Protocol.hh:192
static CRL_CONSTEXPR IdType ID_DATA_LED_STATUS
Definition Protocol.hh:211
static CRL_CONSTEXPR IdType ID_DATA_SYS_PPS
Definition Protocol.hh:220
static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_AUX_CONFIG
Definition Protocol.hh:191
static CRL_CONSTEXPR IdType ID_CMD_SECONDARY_APP_CONTROL
Definition Protocol.hh:198
static CRL_CONSTEXPR IdType ID_DATA_STATUS
Definition Protocol.hh:206
static CRL_CONSTEXPR IdType ID_CMD_REMOTE_HEAD_CONTROL
Definition Protocol.hh:193
static CRL_CONSTEXPR SourceType SOURCE_CHROMA_LEFT
Definition Protocol.hh:259
static CRL_CONSTEXPR float Default_Target_Intensity
Definition Protocol.hh:333
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_LEFT
Definition Protocol.hh:257
static CRL_CONSTEXPR IdType ID_CMD_SYS_MOTOR_POLL
Definition Protocol.hh:188
static CRL_CONSTEXPR SourceType SOURCE_LUMA_RIGHT
Definition Protocol.hh:256
static CRL_CONSTEXPR SourceType SOURCE_IMAGES
Definition Protocol.hh:300
static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_CONFIG
Definition Protocol.hh:159
static CRL_CONSTEXPR SourceType SOURCE_LIDAR_SCAN
Definition Protocol.hh:272
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_AUX
Definition Protocol.hh:279
static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_LEFT
Definition Protocol.hh:263
static CRL_CONSTEXPR SourceType SOURCE_LUMA_AUX
Definition Protocol.hh:276
static CRL_CONSTEXPR IdType ID_CMD_CAM_CONTROL
Definition Protocol.hh:160
static CRL_CONSTEXPR SourceType SOURCE_COMPRESSED_RECTIFIED_RIGHT
Definition Protocol.hh:284
static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DEVICE_MODES
Definition Protocol.hh:177
static CRL_CONSTEXPR IdType ID_DATA_JPEG_IMAGE
Definition Protocol.hh:225
static CRL_CONSTEXPR IdType ID_CMD_LED_GET_SENSOR_STATUS
Definition Protocol.hh:185
static CRL_CONSTEXPR float WIRE_IMAGER_GAIN_MAX
Definition Protocol.hh:339
static CRL_CONSTEXPR IdType ID_CMD_GET_PTP_STATUS
Definition Protocol.hh:194
static CRL_CONSTEXPR float Default_Gamma
Definition Protocol.hh:334
static CRL_CONSTEXPR IdType ID_CMD_SYS_TEST_MTU
Definition Protocol.hh:181
static CRL_CONSTEXPR SourceType SOURCE_UNKNOWN
Definition Protocol.hh:252
static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_HDR
Definition Protocol.hh:162