uavcan.protocol.file.Read_res.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #include <uavcan.protocol.file.Error.h>
  6. #define UAVCAN_PROTOCOL_FILE_READ_RESPONSE_MAX_SIZE 260
  7. #define UAVCAN_PROTOCOL_FILE_READ_RESPONSE_SIGNATURE (0x8DCDCA939F33F678ULL)
  8. #define UAVCAN_PROTOCOL_FILE_READ_RESPONSE_ID 48
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class uavcan_protocol_file_Read_cxx_iface;
  11. #endif
  12. struct uavcan_protocol_file_ReadResponse {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = uavcan_protocol_file_Read_cxx_iface;
  15. #endif
  16. struct uavcan_protocol_file_Error error;
  17. struct { uint16_t len; uint8_t data[256]; }data;
  18. };
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. uint32_t _uavcan_protocol_file_ReadResponse_encode(struct uavcan_protocol_file_ReadResponse* msg, uint8_t* buffer
  24. #if CANARD_ENABLE_TAO_OPTION
  25. , bool tao
  26. #endif
  27. );
  28. bool _uavcan_protocol_file_ReadResponse_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_file_ReadResponse* msg);
  29. static inline uint32_t uavcan_protocol_file_ReadResponse_encode(struct uavcan_protocol_file_ReadResponse* msg, uint8_t* buffer
  30. #if CANARD_ENABLE_TAO_OPTION
  31. , bool tao
  32. #endif
  33. ) {
  34. return _uavcan_protocol_file_ReadResponse_encode(msg, buffer
  35. #if CANARD_ENABLE_TAO_OPTION
  36. , tao
  37. #endif
  38. );
  39. }
  40. static inline bool uavcan_protocol_file_ReadResponse_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_file_ReadResponse* msg) {
  41. return _uavcan_protocol_file_ReadResponse_decode(transfer, msg);
  42. }
  43. #if defined(CANARD_DSDLC_INTERNAL)
  44. static inline void __uavcan_protocol_file_ReadResponse_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_file_ReadResponse* msg, bool tao);
  45. static inline bool __uavcan_protocol_file_ReadResponse_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_file_ReadResponse* msg, bool tao);
  46. void __uavcan_protocol_file_ReadResponse_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_file_ReadResponse* msg, bool tao) {
  47. (void)buffer;
  48. (void)bit_ofs;
  49. (void)msg;
  50. (void)tao;
  51. __uavcan_protocol_file_Error_encode(buffer, bit_ofs, &msg->error, false);
  52. #pragma GCC diagnostic push
  53. #pragma GCC diagnostic ignored "-Wtype-limits"
  54. const uint16_t data_len = msg->data.len > 256 ? 256 : msg->data.len;
  55. #pragma GCC diagnostic pop
  56. if (!tao) {
  57. canardEncodeScalar(buffer, *bit_ofs, 9, &data_len);
  58. *bit_ofs += 9;
  59. }
  60. for (size_t i=0; i < data_len; i++) {
  61. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->data.data[i]);
  62. *bit_ofs += 8;
  63. }
  64. }
  65. /*
  66. decode uavcan_protocol_file_ReadResponse, return true on failure, false on success
  67. */
  68. bool __uavcan_protocol_file_ReadResponse_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_file_ReadResponse* msg, bool tao) {
  69. (void)transfer;
  70. (void)bit_ofs;
  71. (void)msg;
  72. (void)tao;
  73. if (__uavcan_protocol_file_Error_decode(transfer, bit_ofs, &msg->error, false)) {return true;}
  74. if (!tao) {
  75. canardDecodeScalar(transfer, *bit_ofs, 9, false, &msg->data.len);
  76. *bit_ofs += 9;
  77. } else {
  78. msg->data.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  79. }
  80. #pragma GCC diagnostic push
  81. #pragma GCC diagnostic ignored "-Wtype-limits"
  82. if (msg->data.len > 256) {
  83. return true; /* invalid value */
  84. }
  85. #pragma GCC diagnostic pop
  86. for (size_t i=0; i < msg->data.len; i++) {
  87. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->data.data[i]);
  88. *bit_ofs += 8;
  89. }
  90. return false; /* success */
  91. }
  92. #endif
  93. #ifdef CANARD_DSDLC_TEST_BUILD
  94. struct uavcan_protocol_file_ReadResponse sample_uavcan_protocol_file_ReadResponse_msg(void);
  95. #endif
  96. #ifdef __cplusplus
  97. } // extern "C"
  98. #ifdef DRONECAN_CXX_WRAPPERS
  99. #include <canard/cxx_wrappers.h>
  100. #endif
  101. #endif