Protocol.h
Go to the documentation of this file.
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 
00174 //
00175 // Data 
00176 
00177 static CRL_CONSTEXPR IdType ID_DATA_VERSION               = 0x0102;
00178 static CRL_CONSTEXPR IdType ID_DATA_STATUS                = 0x0103;
00179 static CRL_CONSTEXPR IdType ID_DATA_CAM_CONFIG            = 0x0104;
00180 static CRL_CONSTEXPR IdType ID_DATA_CAM_HISTORY           = 0x0105;
00181 static CRL_CONSTEXPR IdType ID_DATA_LIDAR_CONFIG          = 0x0108;
00182 static CRL_CONSTEXPR IdType ID_DATA_LIDAR_SCAN            = 0x0109;
00183 static CRL_CONSTEXPR IdType ID_DATA_LED_STATUS            = 0x010a;
00184 static CRL_CONSTEXPR IdType ID_DATA_SYS_FLASH_RESPONSE    = 0x010b;
00185 static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_INFO       = 0x010c;
00186 static CRL_CONSTEXPR IdType ID_DATA_SYS_CAMERA_CAL        = 0x010d;
00187 static CRL_CONSTEXPR IdType ID_DATA_SYS_LIDAR_CAL         = 0x010e;
00188 static CRL_CONSTEXPR IdType ID_DATA_IMAGE_META            = 0x010f;
00189 static CRL_CONSTEXPR IdType ID_DATA_IMAGE                 = 0x0110;
00190 static CRL_CONSTEXPR IdType ID_DATA_DISPARITY             = 0x0111;
00191 static CRL_CONSTEXPR IdType ID_DATA_SYS_DEVICE_MODES      = 0x0112;
00192 static CRL_CONSTEXPR IdType ID_DATA_SYS_PPS               = 0x0113;
00193 static CRL_CONSTEXPR IdType ID_DATA_IMU                   = 0x0114;
00194 static CRL_CONSTEXPR IdType ID_DATA_IMU_INFO              = 0x0115;
00195 static CRL_CONSTEXPR IdType ID_DATA_IMU_CONFIG            = 0x0116;
00196 static CRL_CONSTEXPR IdType ID_DATA_SYS_TEST_MTU_RESPONSE = 0x0117;
00197 static CRL_CONSTEXPR IdType ID_DATA_JPEG_IMAGE            = 0x0118;
00198 static CRL_CONSTEXPR IdType ID_DATA_SYS_DIRECTED_STREAMS  = 0x0119;
00199 
00200 //
00201 // Data sources
00202 
00203 typedef uint32_t SourceType;
00204 
00205 static CRL_CONSTEXPR SourceType SOURCE_UNKNOWN           = 0;
00206 static CRL_CONSTEXPR SourceType SOURCE_RAW_LEFT          = (1<<0);
00207 static CRL_CONSTEXPR SourceType SOURCE_RAW_RIGHT         = (1<<1);
00208 static CRL_CONSTEXPR SourceType SOURCE_LUMA_LEFT         = (1<<2);
00209 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RIGHT        = (1<<3);
00210 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_LEFT    = (1<<4);
00211 static CRL_CONSTEXPR SourceType SOURCE_LUMA_RECT_RIGHT   = (1<<5);
00212 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_LEFT       = (1<<6);
00213 static CRL_CONSTEXPR SourceType SOURCE_CHROMA_RIGHT      = (1<<7);
00214 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY         = (1<<10);
00215 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_LEFT    = (1<<10); // same as SOURCE_DISPARITY
00216 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_RIGHT   = (1<<11);
00217 static CRL_CONSTEXPR SourceType SOURCE_DISPARITY_COST    = (1<<12);
00218 static CRL_CONSTEXPR SourceType SOURCE_JPEG_LEFT         = (1<<16);
00219 static CRL_CONSTEXPR SourceType SOURCE_RGB_LEFT          = (1<<17);
00220 static CRL_CONSTEXPR SourceType SOURCE_LIDAR_SCAN        = (1<<24);
00221 static CRL_CONSTEXPR SourceType SOURCE_IMU               = (1<<25);
00222 static CRL_CONSTEXPR SourceType SOURCE_IMAGES            = (SOURCE_RAW_LEFT        |
00223                                                             SOURCE_RAW_RIGHT       |
00224                                                             SOURCE_LUMA_LEFT       |
00225                                                             SOURCE_LUMA_RIGHT      |
00226                                                             SOURCE_LUMA_RECT_LEFT  |
00227                                                             SOURCE_LUMA_RECT_RIGHT |
00228                                                             SOURCE_CHROMA_LEFT     |
00229                                                             SOURCE_CHROMA_RIGHT    |
00230                                                             SOURCE_DISPARITY_LEFT  |
00231                                                             SOURCE_DISPARITY_RIGHT |
00232                                                             SOURCE_DISPARITY_COST  |
00233                                                             SOURCE_JPEG_LEFT       |
00234                                                             SOURCE_RGB_LEFT);
00235 
00236 //
00237 // Some helper macros
00238 
00239 #define MSG_ID(x)  ((wire::IdType)(x))
00240 #define MSG_VER(x) ((wire::VersionType)(x))
00241 
00242 #define SER_ARRAY_1(a_,n_)                    \
00243     for(uint32_t i_=0; i_<(n_); i_++)         \
00244         message & (a_)[i_];                   \
00245     
00246 #define SER_ARRAY_2(a_,n_,m_)                 \
00247     for(uint32_t i_=0; i_<(n_); i_++)         \
00248         for(uint32_t j_=0; j_<(m_); j_++)     \
00249             message & (a_)[(i_)][(j_)];       \
00250 
00251 #define CPY_ARRAY_1(d_,s_,n_)                   \
00252     for(uint32_t i_=0; i_<(n_); i_++)           \
00253         (d_)[i_] = (s_)[i_];                    \
00254 
00255 #define CPY_ARRAY_2(d_,s_,n_,m_)                \
00256     for(uint32_t i_=0; i_<(n_); i_++)           \
00257         for(uint32_t j_=0; j_<(m_); j_++)       \
00258             (d_)[i_][j_] = (s_)[i_][j_];        \
00259 
00260 }}}}; // namespaces
00261 
00262 #endif


multisense_lib
Author(s):
autogenerated on Thu Aug 27 2015 14:01:11