uavcan.equipment.actuator.Command.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_MAX_SIZE 4
  6. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_SIGNATURE (0x8D9A6A920C1D616CULL)
  7. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_COMMAND_TYPE_UNITLESS 0
  8. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_COMMAND_TYPE_POSITION 1
  9. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_COMMAND_TYPE_FORCE 2
  10. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_COMMAND_TYPE_SPEED 3
  11. #define UAVCAN_EQUIPMENT_ACTUATOR_COMMAND_COMMAND_TYPE_PWM 4
  12. struct uavcan_equipment_actuator_Command {
  13. uint8_t actuator_id;
  14. uint8_t command_type;
  15. float command_value;
  16. };
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. uint32_t _uavcan_equipment_actuator_Command_encode(struct uavcan_equipment_actuator_Command* msg, uint8_t* buffer
  22. #if CANARD_ENABLE_TAO_OPTION
  23. , bool tao
  24. #endif
  25. );
  26. bool _uavcan_equipment_actuator_Command_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_actuator_Command* msg);
  27. static inline uint32_t uavcan_equipment_actuator_Command_encode(struct uavcan_equipment_actuator_Command* msg, uint8_t* buffer
  28. #if CANARD_ENABLE_TAO_OPTION
  29. , bool tao
  30. #endif
  31. ) {
  32. return _uavcan_equipment_actuator_Command_encode(msg, buffer
  33. #if CANARD_ENABLE_TAO_OPTION
  34. , tao
  35. #endif
  36. );
  37. }
  38. static inline bool uavcan_equipment_actuator_Command_decode(const CanardRxTransfer* transfer, struct uavcan_equipment_actuator_Command* msg) {
  39. return _uavcan_equipment_actuator_Command_decode(transfer, msg);
  40. }
  41. #if defined(CANARD_DSDLC_INTERNAL)
  42. static inline void __uavcan_equipment_actuator_Command_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_Command* msg, bool tao);
  43. static inline bool __uavcan_equipment_actuator_Command_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_Command* msg, bool tao);
  44. void __uavcan_equipment_actuator_Command_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_Command* msg, bool tao) {
  45. (void)buffer;
  46. (void)bit_ofs;
  47. (void)msg;
  48. (void)tao;
  49. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->actuator_id);
  50. *bit_ofs += 8;
  51. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->command_type);
  52. *bit_ofs += 8;
  53. {
  54. uint16_t float16_val = canardConvertNativeFloatToFloat16(msg->command_value);
  55. canardEncodeScalar(buffer, *bit_ofs, 16, &float16_val);
  56. }
  57. *bit_ofs += 16;
  58. }
  59. /*
  60. decode uavcan_equipment_actuator_Command, return true on failure, false on success
  61. */
  62. bool __uavcan_equipment_actuator_Command_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_equipment_actuator_Command* msg, bool tao) {
  63. (void)transfer;
  64. (void)bit_ofs;
  65. (void)msg;
  66. (void)tao;
  67. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->actuator_id);
  68. *bit_ofs += 8;
  69. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->command_type);
  70. *bit_ofs += 8;
  71. {
  72. uint16_t float16_val;
  73. canardDecodeScalar(transfer, *bit_ofs, 16, true, &float16_val);
  74. msg->command_value = canardConvertFloat16ToNativeFloat(float16_val);
  75. }
  76. *bit_ofs += 16;
  77. return false; /* success */
  78. }
  79. #endif
  80. #ifdef CANARD_DSDLC_TEST_BUILD
  81. struct uavcan_equipment_actuator_Command sample_uavcan_equipment_actuator_Command_msg(void);
  82. #endif
  83. #ifdef __cplusplus
  84. } // extern "C"
  85. #ifdef DRONECAN_CXX_WRAPPERS
  86. #include <canard/cxx_wrappers.h>
  87. #endif
  88. #endif