uavcan.protocol.file.BeginFirmwareUpdate_res.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_MAX_SIZE 129
  6. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_SIGNATURE (0xB7D725DF72724126ULL)
  7. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_ID 40
  8. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_ERROR_OK 0
  9. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_ERROR_INVALID_MODE 1
  10. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_ERROR_IN_PROGRESS 2
  11. #define UAVCAN_PROTOCOL_FILE_BEGINFIRMWAREUPDATE_RESPONSE_ERROR_UNKNOWN 255
  12. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  13. class uavcan_protocol_file_BeginFirmwareUpdate_cxx_iface;
  14. #endif
  15. struct uavcan_protocol_file_BeginFirmwareUpdateResponse {
  16. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  17. using cxx_iface = uavcan_protocol_file_BeginFirmwareUpdate_cxx_iface;
  18. #endif
  19. uint8_t error;
  20. struct { uint8_t len; uint8_t data[127]; }optional_error_message;
  21. };
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. uint32_t _uavcan_protocol_file_BeginFirmwareUpdateResponse_encode(struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg, uint8_t* buffer
  27. #if CANARD_ENABLE_TAO_OPTION
  28. , bool tao
  29. #endif
  30. );
  31. bool _uavcan_protocol_file_BeginFirmwareUpdateResponse_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg);
  32. static inline uint32_t uavcan_protocol_file_BeginFirmwareUpdateResponse_encode(struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg, uint8_t* buffer
  33. #if CANARD_ENABLE_TAO_OPTION
  34. , bool tao
  35. #endif
  36. ) {
  37. return _uavcan_protocol_file_BeginFirmwareUpdateResponse_encode(msg, buffer
  38. #if CANARD_ENABLE_TAO_OPTION
  39. , tao
  40. #endif
  41. );
  42. }
  43. static inline bool uavcan_protocol_file_BeginFirmwareUpdateResponse_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg) {
  44. return _uavcan_protocol_file_BeginFirmwareUpdateResponse_decode(transfer, msg);
  45. }
  46. #if defined(CANARD_DSDLC_INTERNAL)
  47. static inline void __uavcan_protocol_file_BeginFirmwareUpdateResponse_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg, bool tao);
  48. static inline bool __uavcan_protocol_file_BeginFirmwareUpdateResponse_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg, bool tao);
  49. void __uavcan_protocol_file_BeginFirmwareUpdateResponse_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg, bool tao) {
  50. (void)buffer;
  51. (void)bit_ofs;
  52. (void)msg;
  53. (void)tao;
  54. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->error);
  55. *bit_ofs += 8;
  56. #pragma GCC diagnostic push
  57. #pragma GCC diagnostic ignored "-Wtype-limits"
  58. const uint8_t optional_error_message_len = msg->optional_error_message.len > 127 ? 127 : msg->optional_error_message.len;
  59. #pragma GCC diagnostic pop
  60. if (!tao) {
  61. canardEncodeScalar(buffer, *bit_ofs, 7, &optional_error_message_len);
  62. *bit_ofs += 7;
  63. }
  64. for (size_t i=0; i < optional_error_message_len; i++) {
  65. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->optional_error_message.data[i]);
  66. *bit_ofs += 8;
  67. }
  68. }
  69. /*
  70. decode uavcan_protocol_file_BeginFirmwareUpdateResponse, return true on failure, false on success
  71. */
  72. bool __uavcan_protocol_file_BeginFirmwareUpdateResponse_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_file_BeginFirmwareUpdateResponse* msg, bool tao) {
  73. (void)transfer;
  74. (void)bit_ofs;
  75. (void)msg;
  76. (void)tao;
  77. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->error);
  78. *bit_ofs += 8;
  79. if (!tao) {
  80. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->optional_error_message.len);
  81. *bit_ofs += 7;
  82. } else {
  83. msg->optional_error_message.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  84. }
  85. #pragma GCC diagnostic push
  86. #pragma GCC diagnostic ignored "-Wtype-limits"
  87. if (msg->optional_error_message.len > 127) {
  88. return true; /* invalid value */
  89. }
  90. #pragma GCC diagnostic pop
  91. for (size_t i=0; i < msg->optional_error_message.len; i++) {
  92. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->optional_error_message.data[i]);
  93. *bit_ofs += 8;
  94. }
  95. return false; /* success */
  96. }
  97. #endif
  98. #ifdef CANARD_DSDLC_TEST_BUILD
  99. struct uavcan_protocol_file_BeginFirmwareUpdateResponse sample_uavcan_protocol_file_BeginFirmwareUpdateResponse_msg(void);
  100. #endif
  101. #ifdef __cplusplus
  102. } // extern "C"
  103. #ifdef DRONECAN_CXX_WRAPPERS
  104. #include <canard/cxx_wrappers.h>
  105. #endif
  106. #endif