| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #pragma once
- #include <stdbool.h>
- #include <stdint.h>
- #include <canard.h>
- #include <uavcan.protocol.param.Empty.h>
- #define UAVCAN_PROTOCOL_PARAM_VALUE_MAX_SIZE 130
- #define UAVCAN_PROTOCOL_PARAM_VALUE_SIGNATURE (0x29F14BF484727267ULL)
- enum uavcan_protocol_param_Value_type_t {
- UAVCAN_PROTOCOL_PARAM_VALUE_EMPTY,
- UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE,
- UAVCAN_PROTOCOL_PARAM_VALUE_REAL_VALUE,
- UAVCAN_PROTOCOL_PARAM_VALUE_BOOLEAN_VALUE,
- UAVCAN_PROTOCOL_PARAM_VALUE_STRING_VALUE,
- };
- struct uavcan_protocol_param_Value {
- enum uavcan_protocol_param_Value_type_t union_tag;
- union {
- struct uavcan_protocol_param_Empty empty;
- int64_t integer_value;
- float real_value;
- uint8_t boolean_value;
- struct { uint8_t len; uint8_t data[128]; }string_value;
- };
- };
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- uint32_t _uavcan_protocol_param_Value_encode(struct uavcan_protocol_param_Value* msg, uint8_t* buffer
- #if CANARD_ENABLE_TAO_OPTION
- , bool tao
- #endif
- );
- bool _uavcan_protocol_param_Value_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_param_Value* msg);
- static inline uint32_t uavcan_protocol_param_Value_encode(struct uavcan_protocol_param_Value* msg, uint8_t* buffer
- #if CANARD_ENABLE_TAO_OPTION
- , bool tao
- #endif
- ) {
- return _uavcan_protocol_param_Value_encode(msg, buffer
- #if CANARD_ENABLE_TAO_OPTION
- , tao
- #endif
- );
- }
- static inline bool uavcan_protocol_param_Value_decode(const CanardRxTransfer* transfer, struct uavcan_protocol_param_Value* msg) {
- return _uavcan_protocol_param_Value_decode(transfer, msg);
- }
- #if defined(CANARD_DSDLC_INTERNAL)
- static inline void __uavcan_protocol_param_Value_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_param_Value* msg, bool tao);
- static inline bool __uavcan_protocol_param_Value_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_param_Value* msg, bool tao);
- void __uavcan_protocol_param_Value_encode(uint8_t* buffer, uint32_t* bit_ofs, struct uavcan_protocol_param_Value* msg, bool tao) {
- (void)buffer;
- (void)bit_ofs;
- (void)msg;
- (void)tao;
- uint8_t union_tag = msg->union_tag;
- canardEncodeScalar(buffer, *bit_ofs, 3, &union_tag);
- *bit_ofs += 3;
- switch(msg->union_tag) {
- case UAVCAN_PROTOCOL_PARAM_VALUE_EMPTY: {
- __uavcan_protocol_param_Empty_encode(buffer, bit_ofs, &msg->empty, tao);
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE: {
- canardEncodeScalar(buffer, *bit_ofs, 64, &msg->integer_value);
- *bit_ofs += 64;
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_REAL_VALUE: {
- canardEncodeScalar(buffer, *bit_ofs, 32, &msg->real_value);
- *bit_ofs += 32;
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_BOOLEAN_VALUE: {
- canardEncodeScalar(buffer, *bit_ofs, 8, &msg->boolean_value);
- *bit_ofs += 8;
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_STRING_VALUE: {
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wtype-limits"
- const uint8_t string_value_len = msg->string_value.len > 128 ? 128 : msg->string_value.len;
- #pragma GCC diagnostic pop
- if (!tao) {
- canardEncodeScalar(buffer, *bit_ofs, 8, &string_value_len);
- *bit_ofs += 8;
- }
- for (size_t i=0; i < string_value_len; i++) {
- canardEncodeScalar(buffer, *bit_ofs, 8, &msg->string_value.data[i]);
- *bit_ofs += 8;
- }
- break;
- }
- }
- }
- /*
- decode uavcan_protocol_param_Value, return true on failure, false on success
- */
- bool __uavcan_protocol_param_Value_decode(const CanardRxTransfer* transfer, uint32_t* bit_ofs, struct uavcan_protocol_param_Value* msg, bool tao) {
- (void)transfer;
- (void)bit_ofs;
- (void)msg;
- (void)tao;
- uint8_t union_tag;
- canardDecodeScalar(transfer, *bit_ofs, 3, false, &union_tag);
- *bit_ofs += 3;
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wtype-limits"
- if (union_tag >= 5) {
- return true; /* invalid value */
- }
- #pragma GCC diagnostic pop
- msg->union_tag = (enum uavcan_protocol_param_Value_type_t)union_tag;
- switch(msg->union_tag) {
- case UAVCAN_PROTOCOL_PARAM_VALUE_EMPTY: {
- if (__uavcan_protocol_param_Empty_decode(transfer, bit_ofs, &msg->empty, tao)) {return true;}
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE: {
- canardDecodeScalar(transfer, *bit_ofs, 64, true, &msg->integer_value);
- *bit_ofs += 64;
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_REAL_VALUE: {
- canardDecodeScalar(transfer, *bit_ofs, 32, true, &msg->real_value);
- *bit_ofs += 32;
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_BOOLEAN_VALUE: {
- canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->boolean_value);
- *bit_ofs += 8;
- break;
- }
- case UAVCAN_PROTOCOL_PARAM_VALUE_STRING_VALUE: {
- if (!tao) {
- canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->string_value.len);
- *bit_ofs += 8;
- } else {
- msg->string_value.len = ((transfer->payload_len*8)-*bit_ofs)/8;
- }
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wtype-limits"
- if (msg->string_value.len > 128) {
- return true; /* invalid value */
- }
- #pragma GCC diagnostic pop
- for (size_t i=0; i < msg->string_value.len; i++) {
- canardDecodeScalar(transfer, *bit_ofs, 8, false, &msg->string_value.data[i]);
- *bit_ofs += 8;
- }
- break;
- }
- }
- return false; /* success */
- }
- #endif
- #ifdef CANARD_DSDLC_TEST_BUILD
- struct uavcan_protocol_param_Value sample_uavcan_protocol_param_Value_msg(void);
- #endif
- #ifdef __cplusplus
- } // extern "C"
- #ifdef DRONECAN_CXX_WRAPPERS
- #include <canard/cxx_wrappers.h>
- #endif
- #endif
|