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


multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46