uavcan.protocol.dynamic_node_id.Allocation.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MAX_SIZE 18
  6. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_SIGNATURE (0xB2A812620A11D40ULL)
  7. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_ID 1
  8. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MAX_REQUEST_PERIOD_MS 1000
  9. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MIN_REQUEST_PERIOD_MS 600
  10. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MAX_FOLLOWUP_DELAY_MS 400
  11. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MIN_FOLLOWUP_DELAY_MS 0
  12. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_FOLLOWUP_TIMEOUT_MS 500
  13. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MAX_LENGTH_OF_UNIQUE_ID_IN_REQUEST 6
  14. #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_ANY_NODE_ID 0
  15. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  16. class uavcan_protocol_dynamic_node_id_Allocation_cxx_iface;
  17. #endif
  18. struct uavcan_protocol_dynamic_node_id_Allocation {
  19. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  20. using cxx_iface = uavcan_protocol_dynamic_node_id_Allocation_cxx_iface;
  21. #endif
  22. uint8_t node_id;
  23. bool first_part_of_unique_id;
  24. struct { uint8_t len; uint8_t data[16]; }unique_id;
  25. };
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. uint32_t _uavcan_protocol_dynamic_node_id_Allocation_encode(struct uavcan_protocol_dynamic_node_id_Allocation* msg, uint8_t* buffer
  31. #if CANARD_ENABLE_TAO_OPTION
  32. , bool tao
  33. #endif
  34. );
  35. bool _uavcan_protocol_dynamic_node_id_Allocation_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_dynamic_node_id_Allocation* msg);
  36. static inline uint32_t uavcan_protocol_dynamic_node_id_Allocation_encode(struct uavcan_protocol_dynamic_node_id_Allocation* msg, uint8_t* buffer
  37. #if CANARD_ENABLE_TAO_OPTION
  38. , bool tao
  39. #endif
  40. ) {
  41. return _uavcan_protocol_dynamic_node_id_Allocation_encode(msg, buffer
  42. #if CANARD_ENABLE_TAO_OPTION
  43. , tao
  44. #endif
  45. );
  46. }
  47. static inline bool uavcan_protocol_dynamic_node_id_Allocation_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_dynamic_node_id_Allocation* msg) {
  48. return _uavcan_protocol_dynamic_node_id_Allocation_decode(transfer, msg);
  49. }
  50. #if defined(CANARD_DSDLC_INTERNAL)
  51. static inline void __uavcan_protocol_dynamic_node_id_Allocation_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_dynamic_node_id_Allocation* msg, bool tao);
  52. static inline bool __uavcan_protocol_dynamic_node_id_Allocation_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_dynamic_node_id_Allocation* msg, bool tao);
  53. void __uavcan_protocol_dynamic_node_id_Allocation_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_dynamic_node_id_Allocation* msg, bool tao) {
  54. (void)buffer;
  55. (void)bit_ofs;
  56. (void)msg;
  57. (void)tao;
  58. canardEncodeScalar(buffer, *bit_ofs, 7, &msg->node_id);
  59. *bit_ofs += 7;
  60. canardEncodeScalar(buffer, *bit_ofs, 1, &msg->first_part_of_unique_id);
  61. *bit_ofs += 1;
  62. #pragma GCC diagnostic push
  63. #pragma GCC diagnostic ignored "-Wtype-limits"
  64. const uint8_t unique_id_len = msg->unique_id.len > 16 ? 16 : msg->unique_id.len;
  65. #pragma GCC diagnostic pop
  66. if (!tao) {
  67. canardEncodeScalar(buffer, *bit_ofs, 5, &unique_id_len);
  68. *bit_ofs += 5;
  69. }
  70. for (size_t i=0; i < unique_id_len; i++) {
  71. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->unique_id.data[i]);
  72. *bit_ofs += 8;
  73. }
  74. }
  75. /*
  76. decode uavcan_protocol_dynamic_node_id_Allocation, return true on failure, false on success
  77. */
  78. bool __uavcan_protocol_dynamic_node_id_Allocation_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_dynamic_node_id_Allocation* msg, bool tao) {
  79. (void)transfer;
  80. (void)bit_ofs;
  81. (void)msg;
  82. (void)tao;
  83. canardDecodeScalar(transfer, *bit_ofs, 7, false, &msg->node_id);
  84. *bit_ofs += 7;
  85. canardDecodeScalar(transfer, *bit_ofs, 1, false, &msg->first_part_of_unique_id);
  86. *bit_ofs += 1;
  87. if (!tao) {
  88. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->unique_id.len);
  89. *bit_ofs += 5;
  90. } else {
  91. msg->unique_id.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  92. }
  93. #pragma GCC diagnostic push
  94. #pragma GCC diagnostic ignored "-Wtype-limits"
  95. if (msg->unique_id.len > 16) {
  96. return true; /* invalid value */
  97. }
  98. #pragma GCC diagnostic pop
  99. for (size_t i=0; i < msg->unique_id.len; i++) {
  100. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->unique_id.data[i]);
  101. *bit_ofs += 8;
  102. }
  103. return false; /* success */
  104. }
  105. #endif
  106. #ifdef CANARD_DSDLC_TEST_BUILD
  107. struct uavcan_protocol_dynamic_node_id_Allocation sample_uavcan_protocol_dynamic_node_id_Allocation_msg(void);
  108. #endif
  109. #ifdef __cplusplus
  110. } // extern "C"
  111. #ifdef DRONECAN_CXX_WRAPPERS
  112. #include <canard/cxx_wrappers.h>
  113. BROADCAST_MESSAGE_CXX_IFACE(uavcan_protocol_dynamic_node_id_Allocation, UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_ID, UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_SIGNATURE, UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_MAX_SIZE);
  114. #endif
  115. #endif