dronecan.remoteid.OperatorID.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <canard.h>
  5. #define DRONECAN_REMOTEID_OPERATORID_MAX_SIZE 43
  6. #define DRONECAN_REMOTEID_OPERATORID_SIGNATURE (0x581E7FC7F03AF935ULL)
  7. #define DRONECAN_REMOTEID_OPERATORID_ID 20034
  8. #define DRONECAN_REMOTEID_OPERATORID_ODID_OPERATOR_ID_TYPE_CAA 0
  9. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  10. class dronecan_remoteid_OperatorID_cxx_iface;
  11. #endif
  12. struct dronecan_remoteid_OperatorID {
  13. #if defined(__cplusplus) && defined(DRONECAN_CXX_WRAPPERS)
  14. using cxx_iface = dronecan_remoteid_OperatorID_cxx_iface;
  15. #endif
  16. struct { uint8_t len; uint8_t data[20]; }id_or_mac;
  17. uint8_t operator_id_type;
  18. struct { uint8_t len; uint8_t data[20]; }operator_id;
  19. };
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. uint32_t dronecan_remoteid_OperatorID_encode(struct dronecan_remoteid_OperatorID* msg, uint8_t* buffer
  25. #if CANARD_ENABLE_TAO_OPTION
  26. , bool tao
  27. #endif
  28. );
  29. bool dronecan_remoteid_OperatorID_decode(const CanardRxTransfer* transfer, struct dronecan_remoteid_OperatorID* msg);
  30. #if defined(CANARD_DSDLC_INTERNAL)
  31. static inline void _dronecan_remoteid_OperatorID_encode(uint8_t* buffer, uint32_t* bit_ofs, struct dronecan_remoteid_OperatorID* msg, bool tao);
  32. static inline bool _dronecan_remoteid_OperatorID_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct dronecan_remoteid_OperatorID* msg, bool tao);
  33. void _dronecan_remoteid_OperatorID_encode(uint8_t* buffer, uint32_t* bit_ofs, struct dronecan_remoteid_OperatorID* msg, bool tao) {
  34. (void)buffer;
  35. (void)bit_ofs;
  36. (void)msg;
  37. (void)tao;
  38. #pragma GCC diagnostic push
  39. #pragma GCC diagnostic ignored "-Wtype-limits"
  40. const uint8_t id_or_mac_len = msg->id_or_mac.len > 20 ? 20 : msg->id_or_mac.len;
  41. #pragma GCC diagnostic pop
  42. canardEncodeScalar(buffer, *bit_ofs, 5, &id_or_mac_len);
  43. *bit_ofs += 5;
  44. for (size_t i=0; i < id_or_mac_len; i++) {
  45. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->id_or_mac.data[i]);
  46. *bit_ofs += 8;
  47. }
  48. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->operator_id_type);
  49. *bit_ofs += 8;
  50. #pragma GCC diagnostic push
  51. #pragma GCC diagnostic ignored "-Wtype-limits"
  52. const uint8_t operator_id_len = msg->operator_id.len > 20 ? 20 : msg->operator_id.len;
  53. #pragma GCC diagnostic pop
  54. if (!tao) {
  55. canardEncodeScalar(buffer, *bit_ofs, 5, &operator_id_len);
  56. *bit_ofs += 5;
  57. }
  58. for (size_t i=0; i < operator_id_len; i++) {
  59. canardEncodeScalar(buffer, *bit_ofs, 8, &msg->operator_id.data[i]);
  60. *bit_ofs += 8;
  61. }
  62. }
  63. /*
  64. decode dronecan_remoteid_OperatorID, return true on failure, false on success
  65. */
  66. bool _dronecan_remoteid_OperatorID_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct dronecan_remoteid_OperatorID* msg, bool tao) {
  67. (void)transfer;
  68. (void)bit_ofs;
  69. (void)msg;
  70. (void)tao;
  71. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->id_or_mac.len);
  72. *bit_ofs += 5;
  73. #pragma GCC diagnostic push
  74. #pragma GCC diagnostic ignored "-Wtype-limits"
  75. if (msg->id_or_mac.len > 20) {
  76. return true; /* invalid value */
  77. }
  78. #pragma GCC diagnostic pop
  79. for (size_t i=0; i < msg->id_or_mac.len; i++) {
  80. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->id_or_mac.data[i]);
  81. *bit_ofs += 8;
  82. }
  83. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->operator_id_type);
  84. *bit_ofs += 8;
  85. if (!tao) {
  86. canardDecodeScalar(transfer, *bit_ofs, 5, false, &msg->operator_id.len);
  87. *bit_ofs += 5;
  88. } else {
  89. msg->operator_id.len = ((transfer->payload_len*8)-*bit_ofs)/8;
  90. }
  91. #pragma GCC diagnostic push
  92. #pragma GCC diagnostic ignored "-Wtype-limits"
  93. if (msg->operator_id.len > 20) {
  94. return true; /* invalid value */
  95. }
  96. #pragma GCC diagnostic pop
  97. for (size_t i=0; i < msg->operator_id.len; i++) {
  98. canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->operator_id.data[i]);
  99. *bit_ofs += 8;
  100. }
  101. return false; /* success */
  102. }
  103. #endif
  104. #ifdef CANARD_DSDLC_TEST_BUILD
  105. struct dronecan_remoteid_OperatorID sample_dronecan_remoteid_OperatorID_msg(void);
  106. #endif
  107. #ifdef __cplusplus
  108. } // extern "C"
  109. #ifdef DRONECAN_CXX_WRAPPERS
  110. #include <canard/cxx_wrappers.h>
  111. BROADCAST_MESSAGE_CXX_IFACE(dronecan_remoteid_OperatorID, DRONECAN_REMOTEID_OPERATORID_ID, DRONECAN_REMOTEID_OPERATORID_SIGNATURE, DRONECAN_REMOTEID_OPERATORID_MAX_SIZE);
  112. #endif
  113. #endif