uavcan.protocol.file.Path.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define UAVCAN_PROTOCOL_FILE_PATH_MAX_SIZE 201
  6. #define UAVCAN_PROTOCOL_FILE_PATH_SIGNATURE (0x12AEFC50878A43E2ULL)
  7. #define UAVCAN_PROTOCOL_FILE_PATH_SEPARATOR 47
  8. struct uavcan_protocol_file_Path {
  9. struct { uint8_t len; uint8_t data[200]; }path;
  10. };
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. uint32_t _uavcan_protocol_file_Path_encode(struct uavcan_protocol_file_Path* msg, uint8_t* buffer
  16. #if CANARD_ENABLE_TAO_OPTION
  17. , bool tao
  18. #endif
  19. );
  20. bool _uavcan_protocol_file_Path_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_file_Path* msg);
  21. static inline uint32_t uavcan_protocol_file_Path_encode(struct uavcan_protocol_file_Path* msg, uint8_t* buffer
  22. #if CANARD_ENABLE_TAO_OPTION
  23. , bool tao
  24. #endif
  25. ) {
  26. return _uavcan_protocol_file_Path_encode(msg, buffer
  27. #if CANARD_ENABLE_TAO_OPTION
  28. , tao
  29. #endif
  30. );
  31. }
  32. static inline bool uavcan_protocol_file_Path_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_file_Path* msg) {
  33. return _uavcan_protocol_file_Path_decode(transfer, msg);
  34. }
  35. #if defined(CANARD_DSDLC_INTERNAL)
  36. static inline void __uavcan_protocol_file_Path_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_file_Path* msg, bool tao);
  37. static inline bool __uavcan_protocol_file_Path_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_file_Path* msg, bool tao);
  38. void __uavcan_protocol_file_Path_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_file_Path* msg, bool tao) {
  39. (void)buffer;
  40. (void)bit_ofs;
  41. (void)msg;
  42. (void)tao;
  43. #pragma GCC diagnostic push
  44. #pragma GCC diagnostic ignored "-Wtype-limits"
  45. const uint8_t path_len = msg->path.len > 200 ? 200 : msg->path.len;
  46. #pragma GCC diagnostic pop
  47. if (!tao) {
  48. canardEncodeScalar(buffer, *bit_ofs, 8, &path_len);
  49. *bit_ofs += 8;
  50. }
  51. for (size_t i=0; i < path_len; i++) {
  52. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->path.data[i]);
  53. *bit_ofs += 8;
  54. }
  55. }
  56. /*
  57. decode uavcan_protocol_file_Path, return true on failure, false on success
  58. */
  59. bool __uavcan_protocol_file_Path_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_file_Path* msg, bool tao) {
  60. (void)transfer;
  61. (void)bit_ofs;
  62. (void)msg;
  63. (void)tao;
  64. if (!tao) {
  65. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->path.len);
  66. *bit_ofs += 8;
  67. } else {
  68. msg->path.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  69. }
  70. #pragma GCC diagnostic push
  71. #pragma GCC diagnostic ignored "-Wtype-limits"
  72. if (msg->path.len > 200) {
  73. return true; /* invalid value */
  74. }
  75. #pragma GCC diagnostic pop
  76. for (size_t i=0; i < msg->path.len; i++) {
  77. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->path.data[i]);
  78. *bit_ofs += 8;
  79. }
  80. return false; /* success */
  81. }
  82. #endif
  83. #ifdef CANARD_DSDLC_TEST_BUILD
  84. struct uavcan_protocol_file_Path sample_uavcan_protocol_file_Path_msg(void);
  85. #endif
  86. #ifdef __cplusplus
  87. } // extern "C"
  88. #ifdef DRONECAN_CXX_WRAPPERS
  89. #include <canard/cxx_wrappers.h>
  90. #endif
  91. #endif