mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 05:07:35 +08:00
Refactored unions
This commit is contained in:
@@ -32,22 +32,22 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
KeyValue::iterator it = kv.find(name.c_str());
|
||||
if (it != kv.end())
|
||||
{
|
||||
if (value.is<bool>())
|
||||
if (value.is(Value::Tag::boolean_value))
|
||||
{
|
||||
assert(value.getTag() == Value::Tag::boolean_value);
|
||||
it->second = double(value.boolean_value);
|
||||
}
|
||||
else if (value.is<Value::FieldTypes::integer_value>())
|
||||
else if (value.is(Value::Tag::integer_value))
|
||||
{
|
||||
assert(value.getTag() == Value::Tag::integer_value);
|
||||
it->second = double(value.integer_value);
|
||||
}
|
||||
else if (value.is<float>())
|
||||
else if (value.is(Value::Tag::real_value))
|
||||
{
|
||||
assert(value.getTag() == Value::Tag::real_value);
|
||||
it->second = double(value.real_value);
|
||||
}
|
||||
else if (value.is<Value::FieldTypes::string_value>())
|
||||
else if (value.is(Value::Tag::string_value))
|
||||
{
|
||||
assert(value.getTag() == Value::Tag::string_value);
|
||||
it->second = std::atof(value.string_value.c_str());
|
||||
@@ -65,7 +65,7 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
KeyValue::const_iterator it = kv.find(name.c_str());
|
||||
if (it != kv.end())
|
||||
{
|
||||
out_value = float(it->second);
|
||||
out_value.to<Value::Tag::real_value>() = float(it->second);
|
||||
assert(out_value.getTag() == Value::Tag::real_value);
|
||||
}
|
||||
std::cout << "READ [" << name.c_str() << "]\n" << out_value << "\n---" << std::endl;
|
||||
@@ -141,10 +141,10 @@ TEST(ParamServer, Basic)
|
||||
// No such variable, shall return empty name/value
|
||||
get_set_rq.index = 0;
|
||||
get_set_rq.name.clear();
|
||||
get_set_rq.value = uavcan::int64_t(0xDEADBEEF);
|
||||
get_set_rq.value.to<uavcan::protocol::param::Value::Tag::integer_value>() = 0xDEADBEEF;
|
||||
doCall(get_set_cln, get_set_rq, nodes);
|
||||
ASSERT_TRUE(get_set_cln.collector.result->getResponse().name.empty());
|
||||
ASSERT_TRUE(get_set_cln.collector.result->getResponse().value.is<uavcan::protocol::param::Empty>());
|
||||
ASSERT_TRUE(get_set_cln.collector.result->getResponse().value.is(uavcan::protocol::param::Value::Tag::empty));
|
||||
|
||||
mgr.kv["foobar"] = 123.456; // New param
|
||||
|
||||
@@ -153,21 +153,24 @@ TEST(ParamServer, Basic)
|
||||
get_set_rq.name = "foobar";
|
||||
doCall(get_set_cln, get_set_rq, nodes);
|
||||
ASSERT_STREQ("foobar", get_set_cln.collector.result->getResponse().name.c_str());
|
||||
ASSERT_TRUE(get_set_cln.collector.result->getResponse().value.is<float>());
|
||||
ASSERT_FLOAT_EQ(123.456F, get_set_cln.collector.result->getResponse().value.to<float>());
|
||||
ASSERT_TRUE(get_set_cln.collector.result->getResponse().value.is(uavcan::protocol::param::Value::Tag::real_value));
|
||||
ASSERT_FLOAT_EQ(123.456F, get_set_cln.collector.result->getResponse().value.
|
||||
to<uavcan::protocol::param::Value::Tag::real_value>());
|
||||
|
||||
// Set by index
|
||||
get_set_rq = uavcan::protocol::param::GetSet::Request();
|
||||
get_set_rq.index = 0;
|
||||
get_set_rq.value = uavcan::protocol::param::Value::FieldTypes::string_value("424242");
|
||||
get_set_rq.value.to<uavcan::protocol::param::Value::Tag::string_value>() = "424242";
|
||||
doCall(get_set_cln, get_set_rq, nodes);
|
||||
ASSERT_STREQ("foobar", get_set_cln.collector.result->getResponse().name.c_str());
|
||||
ASSERT_FLOAT_EQ(424242, get_set_cln.collector.result->getResponse().value.to<float>());
|
||||
ASSERT_FLOAT_EQ(424242, get_set_cln.collector.result->getResponse().value.
|
||||
to<uavcan::protocol::param::Value::Tag::real_value>());
|
||||
|
||||
// Get by index
|
||||
get_set_rq = uavcan::protocol::param::GetSet::Request();
|
||||
get_set_rq.index = 0;
|
||||
doCall(get_set_cln, get_set_rq, nodes);
|
||||
ASSERT_STREQ("foobar", get_set_cln.collector.result->getResponse().name.c_str());
|
||||
ASSERT_FLOAT_EQ(424242, get_set_cln.collector.result->getResponse().value.to<float>());
|
||||
ASSERT_FLOAT_EQ(424242, get_set_cln.collector.result->getResponse().value.
|
||||
to<uavcan::protocol::param::Value::Tag::real_value>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user