crtp.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "Crazyradio.h"
00004 #include <cstdint>
00005 
00006 static int const CRTP_MAX_DATA_SIZE = 30;
00007 static int const CRTP_MAXSIZE = 31;
00008 #define CHECKSIZE(s) static_assert(sizeof(s) <= CRTP_MAXSIZE, #s " packet is too large");
00009 
00010 static int const CRTP_MAXSIZE_RESPONSE = 32;
00011 #define CHECKSIZE_RESPONSE(s) static_assert(sizeof(s) <= CRTP_MAXSIZE_RESPONSE, #s " packet is too large");
00012 
00013 void quatdecompress(uint32_t comp, float q[4]);
00014 
00015 // Header
00016 struct crtp
00017 {
00018   constexpr crtp(uint8_t port, uint8_t channel)
00019     : channel(channel)
00020     , link(3)
00021     , port(port)
00022   {
00023   }
00024 
00025   crtp(uint8_t byte)
00026   {
00027     channel = (byte >> 0) & 0x3;
00028     link    = (byte >> 2) & 0x3;
00029     port    = (byte >> 4) & 0xF;
00030   }
00031 
00032   bool operator==(const crtp& other) const {
00033     return channel == other.channel && port == other.port;
00034   }
00035 
00036   uint8_t channel:2;
00037   uint8_t link:2;
00038   uint8_t port:4;
00039 } __attribute__((packed));
00040 
00041 // Packet structure definition
00042 typedef struct {
00043   uint8_t size;
00044   union {
00045     struct {
00046       uint8_t header;
00047       uint8_t data[CRTP_MAX_DATA_SIZE];
00048     };
00049     uint8_t raw[CRTP_MAX_DATA_SIZE+1];
00050   };
00051 } crtpPacket_t;
00052 
00053 struct crtpEmpty
00054 {
00055   const uint8_t cmd = 0xFF;
00056 };
00057 
00058 // Port 0 (Console)
00059 struct crtpConsoleResponse
00060 {
00061     static bool match(const Crazyradio::Ack& response) {
00062       return crtp(response.data[0]) == crtp(0, 0);
00063     }
00064 
00065     crtp header;
00066     char text[31];
00067 };
00068 CHECKSIZE_RESPONSE(crtpConsoleResponse)
00069 
00070 // Port 2 (Parameters)
00071 
00072 struct crtpParamTocGetItemResponse;
00073 struct crtpParamTocGetItemRequest
00074 {
00075   crtpParamTocGetItemRequest(
00076     uint8_t id)
00077     : header(2, 0)
00078     , command(0)
00079     , id(id)
00080   {
00081   }
00082 
00083   bool operator==(const crtpParamTocGetItemRequest& other) const {
00084     return header == other.header && command == other.command && id == other.id;
00085   }
00086 
00087   typedef crtpParamTocGetItemResponse Response;
00088 
00089   const crtp header;
00090   const uint8_t command;
00091   uint8_t id;
00092 } __attribute__((packed));
00093 CHECKSIZE(crtpParamTocGetItemRequest)
00094 
00095 struct crtpParamTocGetItemResponse
00096 {
00097   static bool match(const Crazyradio::Ack& response) {
00098     return response.size > 5 &&
00099            crtp(response.data[0]) == crtp(2, 0) &&
00100            response.data[1] == 0;
00101   }
00102 
00103   crtpParamTocGetItemRequest request;
00104   uint8_t length:2; // one of ParamLength
00105   uint8_t type:1;   // one of ParamType
00106   uint8_t sign:1;   // one of ParamSign
00107   uint8_t res0:2;   // reserved
00108   uint8_t readonly:1;
00109   uint8_t group:1;  // one of ParamGroup
00110   char text[28]; // group, name
00111 } __attribute__((packed));
00112 CHECKSIZE_RESPONSE(crtpParamTocGetItemResponse)
00113 
00114 struct crtpParamTocGetInfoResponse;
00115 struct crtpParamTocGetInfoRequest
00116 {
00117   crtpParamTocGetInfoRequest()
00118     : header(2, 0)
00119     , command(1)
00120   {
00121   }
00122 
00123   bool operator==(const crtpParamTocGetInfoRequest& other) const {
00124     return header == other.header && command == other.command;
00125   }
00126 
00127   typedef crtpParamTocGetInfoResponse Response;
00128 
00129   const crtp header;
00130   const uint8_t command;
00131 } __attribute__((packed));
00132 CHECKSIZE(crtpParamTocGetInfoRequest)
00133 
00134 struct crtpParamTocGetInfoResponse
00135 {
00136   static bool match(const Crazyradio::Ack& response) {
00137     return response.size == 7 &&
00138            crtp(response.data[0]) == crtp(2, 0) &&
00139            response.data[1] == 1;
00140   }
00141 
00142   crtpParamTocGetInfoRequest request;
00143   uint8_t numParam;
00144   uint32_t crc;
00145 } __attribute__((packed));
00146 CHECKSIZE_RESPONSE(crtpParamTocGetInfoResponse)
00147 
00148 struct crtpParamValueResponse;
00149 struct crtpParamReadRequest
00150 {
00151   crtpParamReadRequest(
00152     uint8_t id)
00153     : header(2, 1)
00154     , id(id)
00155   {
00156   }
00157 
00158   bool operator==(const crtpParamReadRequest& other) const {
00159     return header == other.header && id == other.id;
00160   }
00161 
00162   typedef crtpParamValueResponse Response;
00163 
00164   const crtp header;
00165   const uint8_t id;
00166 } __attribute__((packed));
00167 CHECKSIZE(crtpParamReadRequest)
00168 
00169 template <class T>
00170 struct crtpParamWriteRequest
00171 {
00172   crtpParamWriteRequest(
00173     uint8_t id,
00174     const T& value)
00175     : header(2, 2)
00176     , id(id)
00177     , value(value)
00178     {
00179     }
00180 
00181     const crtp header;
00182     const uint8_t id;
00183     const T value;
00184 } __attribute__((packed));
00185 CHECKSIZE(crtpParamWriteRequest<double>) // largest kind of param
00186 
00187 struct crtpParamValueResponse
00188 {
00189   static bool match(const Crazyradio::Ack& response) {
00190     return response.size > 2 &&
00191            (crtp(response.data[0]) == crtp(2, 1) ||
00192             crtp(response.data[0]) == crtp(2, 2));
00193   }
00194 
00195   crtpParamReadRequest request;
00196   union {
00197     uint8_t valueUint8;
00198     int8_t valueInt8;
00199     uint16_t valueUint16;
00200     int16_t valueInt16;
00201     uint32_t valueUint32;
00202     int32_t valueInt32;
00203     float valueFloat;
00204   };
00205 } __attribute__((packed));
00206 CHECKSIZE_RESPONSE(crtpParamValueResponse)
00207 
00208 // V2
00209 struct crtpParamTocGetItemV2Response;
00210 struct crtpParamTocGetItemV2Request
00211 {
00212   crtpParamTocGetItemV2Request(
00213     uint16_t id)
00214     : header(2, 0)
00215     , command(2)
00216     , id(id)
00217   {
00218   }
00219 
00220   bool operator==(const crtpParamTocGetItemV2Request& other) const {
00221     return header == other.header && command == other.command && id == other.id;
00222   }
00223 
00224   typedef crtpParamTocGetItemResponse Response;
00225 
00226   const crtp header;
00227   const uint8_t command;
00228   uint16_t id;
00229 } __attribute__((packed));
00230 CHECKSIZE(crtpParamTocGetItemV2Request)
00231 
00232 struct crtpParamTocGetItemV2Response
00233 {
00234   static bool match(const Crazyradio::Ack& response) {
00235     return response.size > 5 &&
00236            crtp(response.data[0]) == crtp(2, 0) &&
00237            response.data[1] == 2;
00238   }
00239 
00240   crtpParamTocGetItemV2Request request;
00241   uint8_t length:2; // one of ParamLength
00242   uint8_t type:1;   // one of ParamType
00243   uint8_t sign:1;   // one of ParamSign
00244   uint8_t res0:2;   // reserved
00245   uint8_t readonly:1;
00246   uint8_t group:1;  // one of ParamGroup
00247   char text[27]; // group, name
00248 } __attribute__((packed));
00249 CHECKSIZE_RESPONSE(crtpParamTocGetItemV2Response)
00250 
00251 struct crtpParamTocGetInfoV2Response;
00252 struct crtpParamTocGetInfoV2Request
00253 {
00254   crtpParamTocGetInfoV2Request()
00255     : header(2, 0)
00256     , command(3)
00257   {
00258   }
00259 
00260   bool operator==(const crtpParamTocGetInfoV2Request& other) const {
00261     return header == other.header && command == other.command;
00262   }
00263 
00264   typedef crtpParamTocGetInfoV2Response Response;
00265 
00266   const crtp header;
00267   const uint8_t command;
00268 } __attribute__((packed));
00269 CHECKSIZE(crtpParamTocGetInfoV2Request)
00270 
00271 struct crtpParamTocGetInfoV2Response
00272 {
00273   static bool match(const Crazyradio::Ack& response) {
00274     return response.size == 8 &&
00275            crtp(response.data[0]) == crtp(2, 0) &&
00276            response.data[1] == 3;
00277   }
00278 
00279   crtpParamTocGetInfoV2Request request;
00280   uint16_t numParam;
00281   uint32_t crc;
00282 } __attribute__((packed));
00283 CHECKSIZE_RESPONSE(crtpParamTocGetInfoV2Response)
00284 
00285 struct crtpParamValueV2Response;
00286 struct crtpParamReadV2Request
00287 {
00288   crtpParamReadV2Request(
00289     uint16_t id)
00290     : header(2, 1)
00291     , id(id)
00292   {
00293   }
00294 
00295   bool operator==(const crtpParamReadV2Request& other) const {
00296     return header == other.header && id == other.id;
00297   }
00298 
00299   typedef crtpParamValueV2Response Response;
00300 
00301   const crtp header;
00302   const uint16_t id;
00303 } __attribute__((packed));
00304 CHECKSIZE(crtpParamReadV2Request)
00305 
00306 template <class T>
00307 struct crtpParamWriteV2Request
00308 {
00309   crtpParamWriteV2Request(
00310     uint16_t id,
00311     const T& value)
00312     : header(2, 2)
00313     , id(id)
00314     , value(value)
00315     {
00316     }
00317 
00318     const crtp header;
00319     const uint16_t id;
00320     const T value;
00321 } __attribute__((packed));
00322 CHECKSIZE(crtpParamWriteV2Request<float>) // largest kind of param
00323 
00324 struct crtpParamValueV2Response
00325 {
00326   static bool match(const Crazyradio::Ack& response) {
00327     return response.size > 2 &&
00328            (crtp(response.data[0]) == crtp(2, 1) ||
00329             crtp(response.data[0]) == crtp(2, 2));
00330   }
00331 
00332   crtpParamReadV2Request request;
00333   uint8_t status; // 0 = success
00334   union {
00335     uint8_t valueUint8;
00336     int8_t valueInt8;
00337     uint16_t valueUint16;
00338     int16_t valueInt16;
00339     uint32_t valueUint32;
00340     int32_t valueInt32;
00341     float valueFloat;
00342   };
00343 } __attribute__((packed));
00344 CHECKSIZE_RESPONSE(crtpParamValueV2Response)
00345 
00346 // Port 3 (Commander)
00347 
00348 struct crtpSetpointRequest
00349 {
00350   crtpSetpointRequest(
00351     float roll,
00352     float pitch,
00353     float yawrate,
00354     uint16_t thrust)
00355     : header(0x03, 0)
00356     , roll(roll)
00357     , pitch(pitch)
00358     , yawrate(yawrate)
00359     , thrust(thrust)
00360   {
00361   }
00362   const crtp header;
00363   float roll;
00364   float pitch;
00365   float yawrate;
00366   uint16_t thrust;
00367 }  __attribute__((packed));
00368 CHECKSIZE(crtpSetpointRequest)
00369 
00370 // Port 4 (Memory access)
00371 
00372 struct crtpMemoryGetNumberRequest
00373 {
00374   crtpMemoryGetNumberRequest()
00375     : header(0x04, 0)
00376     , command(1)
00377   {
00378   }
00379   const crtp header;
00380   const uint8_t command;
00381 }  __attribute__((packed));
00382 CHECKSIZE(crtpMemoryGetNumberRequest)
00383 
00384 struct crtpMemoryGetNumberResponse
00385 {
00386     static bool match(const Crazyradio::Ack& response) {
00387       return response.size == 3 &&
00388              crtp(response.data[0]) == crtp(4, 0) &&
00389              response.data[1] == 1;
00390     }
00391 
00392     crtpMemoryGetNumberRequest request;
00393     uint8_t numberOfMemories;
00394 } __attribute__((packed));
00395 CHECKSIZE_RESPONSE(crtpMemoryGetNumberResponse)
00396 
00397 struct crtpMemoryGetInfoRequest
00398 {
00399   crtpMemoryGetInfoRequest(
00400     uint8_t memId)
00401     : header(0x04, 0)
00402     , command(2)
00403     , memId(memId)
00404   {
00405   }
00406   const crtp header;
00407   const uint8_t command;
00408   uint8_t memId;
00409 }  __attribute__((packed));
00410 CHECKSIZE(crtpMemoryGetInfoRequest)
00411 
00412 enum crtpMemoryType : uint8_t
00413 {
00414   EEPROM = 0x00,
00415   OW     = 0x01,
00416   LED12  = 0x10,
00417   LOCO   = 0x11,
00418 };
00419 
00420 struct crtpMemoryGetInfoResponse
00421 {
00422     static bool match(const Crazyradio::Ack& response) {
00423       return response.size > 2 &&
00424              crtp(response.data[0]) == crtp(4, 0) &&
00425              response.data[1] == 2;
00426     }
00427 
00428     crtpMemoryGetInfoRequest request;
00429     crtpMemoryType memType;
00430     uint32_t memSize; // Bytes
00431     uint64_t memAddr; // valid for OW and EEPROM
00432 } __attribute__((packed));
00433 CHECKSIZE_RESPONSE(crtpMemoryGetInfoResponse)
00434 
00435 struct crtpMemoryReadRequest
00436 {
00437   crtpMemoryReadRequest(
00438     uint8_t memId,
00439     uint32_t memAddr,
00440     uint8_t length)
00441     : header(0x04, 1)
00442     , memId(memId)
00443     , memAddr(memAddr)
00444     , length(length)
00445   {
00446   }
00447   const crtp header;
00448   uint8_t memId;
00449   uint32_t memAddr;
00450   uint8_t length;
00451 }  __attribute__((packed));
00452 CHECKSIZE(crtpMemoryReadRequest)
00453 
00454 struct crtpMemoryReadResponse
00455 {
00456     static bool match(const Crazyradio::Ack& response) {
00457       return response.size > 2 &&
00458              crtp(response.data[0]) == crtp(4, 1);
00459     }
00460 
00461     crtp header;
00462     uint8_t memId;
00463     uint32_t memAddr;
00464     uint8_t status;
00465     uint8_t data[24];
00466 } __attribute__((packed));
00467 CHECKSIZE_RESPONSE(crtpMemoryReadResponse)
00468 
00469 struct crtpMemoryWriteRequest
00470 {
00471   crtpMemoryWriteRequest(
00472     uint8_t memId,
00473     uint32_t memAddr)
00474     : header(0x04, 2)
00475     , memId(memId)
00476     , memAddr(memAddr)
00477   {
00478   }
00479   const crtp header;
00480   uint8_t memId;
00481   uint32_t memAddr;
00482   uint8_t data[24];
00483 }  __attribute__((packed));
00484 CHECKSIZE(crtpMemoryWriteRequest)
00485 
00486 struct crtpMemoryWriteResponse
00487 {
00488     static bool match(const Crazyradio::Ack& response) {
00489       return response.size > 2 &&
00490              crtp(response.data[0]) == crtp(4, 2);
00491     }
00492 
00493     crtp header;
00494     uint8_t memId;
00495     uint32_t memAddr;
00496     uint8_t status;
00497 } __attribute__((packed));
00498 CHECKSIZE_RESPONSE(crtpMemoryWriteResponse)
00499 
00500 // Port 5 (Data logging)
00501 
00502 struct crtpLogGetInfoResponse;
00503 struct crtpLogGetInfoRequest
00504 {
00505   crtpLogGetInfoRequest()
00506     : header(5, 0)
00507     , command(1)
00508     {
00509     }
00510 
00511   bool operator==(const crtpLogGetInfoRequest& other) const {
00512     return header == other.header && command == other.command;
00513   }
00514 
00515   typedef crtpLogGetInfoResponse Response;
00516 
00517   const crtp header;
00518   const uint8_t command;
00519 } __attribute__((packed));
00520 CHECKSIZE(crtpLogGetInfoRequest)
00521 
00522 struct crtpLogGetInfoResponse
00523 {
00524   static bool match(const Crazyradio::Ack& response) {
00525     return response.size == 9 &&
00526            crtp(response.data[0]) == crtp(5, 0) &&
00527            response.data[1] == 1;
00528   }
00529 
00530   crtpLogGetInfoRequest request;
00531   // Number of log items contained in the log table of content
00532   uint8_t log_len;
00533   // CRC values of the log TOC memory content. This is a fingerprint of the copter build that can be used to cache the TOC
00534   uint32_t log_crc;
00535   // Maximum number of log packets that can be programmed in the copter
00536   uint8_t log_max_packet;
00537   // Maximum number of operation programmable in the copter. An operation is one log variable retrieval programming
00538   uint8_t log_max_ops;
00539 } __attribute__((packed));
00540 CHECKSIZE_RESPONSE(crtpLogGetInfoResponse)
00541 
00542 struct crtpLogGetItemResponse;
00543 struct crtpLogGetItemRequest
00544 {
00545   crtpLogGetItemRequest(uint8_t id)
00546     : header(5, 0)
00547     , command(0)
00548     , id(id)
00549   {
00550   }
00551 
00552   bool operator==(const crtpLogGetItemRequest& other) const {
00553     return header == other.header && command == other.command && id == other.id;
00554   }
00555 
00556   typedef crtpLogGetItemResponse Response;
00557 
00558   const crtp header;
00559   const uint8_t command;
00560   uint8_t id;
00561 } __attribute__((packed));
00562 CHECKSIZE(crtpLogGetItemRequest)
00563 
00564 struct crtpLogGetItemResponse
00565 {
00566     static bool match(const Crazyradio::Ack& response) {
00567       return response.size > 5 &&
00568              crtp(response.data[0]) == crtp(5, 0) &&
00569              response.data[1] == 0;
00570     }
00571 
00572     crtpLogGetItemRequest request;
00573     uint8_t type;
00574     char text[28]; // group, name
00575 } __attribute__((packed));
00576 CHECKSIZE_RESPONSE(crtpLogGetItemResponse)
00577 
00578 struct logBlockItem {
00579   uint8_t logType;
00580   uint8_t id;
00581 } __attribute__((packed));
00582 
00583 struct crtpLogCreateBlockRequest
00584 {
00585   crtpLogCreateBlockRequest()
00586   : header(5, 1)
00587   , command(0)
00588   {
00589   }
00590 
00591   const crtp header;
00592   const uint8_t command;
00593   uint8_t id;
00594   logBlockItem items[14];
00595 } __attribute__((packed));
00596 CHECKSIZE(crtpLogCreateBlockRequest)
00597 
00598 // struct logAppendBlockRequest
00599 // {
00600 //   logAppendBlockRequest()
00601 //     : header(5, 1)
00602 //     , command(1)
00603 //     {
00604 //     }
00605 
00606 //     const crtp header;
00607 //     const uint8_t command;
00608 //     uint8_t id;
00609 //     logBlockItem items[16];
00610 // } __attribute__((packed));
00611 
00612 // struct logDeleteBlockRequest
00613 // {
00614 //   logDeleteBlockRequest()
00615 //     : header(5, 1)
00616 //     , command(2)
00617 //     {
00618 //     }
00619 
00620 //     const crtp header;
00621 //     const uint8_t command;
00622 //     uint8_t id;
00623 // } __attribute__((packed));
00624 
00625 struct crtpLogStartRequest
00626 {
00627   crtpLogStartRequest(
00628     uint8_t id,
00629     uint8_t period)
00630     : header(5, 1)
00631     , command(3)
00632     , id(id)
00633     , period(period)
00634     {
00635     }
00636 
00637     const crtp header;
00638     const uint8_t command;
00639     uint8_t id;
00640     uint8_t period; // in increments of 10ms
00641 } __attribute__((packed));
00642 CHECKSIZE(crtpLogStartRequest)
00643 
00644 struct crtpLogStopRequest
00645 {
00646   crtpLogStopRequest(
00647     uint8_t id)
00648     : header(5, 1)
00649     , command(4)
00650     , id(id)
00651     {
00652     }
00653 
00654     const crtp header;
00655     const uint8_t command;
00656     uint8_t id;
00657 } __attribute__((packed));
00658 CHECKSIZE(crtpLogStopRequest)
00659 
00660 struct crtpLogResetRequest
00661 {
00662   crtpLogResetRequest()
00663     : header(5, 1)
00664     , command(5)
00665     {
00666     }
00667 
00668     const crtp header;
00669     const uint8_t command;
00670 } __attribute__((packed));
00671 CHECKSIZE(crtpLogResetRequest)
00672 
00673 enum crtpLogControlResult {
00674   crtpLogControlResultOk            = 0,
00675   crtpLogControlResultOutOfMemory   = 12, // ENOMEM
00676   crtpLogControlResultCmdNotFound   = 8,  // ENOEXEC
00677   crtpLogControlResultWrongBlockId  = 2,  // ENOENT
00678   crtpLogControlResultBlockTooLarge = 7,  // E2BIG
00679   crtpLogControlResultBlockExists   = 17, // EEXIST
00680 
00681 };
00682 
00683 struct crtpLogControlResponse
00684 {
00685     static bool match(const Crazyradio::Ack& response) {
00686       return response.size == 4 &&
00687              crtp(response.data[0]) == crtp(5, 1);
00688     }
00689 
00690     crtp header;
00691     uint8_t command;
00692     uint8_t requestByte1;
00693     uint8_t result; // one of crtpLogControlResult
00694 } __attribute__((packed));
00695 CHECKSIZE_RESPONSE(crtpLogControlResponse)
00696 
00697 struct crtpLogDataResponse
00698 {
00699     static bool match(const Crazyradio::Ack& response) {
00700       return response.size > 4 &&
00701              crtp(response.data[0]) == crtp(5, 2);
00702     }
00703 
00704     crtp header;
00705     uint8_t blockId;
00706     uint8_t timestampLo;
00707     uint16_t timestampHi;
00708     uint8_t data[26];
00709 } __attribute__((packed));
00710 CHECKSIZE_RESPONSE(crtpLogDataResponse)
00711 
00712 // V2
00713 struct crtpLogGetInfoV2Response;
00714 struct crtpLogGetInfoV2Request
00715 {
00716   crtpLogGetInfoV2Request()
00717     : header(5, 0)
00718     , command(3)
00719     {
00720     }
00721 
00722   bool operator==(const crtpLogGetInfoV2Request& other) const {
00723     return header == other.header && command == other.command;
00724   }
00725 
00726   typedef crtpLogGetInfoV2Response Response;
00727 
00728   const crtp header;
00729   const uint8_t command;
00730 } __attribute__((packed));
00731 CHECKSIZE(crtpLogGetInfoV2Request)
00732 
00733 struct crtpLogGetInfoV2Response
00734 {
00735   static bool match(const Crazyradio::Ack& response) {
00736     return response.size == 10 &&
00737            crtp(response.data[0]) == crtp(5, 0) &&
00738            response.data[1] == 3;
00739   }
00740 
00741   crtpLogGetInfoRequest request;
00742   // Number of log items contained in the log table of content
00743   uint16_t log_len;
00744   // CRC values of the log TOC memory content. This is a fingerprint of the copter build that can be used to cache the TOC
00745   uint32_t log_crc;
00746   // Maximum number of log packets that can be programmed in the copter
00747   uint8_t log_max_packet;
00748   // Maximum number of operation programmable in the copter. An operation is one log variable retrieval programming
00749   uint8_t log_max_ops;
00750 } __attribute__((packed));
00751 CHECKSIZE_RESPONSE(crtpLogGetInfoV2Response)
00752 
00753 struct crtpLogGetItemV2Response;
00754 struct crtpLogGetItemV2Request
00755 {
00756   crtpLogGetItemV2Request(uint16_t id)
00757     : header(5, 0)
00758     , command(2)
00759     , id(id)
00760   {
00761   }
00762 
00763   bool operator==(const crtpLogGetItemV2Request& other) const {
00764     return header == other.header && command == other.command && id == other.id;
00765   }
00766 
00767   typedef crtpLogGetItemV2Response Response;
00768 
00769   const crtp header;
00770   const uint8_t command;
00771   uint16_t id;
00772 } __attribute__((packed));
00773 CHECKSIZE(crtpLogGetItemV2Request)
00774 
00775 struct crtpLogGetItemV2Response
00776 {
00777     static bool match(const Crazyradio::Ack& response) {
00778       return response.size > 6 &&
00779              crtp(response.data[0]) == crtp(5, 0) &&
00780              response.data[1] == 2;
00781     }
00782 
00783     crtpLogGetItemV2Request request;
00784     uint8_t type;
00785     char text[27]; // group, name
00786 } __attribute__((packed));
00787 CHECKSIZE_RESPONSE(crtpLogGetItemV2Response)
00788 
00789 struct logBlockItemV2 {
00790   uint8_t logType;
00791   uint16_t id;
00792 } __attribute__((packed));
00793 
00794 struct crtpLogCreateBlockV2Request
00795 {
00796   crtpLogCreateBlockV2Request()
00797   : header(5, 1)
00798   , command(6)
00799   {
00800   }
00801 
00802   const crtp header;
00803   const uint8_t command;
00804   uint8_t id;
00805   logBlockItemV2 items[9];
00806 } __attribute__((packed));
00807 CHECKSIZE(crtpLogCreateBlockV2Request)
00808 
00809 
00810 // Port 0x06 (External Position Update)
00811 
00812 struct crtpExternalPositionUpdate
00813 {
00814   crtpExternalPositionUpdate(
00815     float x,
00816     float y,
00817     float z)
00818     : header(0x06, 0)
00819     , x(x)
00820     , y(y)
00821     , z(z)
00822   {
00823   }
00824   const crtp header;
00825   float x;
00826   float y;
00827   float z;
00828 }  __attribute__((packed));
00829 CHECKSIZE(crtpExternalPositionUpdate)
00830 
00831 struct crtpExternalPositionPacked
00832 {
00833   crtpExternalPositionPacked()
00834     : header(0x06, 2)
00835   {
00836   }
00837   const crtp header;
00838   struct {
00839     uint8_t id;
00840     int16_t x; // mm
00841     int16_t y; // mm
00842     int16_t z; // mm
00843   } __attribute__((packed)) positions[4];
00844 }  __attribute__((packed));
00845 CHECKSIZE(crtpExternalPositionPacked)
00846 
00847 struct crtpEmergencyStopRequest
00848 {
00849   crtpEmergencyStopRequest()
00850     : header(0x06, 1)
00851   {
00852   }
00853   const crtp header;
00854   const uint8_t type = 3;
00855 }  __attribute__((packed));
00856 CHECKSIZE(crtpEmergencyStopRequest)
00857 
00858 struct crtpEmergencyStopWatchdogRequest
00859 {
00860   crtpEmergencyStopWatchdogRequest()
00861     : header(0x06, 1)
00862   {
00863   }
00864   const crtp header;
00865   const uint8_t type = 4;
00866 }  __attribute__((packed));
00867 CHECKSIZE(crtpEmergencyStopWatchdogRequest)
00868 
00869 struct crtpExternalPoseUpdate
00870 {
00871   crtpExternalPoseUpdate(
00872     float x,
00873     float y,
00874     float z,
00875     float qx,
00876     float qy,
00877     float qz,
00878     float qw)
00879     : header(0x06, 1)
00880     , x(x)
00881     , y(y)
00882     , z(z)
00883     , qx(qx)
00884     , qy(qy)
00885     , qz(qz)
00886     , qw(qw)
00887   {
00888   }
00889   const crtp header;
00890   const uint8_t type = 8;
00891   float x;
00892   float y;
00893   float z;
00894   float qx;
00895   float qy;
00896   float qz;
00897   float qw;
00898 }  __attribute__((packed));
00899 CHECKSIZE(crtpExternalPoseUpdate)
00900 
00901 struct crtpExternalPosePacked
00902 {
00903   crtpExternalPosePacked()
00904     : header(0x06, 1)
00905   {
00906   }
00907   const crtp header;
00908   const uint8_t type = 9;
00909   struct {
00910     uint8_t id; // last 8 bit of the Crazyflie address
00911     int16_t x; // mm
00912     int16_t y; // mm
00913     int16_t z; // mm
00914     uint32_t quat; // compressed quaternion, see quatcompress.h
00915   } __attribute__((packed)) poses[2];
00916 }  __attribute__((packed));
00917 CHECKSIZE(crtpExternalPosePacked)
00918 
00919 struct crtpStopRequest
00920 {
00921   crtpStopRequest();
00922   const crtp header;
00923   uint8_t type;
00924 } __attribute__((packed));
00925 CHECKSIZE(crtpStopRequest)
00926 
00927 struct crtpHoverSetpointRequest
00928 {
00929   crtpHoverSetpointRequest(
00930     float vx,
00931     float vy,
00932     float yawrate,
00933     float zDistance);
00934   const crtp header;
00935   uint8_t type;
00936   float vx;
00937   float vy;
00938   float yawrate;
00939   float zDistance;
00940 } __attribute__((packed));
00941 CHECKSIZE(crtpHoverSetpointRequest)
00942 
00943 struct crtpPositionSetpointRequest
00944 {
00945   crtpPositionSetpointRequest(
00946     float x,
00947     float y,
00948     float z,
00949     float yaw);
00950   const crtp header;
00951   uint8_t type;
00952   float x;
00953   float y;
00954   float z;
00955   float yaw;
00956 } __attribute__((packed));
00957 CHECKSIZE(crtpPositionSetpointRequest)
00958 
00959 // Port 0x07 (Generic Setpoint)
00960 
00961 struct crtpFullStateSetpointRequest
00962 {
00963   crtpFullStateSetpointRequest(
00964     float x, float y, float z,
00965     float vx, float vy, float vz,
00966     float ax, float ay, float az,
00967     float qx, float qy, float qz, float qw,
00968     float rollRate, float pitchRate, float yawRate);
00969   const crtp header;
00970   uint8_t type;
00971   int16_t x;
00972   int16_t y;
00973   int16_t z;
00974   int16_t vx;
00975   int16_t vy;
00976   int16_t vz;
00977   int16_t ax;
00978   int16_t ay;
00979   int16_t az;
00980   int32_t quat; // compressed quaternion, xyzw
00981   int16_t omegax;
00982   int16_t omegay;
00983   int16_t omegaz;
00984 } __attribute__((packed));
00985 CHECKSIZE(crtpFullStateSetpointRequest)
00986 
00987 // Port 0x08 (High-level Setpoints)
00988 
00989 struct crtpCommanderHighLevelSetGroupMaskRequest
00990 {
00991   crtpCommanderHighLevelSetGroupMaskRequest(
00992     uint8_t groupMask)
00993     : header(0x08, 0)
00994     , command(0)
00995     , groupMask(groupMask)
00996     {
00997     }
00998 
00999     const crtp header;
01000     const uint8_t command;
01001     uint8_t groupMask;
01002 } __attribute__((packed));
01003 CHECKSIZE(crtpCommanderHighLevelSetGroupMaskRequest)
01004 
01005 struct crtpCommanderHighLevelTakeoffRequest
01006 {
01007   crtpCommanderHighLevelTakeoffRequest(
01008     uint8_t groupMask,
01009     float height,
01010     float duration)
01011     : header(0x08, 0)
01012     , command(1)
01013     , groupMask(groupMask)
01014     , height(height)
01015     , duration(duration)
01016     {
01017     }
01018 
01019     const crtp header;
01020     const uint8_t command;
01021     uint8_t groupMask;        // mask for which CFs this should apply to
01022     float height;             // m (absolute)
01023     float duration;           // s (time it should take until target height is reached)
01024 } __attribute__((packed));
01025 CHECKSIZE(crtpCommanderHighLevelTakeoffRequest)
01026 
01027 struct crtpCommanderHighLevelLandRequest
01028 {
01029   crtpCommanderHighLevelLandRequest(
01030     uint8_t groupMask,
01031     float height,
01032     float duration)
01033     : header(0x08, 0)
01034     , command(2)
01035     , groupMask(groupMask)
01036     , height(height)
01037     , duration(duration)
01038     {
01039     }
01040 
01041     const crtp header;
01042     const uint8_t command;
01043     uint8_t groupMask;        // mask for which CFs this should apply to
01044     float height;             // m (absolute)
01045     float duration;           // s (time it should take until target height is reached)
01046 } __attribute__((packed));
01047 CHECKSIZE(crtpCommanderHighLevelLandRequest)
01048 
01049 struct crtpCommanderHighLevelStopRequest
01050 {
01051   crtpCommanderHighLevelStopRequest(
01052     uint8_t groupMask)
01053     : header(0x08, 0)
01054     , command(3)
01055     , groupMask(groupMask)
01056     {
01057     }
01058 
01059     const crtp header;
01060     const uint8_t command;
01061     uint8_t groupMask;        // mask for which CFs this should apply to
01062 } __attribute__((packed));
01063 CHECKSIZE(crtpCommanderHighLevelStopRequest)
01064 
01065 struct crtpCommanderHighLevelGoToRequest
01066 {
01067   crtpCommanderHighLevelGoToRequest(
01068     uint8_t groupMask,
01069     bool relative,
01070     float x,
01071     float y,
01072     float z,
01073     float yaw,
01074     float duration)
01075     : header(0x08, 0)
01076     , command(4)
01077     , groupMask(groupMask)
01078     , relative(relative)
01079     , x(x)
01080     , y(y)
01081     , z(z)
01082     , yaw(yaw)
01083     , duration(duration)
01084     {
01085     }
01086 
01087     const crtp header;
01088     const uint8_t command;
01089     uint8_t groupMask; // mask for which CFs this should apply to
01090     uint8_t relative;  // set to true, if position/yaw are relative to current setpoint
01091     float x; // m
01092     float y; // m
01093     float z; // m
01094     float yaw; // deg
01095     float duration; // sec
01096 } __attribute__((packed));
01097 CHECKSIZE(crtpCommanderHighLevelGoToRequest)
01098 
01099 struct crtpCommanderHighLevelStartTrajectoryRequest
01100 {
01101   crtpCommanderHighLevelStartTrajectoryRequest(
01102     uint8_t groupMask,
01103     bool relative,
01104     bool reversed,
01105     uint8_t trajectoryId,
01106     float timescale)
01107     : header(0x08, 0)
01108     , command(5)
01109     , groupMask(groupMask)
01110     , relative(relative)
01111     , reversed(reversed)
01112     , trajectoryId(trajectoryId)
01113     , timescale(timescale)
01114     {
01115     }
01116 
01117     const crtp header;
01118     const uint8_t command;
01119     uint8_t groupMask; // mask for which CFs this should apply to
01120     uint8_t relative;  // set to true, if trajectory should be shifted to current setpoint
01121     uint8_t reversed;  // set to true, if trajectory should be executed in reverse
01122     uint8_t trajectoryId; // id of the trajectory (previously defined by COMMAND_DEFINE_TRAJECTORY)
01123     float timescale; // time factor; 1 = original speed; >1: slower; <1: faster
01124 } __attribute__((packed));
01125 CHECKSIZE(crtpCommanderHighLevelStartTrajectoryRequest)
01126 
01127 enum TrajectoryLocation_e {
01128   TRAJECTORY_LOCATION_INVALID = 0,
01129   TRAJECTORY_LOCATION_MEM     = 1, // for trajectories that are uploaded dynamically
01130   // Future features might include trajectories on flash or uSD card
01131 };
01132 
01133 enum TrajectoryType_e {
01134   TRAJECTORY_TYPE_POLY4D = 0, // struct poly4d, see pptraj.h
01135   // Future types might include versions without yaw
01136 };
01137 
01138 struct trajectoryDescription
01139 {
01140   uint8_t trajectoryLocation; // one of TrajectoryLocation_e
01141   uint8_t trajectoryType;     // one of TrajectoryType_e
01142   union
01143   {
01144     struct {
01145       uint32_t offset;  // offset in uploaded memory
01146       uint8_t n_pieces;
01147     } __attribute__((packed)) mem; // if trajectoryLocation is TRAJECTORY_LOCATION_MEM
01148   } trajectoryIdentifier;
01149 } __attribute__((packed));
01150 
01151 struct crtpCommanderHighLevelDefineTrajectoryRequest
01152 {
01153   crtpCommanderHighLevelDefineTrajectoryRequest(
01154     uint8_t trajectoryId)
01155     : header(0x08, 0)
01156     , command(6)
01157     , trajectoryId(trajectoryId)
01158     {
01159     }
01160 
01161     const crtp header;
01162     const uint8_t command;
01163     uint8_t trajectoryId;
01164     struct trajectoryDescription description;
01165 } __attribute__((packed));
01166 CHECKSIZE(crtpCommanderHighLevelDefineTrajectoryRequest)
01167 
01168 // Port 13 (Platform)
01169 
01170 struct crtpGetProtocolVersionRequest
01171 {
01172   crtpGetProtocolVersionRequest()
01173     : header(0x0D, 1)
01174     {
01175     }
01176 
01177     const crtp header;
01178     const uint8_t cmd = 0;
01179 } __attribute__((packed));
01180 CHECKSIZE(crtpGetProtocolVersionRequest)
01181 
01182 struct crtpGetProtocolVersionResponse
01183 {
01184   crtpGetProtocolVersionRequest request;
01185   int version;
01186 } __attribute__((packed));
01187 CHECKSIZE_RESPONSE(crtpGetProtocolVersionResponse)
01188 
01189 struct crtpGetFirmwareVersionRequest
01190 {
01191   crtpGetFirmwareVersionRequest()
01192     : header(0x0D, 1)
01193     {
01194     }
01195 
01196     const crtp header;
01197     const uint8_t cmd = 1;
01198 } __attribute__((packed));
01199 CHECKSIZE(crtpGetProtocolVersionRequest)
01200 
01201 struct crtpGetFirmwareVersionResponse
01202 {
01203   crtpGetFirmwareVersionRequest request;
01204   char version[30];
01205 } __attribute__((packed));
01206 CHECKSIZE_RESPONSE(crtpGetFirmwareVersionResponse)
01207 
01208 struct crtpGetDeviceTypeNameRequest
01209 {
01210   crtpGetDeviceTypeNameRequest()
01211     : header(0x0D, 1)
01212     {
01213     }
01214 
01215     const crtp header;
01216     const uint8_t cmd = 2;
01217 } __attribute__((packed));
01218 CHECKSIZE(crtpGetProtocolVersionRequest)
01219 
01220 struct crtpGetDeviceTypeNameResponse
01221 {
01222   crtpGetDeviceTypeNameRequest request;
01223   char name[30];
01224 } __attribute__((packed));
01225 CHECKSIZE_RESPONSE(crtpGetDeviceTypeNameResponse)
01226 
01227 // The crazyflie-nrf firmware sends empty packets with the signal strength, if nothing else is in the queue
01228 struct crtpPlatformRSSIAck
01229 {
01230     static bool match(const Crazyradio::Ack& response) {
01231       return crtp(response.data[0]) == crtp(15, 3);
01232     }
01233 
01234     crtp header;
01235     uint8_t reserved;
01236     uint8_t rssi;
01237 };
01238 CHECKSIZE_RESPONSE(crtpPlatformRSSIAck)


crazyflie_cpp
Author(s): Wolfgang Hoenig
autogenerated on Wed Jun 12 2019 19:20:44