dronecan.remoteid.SecureCommand_res.h 4.0 KB

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