uavcan.protocol.dynamic_node_id.server.Discovery.h 4.5 KB

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