dronecan.remoteid.SecureCommand_req.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_MAX_SIZE 230
  6. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SIGNATURE (0x126A47C9C17A8BD7ULL)
  7. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_ID 64
  8. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_GET_SESSION_KEY 0
  9. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_GET_REMOTEID_SESSION_KEY 1
  10. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_REMOVE_PUBLIC_KEYS 2
  11. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_GET_PUBLIC_KEYS 3
  12. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_SET_PUBLIC_KEYS 4
  13. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_GET_REMOTEID_CONFIG 5
  14. #define DRONECAN_REMOTEID_SECURECOMMAND_REQUEST_SECURE_COMMAND_SET_REMOTEID_CONFIG 6
  15. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  16. class dronecan_remoteid_SecureCommand_cxx_iface;
  17. #endif
  18. struct dronecan_remoteid_SecureCommandRequest {
  19. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  20. using cxx_iface = dronecan_remoteid_SecureCommand_cxx_iface;
  21. #endif
  22. uint32_t sequence;
  23. uint32_t operation;
  24. uint8_t sig_length;
  25. struct { uint8_t len; uint8_t data[220]; }data;
  26. };
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. uint32_t dronecan_remoteid_SecureCommandRequest_encode(struct dronecan_remoteid_SecureCommandRequest* msg, uint8_t* buffer
  32. #if CANARD_ENABLE_TAO_OPTION
  33. , bool tao
  34. #endif
  35. );
  36. bool dronecan_remoteid_SecureCommandRequest_decode(const CanardRxTransfer* transfer, struct dronecan_remoteid_SecureCommandRequest* msg);
  37. #if defined(CANARD_DSDLC_INTERNAL)
  38. static inline void _dronecan_remoteid_SecureCommandRequest_encode(uint8_t* buffer, uint32_t* bit_ofs, struct dronecan_remoteid_SecureCommandRequest* msg, bool tao);
  39. static inline bool _dronecan_remoteid_SecureCommandRequest_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct dronecan_remoteid_SecureCommandRequest* msg, bool tao);
  40. void _dronecan_remoteid_SecureCommandRequest_encode(uint8_t* buffer, uint32_t* bit_ofs, struct dronecan_remoteid_SecureCommandRequest* msg, bool tao) {
  41. (void)buffer;
  42. (void)bit_ofs;
  43. (void)msg;
  44. (void)tao;
  45. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->sequence);
  46. *bit_ofs += 32;
  47. canardEncodeScalar(buffer, *bit_ofs, 32, &msg->operation);
  48. *bit_ofs += 32;
  49. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->sig_length);
  50. *bit_ofs += 8;
  51. #pragma GCC diagnostic push
  52. #pragma GCC diagnostic ignored "-Wtype-limits"
  53. const uint8_t data_len = msg->data.len > 220 ? 220 : msg->data.len;
  54. #pragma GCC diagnostic pop
  55. if (!tao) {
  56. canardEncodeScalar(buffer, *bit_ofs, 8, &data_len);
  57. *bit_ofs += 8;
  58. }
  59. for (size_t i=0; i < data_len; i++) {
  60. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->data.data[i]);
  61. *bit_ofs += 8;
  62. }
  63. }
  64. /*
  65. decode dronecan_remoteid_SecureCommandRequest, return true on failure, false on success
  66. */
  67. bool _dronecan_remoteid_SecureCommandRequest_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct dronecan_remoteid_SecureCommandRequest* msg, bool tao) {
  68. (void)transfer;
  69. (void)bit_ofs;
  70. (void)msg;
  71. (void)tao;
  72. canardDecodeScalar(transfer, *bit_ofs, 32, false, &msg->sequence);
  73. *bit_ofs += 32;
  74. canardDecodeScalar(transfer, *bit_ofs, 32, false, &msg->operation);
  75. *bit_ofs += 32;
  76. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->sig_length);
  77. *bit_ofs += 8;
  78. if (!tao) {
  79. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->data.len);
  80. *bit_ofs += 8;
  81. } else {
  82. msg->data.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  83. }
  84. #pragma GCC diagnostic push
  85. #pragma GCC diagnostic ignored "-Wtype-limits"
  86. if (msg->data.len > 220) {
  87. return true; /* invalid value */
  88. }
  89. #pragma GCC diagnostic pop
  90. for (size_t i=0; i < msg->data.len; i++) {
  91. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->data.data[i]);
  92. *bit_ofs += 8;
  93. }
  94. return false; /* success */
  95. }
  96. #endif
  97. #ifdef CANARD_DSDLC_TEST_BUILD
  98. struct dronecan_remoteid_SecureCommandRequest sample_dronecan_remoteid_SecureCommandRequest_msg(void);
  99. #endif
  100. #ifdef __cplusplus
  101. } // extern "C"
  102. #ifdef DRONECAN_CXX_WRAPPERS
  103. #include <canard/cxx_wrappers.h>
  104. #endif
  105. #endif