00001 00037 #ifndef LibMultiSense_details_wire_protocol 00038 #define LibMultiSense_details_wire_protocol 00039 00040 #include <stdint.h> 00041 00042 #include "../utility/Portability.hh" 00043 00044 namespace crl { 00045 namespace multisense { 00046 namespace details { 00047 namespace wire { 00048 00049 // 00050 // Some message headers are directly used by sensor firmware 00051 00052 #ifdef SENSORPOD_FIRMWARE 00053 #define WIRE_HEADER_ATTRIBS_ __attribute__ ((__packed__)) 00054 #else 00055 #define WIRE_HEADER_ATTRIBS_ 00056 #endif // SENSORPOD_FIRMWARE 00057 00058 // 00059 // The size of the combined headers 00060 00061 static CRL_CONSTEXPR uint8_t COMBINED_HEADER_LENGTH = 60; 00062 00063 // 00064 // The magic number and version 00065 00066 static CRL_CONSTEXPR uint16_t HEADER_MAGIC = 0xadad; 00067 static CRL_CONSTEXPR uint16_t HEADER_VERSION = 0x0100; 00068 00069 // 00070 // The protocol group (TODO: define CRL-wide) 00071 00072 static CRL_CONSTEXPR uint16_t HEADER_GROUP = 0x0001; 00073 00074 // 00075 // The packet header structure 00076 00077 #if defined (_MSC_VER) 00078 #pragma pack(push, 1) 00079 typedef struct { 00080 #else 00081 typedef struct __attribute__ ((__packed__)) { 00082 #endif 00083 // 00084 // The magic number 00085 00086 uint16_t magic; 00087 00088 // 00089 // The protocol version 00090 00091 uint16_t version; 00092 00093 // 00094 // The protocol group 00095 00096 uint16_t group; 00097 00098 // 00099 // Protocol flags 00100 00101 uint16_t flags; 00102 00103 // 00104 // The message sequence identifier 00105 00106 uint16_t sequenceIdentifier; 00107 00108 // 00109 // The total size of the message 00110 00111 uint32_t messageLength; 00112 00113 // 00114 // Offset of this packet's payload 00115 00116 uint32_t byteOffset; 00117 00118 } Header; 00119 #if defined (_MSC_VER) 00120 #pragma pack(pop) 00121 #endif 00122 00123 // 00124 // Types for message IDs and versions 00125 00126 typedef uint16_t IdType; 00127 typedef uint16_t VersionType; 00128 00129 // 00130 // Every command responsds with an ID_ACK message, 00131 // regardless if a data message is also following. 00132 00133 // 00134 // TODO: this message set is still awkward in places: 00135 // - Missing 1:1 get/set 00136 // - Some "Data" messages are also commands 00137 // - Duplicated information (CAM_GET_CONFIG, SYS_GET_CAMERA_CAL, etc.) 00138 00139 // 00140 // [N]acks 00141 00142 static CRL_CONSTEXPR IdType ID_ACK = 0x0001; 00143 00144 // 00145 // Commands 00146 00147 static CRL_CONSTEXPR IdType ID_CMD_GET_VERSION = 0x0002; 00148 static CRL_CONSTEXPR IdType ID_CMD_GET_STATUS = 0x0003; 00149 static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_CONFIG = 0x0004; 00150 static CRL_CONSTEXPR IdType ID_CMD_CAM_CONTROL = 0x0007; 00151 static CRL_CONSTEXPR IdType ID_CMD_CAM_GET_HISTORY = 0x0008; 00152 static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_HDR = 0x000b; 00153 static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_RESOLUTION = 0x000c; 00154 static CRL_CONSTEXPR IdType ID_CMD_LIDAR_GET_CONFIG = 0x000d; 00155 static CRL_CONSTEXPR IdType ID_CMD_LIDAR_SET_MOTOR = 0x0010; 00156 static CRL_CONSTEXPR IdType ID_CMD_LED_GET_STATUS = 0x0012; 00157 static CRL_CONSTEXPR IdType ID_CMD_LED_SET = 0x0013; 00158 static CRL_CONSTEXPR IdType ID_CMD_SYS_MTU = 0x0014; 00159 static CRL_CONSTEXPR IdType ID_CMD_SYS_FLASH_OP = 0x0015; 00160 static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_NETWORK = 0x0016; 00161 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DEVICE_INFO = 0x0017; 00162 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_CAMERA_CAL = 0x0018; 00163 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_LIDAR_CAL = 0x0019; 00164 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_MTU = 0x001a; 00165 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_NETWORK = 0x001b; 00166 static CRL_CONSTEXPR IdType ID_CMD_STREAM_CONTROL = 0x001c; 00167 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DEVICE_MODES = 0x001d; 00168 static CRL_CONSTEXPR IdType ID_CMD_CAM_SET_TRIGGER_SOURCE = 0x001e; 00169 static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_INFO = 0x001f; 00170 static CRL_CONSTEXPR IdType ID_CMD_IMU_GET_CONFIG = 0x0020; 00171 static CRL_CONSTEXPR IdType ID_CMD_SYS_TEST_MTU = 0x0021; 00172 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_DIRECTED_STREAMS = 0x0022; 00173 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_SENSOR_CAL = 0x0023; 00174 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_EXTERNAL_CAL = 0x0024; 00175 static CRL_CONSTEXPR IdType ID_CMD_LED_GET_SENSOR_STATUS = 0x0025; 00176 static CRL_CONSTEXPR IdType ID_CMD_SYS_SET_TRANSMIT_DELAY = 0x0026; 00177 static CRL_CONSTEXPR IdType ID_CMD_SYS_GET_TRANSMIT_DELAY = 0x0027; 00178 00179 // 00180 // Data 00181 00182 static CRL_CONSTEXPR IdType ID_DATA_VERSION = 0x0102; 00183 static CRL_CONSTEXPR IdType ID_DATA_STATUS = 0x0103; 00184 static CRL_CONSTEXPR IdType ID_DATA_CAM_CONFIG = 0x0104; 00185 static CRL_CONSTEXPR IdType ID_DATA_CAM_HISTORY = 0x0105; 00186 static CRL_CONSTEXPR IdType ID_DATA_LIDAR_CONFIG = 0x0108; 00187 static CRL_CONSTEXPR IdType ID_DATA_LIDAR_SCAN = 0x0109; 00188 static CRL_CONSTEXPR IdType ID_DATA_LED_STATUS = 0x010a; 00189 static CRL_CONSTEXPR IdType ID_DATA_SYS_FLASH_RESPONSE = 0x010b; 00190 static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_INFO = 0x010c; 00191 static CRL_CONSTEXPR IdType ID_DATA_SYS_CAMERA_CAL = 0x010d; 00192 static CRL_CONSTEXPR IdType ID_DATA_SYS_LIDAR_CAL = 0x010e; 00193 static CRL_CONSTEXPR IdType ID_DATA_IMAGE_META = 0x010f; 00194 static CRL_CONSTEXPR IdType ID_DATA_IMAGE = 0x0110; 00195 static CRL_CONSTEXPR IdType ID_DATA_DISPARITY = 0x0111; 00196 static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_MODES = 0x0112; 00197 static CRL_CONSTEXPR IdType ID_DATA_SYS_PPS = 0x0113; 00198 static CRL_CONSTEXPR IdType ID_DATA_IMU = 0x0114; 00199 static CRL_CONSTEXPR IdType ID_DATA_IMU_INFO = 0x0115; 00200 static CRL_CONSTEXPR IdType ID_DATA_IMU_CONFIG = 0x0116; 00201 static CRL_CONSTEXPR IdType ID_DATA_SYS_TEST_MTU_RESPONSE = 0x0117; 00202 static CRL_CONSTEXPR IdType ID_DATA_JPEG_IMAGE = 0x0118; 00203 static CRL_CONSTEXPR IdType ID_DATA_SYS_DIRECTED_STREAMS = 0x0119; 00204 static CRL_CONSTEXPR IdType ID_DATA_SYS_SENSOR_CAL = 0x011a; 00205 static CRL_CONSTEXPR IdType ID_DATA_SYS_EXTERNAL_CAL = 0x011b; 00206 static CRL_CONSTEXPR IdType ID_DATA_LED_SENSOR_STATUS = 0x011c; 00207 00208 // 00209 // Data sources 00210 00211 typedef uint32_t SourceType; 00212 00213 static CRL_CONSTEXPR SourceType SOURCE_UNKNOWN = 0; 00214 static CRL_CONSTEXPR SourceType SOURCE_RAW_LEFT = (1<<0); 00215 static CRL_CONSTEXPR SourceType SOURCE_RAW_RIGHT = (1<<1); 00216 static CRL_CONSTEXPR SourceType SOURCE_LUMA_LEFT = (1<<2); 00217 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RIGHT = (1<<3); 00218 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_LEFT = (1<<4); 00219 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_RIGHT = (1<<5); 00220 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_LEFT = (1<<6); 00221 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RIGHT = (1<<7); 00222 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY = (1<<10); 00223 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_LEFT = (1<<10); // same as SOURCE_DISPARITY 00224 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_RIGHT = (1<<11); 00225 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_COST = (1<<12); 00226 static CRL_CONSTEXPR SourceType SOURCE_JPEG_LEFT = (1<<16); 00227 static CRL_CONSTEXPR SourceType SOURCE_RGB_LEFT = (1<<17); 00228 static CRL_CONSTEXPR SourceType SOURCE_LIDAR_SCAN = (1<<24); 00229 static CRL_CONSTEXPR SourceType SOURCE_IMU = (1<<25); 00230 static CRL_CONSTEXPR SourceType SOURCE_PPS = (1<<26); 00231 static CRL_CONSTEXPR SourceType SOURCE_IMAGES = (SOURCE_RAW_LEFT | 00232 SOURCE_RAW_RIGHT | 00233 SOURCE_LUMA_LEFT | 00234 SOURCE_LUMA_RIGHT | 00235 SOURCE_LUMA_RECT_LEFT | 00236 SOURCE_LUMA_RECT_RIGHT | 00237 SOURCE_CHROMA_LEFT | 00238 SOURCE_CHROMA_RIGHT | 00239 SOURCE_DISPARITY_LEFT | 00240 SOURCE_DISPARITY_RIGHT | 00241 SOURCE_DISPARITY_COST | 00242 SOURCE_JPEG_LEFT | 00243 SOURCE_RGB_LEFT); 00244 00245 // 00246 // Some helper macros 00247 00248 #define MSG_ID(x) ((wire::IdType)(x)) 00249 #define MSG_VER(x) ((wire::VersionType)(x)) 00250 00251 #define SER_ARRAY_1(a_,n_) \ 00252 for(uint32_t i_=0; i_<(n_); i_++) \ 00253 message & (a_)[i_]; \ 00254 00255 #define SER_ARRAY_2(a_,n_,m_) \ 00256 for(uint32_t i_=0; i_<(n_); i_++) \ 00257 for(uint32_t j_=0; j_<(m_); j_++) \ 00258 message & (a_)[(i_)][(j_)]; \ 00259 00260 #define CPY_ARRAY_1(d_,s_,n_) \ 00261 for(uint32_t i_=0; i_<(n_); i_++) \ 00262 (d_)[i_] = (s_)[i_]; \ 00263 00264 #define CPY_ARRAY_2(d_,s_,n_,m_) \ 00265 for(uint32_t i_=0; i_<(n_); i_++) \ 00266 for(uint32_t j_=0; j_<(m_); j_++) \ 00267 (d_)[i_][j_] = (s_)[i_][j_]; \ 00268 00269 }}}}; // namespaces 00270 00271 #endif