crtp.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #define CRTP_MAX_DATA_SIZE 30
00004 
00005 // Header
00006 struct crtp
00007 {
00008   constexpr crtp(uint8_t port, uint8_t channel)
00009     : channel(channel)
00010     , link(3)
00011     , port(port)
00012   {
00013   }
00014 
00015   crtp(uint8_t byte)
00016   {
00017     channel = (byte >> 0) & 0x3;
00018     link    = (byte >> 2) & 0x3;
00019     port    = (byte >> 4) & 0xF;
00020   }
00021 
00022   bool operator==(const crtp& other) const {
00023     return channel == other.channel && port == other.port;
00024   }
00025 
00026   uint8_t channel:2;
00027   uint8_t link:2;
00028   uint8_t port:4;
00029 } __attribute__((packed));
00030 
00031 // Packet structure definition
00032 typedef struct {
00033   uint8_t size;
00034   union {
00035     struct {
00036       uint8_t header;
00037       uint8_t data[CRTP_MAX_DATA_SIZE];
00038     };
00039     uint8_t raw[CRTP_MAX_DATA_SIZE+1];
00040   };
00041 } crtpPacket_t;
00042 
00043 // Port 0 (Console)
00044 struct crtpConsoleResponse
00045 {
00046     static bool match(const Crazyradio::Ack& response) {
00047       return crtp(response.data[0]) == crtp(0, 0);
00048     }
00049 
00050     crtp header;
00051     char text[31];
00052 };
00053 
00054 // Port 2 (Parameters)
00055 
00056 struct crtpParamTocGetItemResponse;
00057 struct crtpParamTocGetItemRequest
00058 {
00059   crtpParamTocGetItemRequest(
00060     uint8_t id)
00061     : header(2, 0)
00062     , command(0)
00063     , id(id)
00064   {
00065   }
00066 
00067   bool operator==(const crtpParamTocGetItemRequest& other) const {
00068     return header == other.header && command == other.command && id == other.id;
00069   }
00070 
00071   typedef crtpParamTocGetItemResponse Response;
00072 
00073   const crtp header;
00074   const uint8_t command;
00075   uint8_t id;
00076 } __attribute__((packed));
00077 
00078 struct crtpParamTocGetItemResponse
00079 {
00080   static bool match(const Crazyradio::Ack& response) {
00081     return response.size > 5 &&
00082            crtp(response.data[0]) == crtp(2, 0) &&
00083            response.data[1] == 0;
00084   }
00085 
00086   crtpParamTocGetItemRequest request;
00087   uint8_t length:2; // one of ParamLength
00088   uint8_t type:1;   // one of ParamType
00089   uint8_t sign:1;   // one of ParamSign
00090   uint8_t res0:2;   // reserved
00091   uint8_t readonly:1;
00092   uint8_t group:1;  // one of ParamGroup
00093   char text[28]; // group, name
00094 } __attribute__((packed));
00095 
00096 struct crtpParamTocGetInfoResponse;
00097 struct crtpParamTocGetInfoRequest
00098 {
00099   crtpParamTocGetInfoRequest()
00100     : header(2, 0)
00101     , command(1)
00102   {
00103   }
00104 
00105   bool operator==(const crtpParamTocGetInfoRequest& other) const {
00106     return header == other.header && command == other.command;
00107   }
00108 
00109   typedef crtpParamTocGetInfoResponse Response;
00110 
00111   const crtp header;
00112   const uint8_t command;
00113 } __attribute__((packed));
00114 
00115 struct crtpParamTocGetInfoResponse
00116 {
00117   static bool match(const Crazyradio::Ack& response) {
00118     return response.size == 7 &&
00119            crtp(response.data[0]) == crtp(2, 0) &&
00120            response.data[1] == 1;
00121   }
00122 
00123   crtpParamTocGetInfoRequest request;
00124   uint8_t numParam;
00125   uint32_t crc;
00126 } __attribute__((packed));
00127 
00128 struct crtpParamValueResponse;
00129 struct crtpParamReadRequest
00130 {
00131   crtpParamReadRequest(
00132     uint8_t id)
00133     : header(2, 1)
00134     , id(id)
00135   {
00136   }
00137 
00138   bool operator==(const crtpParamReadRequest& other) const {
00139     return header == other.header && id == other.id;
00140   }
00141 
00142   typedef crtpParamValueResponse Response;
00143 
00144   const crtp header;
00145   const uint8_t id;
00146 } __attribute__((packed));
00147 
00148 template <class T>
00149 struct crtpParamWriteRequest
00150 {
00151   crtpParamWriteRequest(
00152     uint8_t id,
00153     const T& value)
00154     : header(2, 2)
00155     , id(id)
00156     , value(value)
00157     {
00158     }
00159 
00160     const crtp header;
00161     const uint8_t id;
00162     const T value;
00163 } __attribute__((packed));
00164 
00165 struct crtpParamValueResponse
00166 {
00167   static bool match(const Crazyradio::Ack& response) {
00168     return response.size > 2 &&
00169            (crtp(response.data[0]) == crtp(2, 1) ||
00170             crtp(response.data[0]) == crtp(2, 2));
00171   }
00172 
00173   crtpParamReadRequest request;
00174   union {
00175     uint8_t valueUint8;
00176     int8_t valueInt8;
00177     uint16_t valueUint16;
00178     int16_t valueInt16;
00179     uint32_t valueUint32;
00180     int32_t valueInt32;
00181     float valueFloat;
00182   };
00183 } __attribute__((packed));
00184 
00185 // Port 3 (Commander)
00186 
00187 struct crtpSetpointRequest
00188 {
00189   crtpSetpointRequest(
00190     float roll,
00191     float pitch,
00192     float yawrate,
00193     uint16_t thrust)
00194     : header(0x03, 0)
00195     , roll(roll)
00196     , pitch(pitch)
00197     , yawrate(yawrate)
00198     , thrust(thrust)
00199   {
00200   }
00201   const crtp header;
00202   float roll;
00203   float pitch;
00204   float yawrate;
00205   uint16_t thrust;
00206 }  __attribute__((packed));
00207 
00208 // Port 4 (Memory access)
00209 
00210 // Port 5 (Data logging)
00211 
00212 struct crtpLogGetInfoResponse;
00213 struct crtpLogGetInfoRequest
00214 {
00215   crtpLogGetInfoRequest()
00216     : header(5, 0)
00217     , command(1)
00218     {
00219     }
00220 
00221   bool operator==(const crtpLogGetInfoRequest& other) const {
00222     return header == other.header && command == other.command;
00223   }
00224 
00225   typedef crtpLogGetInfoResponse Response;
00226 
00227   const crtp header;
00228   const uint8_t command;
00229 } __attribute__((packed));
00230 
00231 struct crtpLogGetInfoResponse
00232 {
00233   static bool match(const Crazyradio::Ack& response) {
00234     return response.size == 9 &&
00235            crtp(response.data[0]) == crtp(5, 0) &&
00236            response.data[1] == 1;
00237   }
00238 
00239   crtpLogGetInfoRequest request;
00240   // Number of log items contained in the log table of content
00241   uint8_t log_len;
00242   // CRC values of the log TOC memory content. This is a fingerprint of the copter build that can be used to cache the TOC
00243   uint32_t log_crc;
00244   // Maximum number of log packets that can be programmed in the copter
00245   uint8_t log_max_packet;
00246   // Maximum number of operation programmable in the copter. An operation is one log variable retrieval programming
00247   uint8_t log_max_ops;
00248 } __attribute__((packed));
00249 
00250 struct crtpLogGetItemResponse;
00251 struct crtpLogGetItemRequest
00252 {
00253   crtpLogGetItemRequest(uint8_t id)
00254     : header(5, 0)
00255     , command(0)
00256     , id(id)
00257   {
00258   }
00259 
00260   bool operator==(const crtpLogGetItemRequest& other) const {
00261     return header == other.header && command == other.command && id == other.id;
00262   }
00263 
00264   typedef crtpLogGetItemResponse Response;
00265 
00266   const crtp header;
00267   const uint8_t command;
00268   uint8_t id;
00269 } __attribute__((packed));
00270 
00271 struct crtpLogGetItemResponse
00272 {
00273     static bool match(const Crazyradio::Ack& response) {
00274       return response.size > 5 &&
00275              crtp(response.data[0]) == crtp(5, 0) &&
00276              response.data[1] == 0;
00277     }
00278 
00279     crtpLogGetItemRequest request;
00280     uint8_t type;
00281     char text[28]; // group, name
00282 } __attribute__((packed));
00283 
00284 struct logBlockItem {
00285   uint8_t logType;
00286   uint8_t id;
00287 } __attribute__((packed));
00288 
00289 struct crtpLogCreateBlockRequest
00290 {
00291   crtpLogCreateBlockRequest()
00292   : header(5, 1)
00293   , command(0)
00294   {
00295   }
00296 
00297   const crtp header;
00298   const uint8_t command;
00299   uint8_t id;
00300   logBlockItem items[16];
00301 } __attribute__((packed));
00302 
00303 // struct logAppendBlockRequest
00304 // {
00305 //   logAppendBlockRequest()
00306 //     : header(5, 1)
00307 //     , command(1)
00308 //     {
00309 //     }
00310 
00311 //     const crtp header;
00312 //     const uint8_t command;
00313 //     uint8_t id;
00314 //     logBlockItem items[16];
00315 // } __attribute__((packed));
00316 
00317 // struct logDeleteBlockRequest
00318 // {
00319 //   logDeleteBlockRequest()
00320 //     : header(5, 1)
00321 //     , command(2)
00322 //     {
00323 //     }
00324 
00325 //     const crtp header;
00326 //     const uint8_t command;
00327 //     uint8_t id;
00328 // } __attribute__((packed));
00329 
00330 struct crtpLogStartRequest
00331 {
00332   crtpLogStartRequest(
00333     uint8_t id,
00334     uint8_t period)
00335     : header(5, 1)
00336     , command(3)
00337     , id(id)
00338     , period(period)
00339     {
00340     }
00341 
00342     const crtp header;
00343     const uint8_t command;
00344     uint8_t id;
00345     uint8_t period; // in increments of 10ms
00346 } __attribute__((packed));
00347 
00348 struct crtpLogStopRequest
00349 {
00350   crtpLogStopRequest(
00351     uint8_t id)
00352     : header(5, 1)
00353     , command(4)
00354     , id(id)
00355     {
00356     }
00357 
00358     const crtp header;
00359     const uint8_t command;
00360     uint8_t id;
00361 } __attribute__((packed));
00362 
00363 struct crtpLogResetRequest
00364 {
00365   crtpLogResetRequest()
00366     : header(5, 1)
00367     , command(5)
00368     {
00369     }
00370 
00371     const crtp header;
00372     const uint8_t command;
00373 } __attribute__((packed));
00374 
00375 enum crtpLogControlResult {
00376   crtpLogControlResultOk            = 0,
00377   crtpLogControlResultOutOfMemory   = 12, // ENOMEM
00378   crtpLogControlResultCmdNotFound   = 8,  // ENOEXEC
00379   crtpLogControlResultWrongBlockId  = 2,  // ENOENT
00380   crtpLogControlResultBlockTooLarge = 7,  // E2BIG
00381   crtpLogControlResultBlockExists   = 17, // EEXIST
00382 
00383 };
00384 
00385 struct crtpLogControlResponse
00386 {
00387     static bool match(const Crazyradio::Ack& response) {
00388       return response.size == 4 &&
00389              crtp(response.data[0]) == crtp(5, 1);
00390     }
00391 
00392     crtp header;
00393     uint8_t command;
00394     uint8_t requestByte1;
00395     uint8_t result; // one of crtpLogControlResult
00396 } __attribute__((packed));
00397 
00398 struct crtpLogDataResponse
00399 {
00400     static bool match(const Crazyradio::Ack& response) {
00401       return response.size > 4 &&
00402              crtp(response.data[0]) == crtp(5, 2);
00403     }
00404 
00405     crtp header;
00406     uint8_t blockId;
00407     uint8_t timestampLo;
00408     uint16_t timestampHi;
00409     uint8_t data[26];
00410 } __attribute__((packed));
00411 
00412 
00413 // Port 0x06 (External Position Update)
00414 
00415 struct crtpExternalPositionUpdate
00416 {
00417   crtpExternalPositionUpdate(
00418     float x,
00419     float y,
00420     float z)
00421     : header(0x06, 0)
00422     , x(x)
00423     , y(y)
00424     , z(z)
00425   {
00426   }
00427   const crtp header;
00428   float x;
00429   float y;
00430   float z;
00431 }  __attribute__((packed));
00432 
00433 
00434 
00435 // Port 13 (Platform)
00436 
00437 // The crazyflie-nrf firmware sends empty packets with the signal strength, if nothing else is in the queue
00438 struct crtpPlatformRSSIAck
00439 {
00440     static bool match(const Crazyradio::Ack& response) {
00441       return crtp(response.data[0]) == crtp(15, 3);
00442     }
00443 
00444     crtp header;
00445     uint8_t reserved;
00446     uint8_t rssi;
00447 };


crazyflie_cpp
Author(s): Wolfgang Hoenig
autogenerated on Sun Oct 8 2017 02:47:59