mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 17:58:52 +08:00
Merge pull request #128 from UAVCAN/integer_bit_len_check
DSDL union tag code generation bug fix
This commit is contained in:
@@ -70,7 +70,7 @@ struct UAVCAN_EXPORT ${t.cpp_type_name}
|
||||
};
|
||||
};
|
||||
|
||||
typedef ::uavcan::IntegerSpec< ::uavcan::IntegerBitLen< ${len(fields)} >::Result,
|
||||
typedef ::uavcan::IntegerSpec< ::uavcan::IntegerBitLen< ${len(fields)}U - 1U >::Result,
|
||||
::uavcan::SignednessUnsigned, ::uavcan::CastModeTruncate > TagType;
|
||||
|
||||
<!--(macro expand_enum_per_field)--> #! enum_name, enum_comparator
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <root_ns_a/Deep.hpp>
|
||||
#include <root_ns_a/UnionTest.hpp>
|
||||
#include <root_ns_a/UnionTest4.hpp>
|
||||
|
||||
template <typename T>
|
||||
static bool validateYaml(const T& obj, const std::string& reference)
|
||||
@@ -200,6 +201,37 @@ TEST(Dsdl, Union)
|
||||
}
|
||||
|
||||
|
||||
TEST(Dsdl, UnionTagWidth)
|
||||
{
|
||||
using root_ns_a::UnionTest4;
|
||||
|
||||
ASSERT_EQ(2, UnionTest4::MinBitLen);
|
||||
ASSERT_EQ(8, UnionTest4::MaxBitLen);
|
||||
|
||||
UnionTest4 s;
|
||||
|
||||
{
|
||||
uavcan::StaticTransferBuffer<100> buf;
|
||||
uavcan::BitStream bs_wr(buf);
|
||||
uavcan::ScalarCodec sc_wr(bs_wr);
|
||||
|
||||
ASSERT_EQ(1, UnionTest4::encode(s, sc_wr));
|
||||
ASSERT_EQ("00000000", bs_wr.toString());
|
||||
}
|
||||
|
||||
{
|
||||
uavcan::StaticTransferBuffer<100> buf;
|
||||
uavcan::BitStream bs_wr(buf);
|
||||
uavcan::ScalarCodec sc_wr(bs_wr);
|
||||
|
||||
s.to<UnionTest4::Tag::third>() = 1U << 5U; // 32, 0b100000
|
||||
|
||||
ASSERT_EQ(1, UnionTest4::encode(s, sc_wr));
|
||||
ASSERT_EQ("10100000", bs_wr.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(Dsdl, ParamGetSetRequestUnion)
|
||||
{
|
||||
uavcan::protocol::param::GetSet::Request req;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# A union of four items; tag 2 bits wide, total length 1 byte
|
||||
@union # 2 bits
|
||||
Empty first # Tag value 0
|
||||
uint5 second # Tag value 1
|
||||
uint6 third # Tag value 2
|
||||
int2 fourth # Tag value 3
|
||||
Reference in New Issue
Block a user