mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 06:13:35 +08:00
Merge branch 'dsdl_review'
This commit is contained in:
@@ -105,6 +105,12 @@ TEST(DataTypeDescriptor, ToString)
|
||||
desc = uavcan::DataTypeDescriptor(uavcan::DataTypeKindMessage, 123,
|
||||
uavcan::DataTypeSignature(0xdeadbeef1234), "Bar");
|
||||
ASSERT_EQ("Bar:123m:0000deadbeef1234", desc.toString());
|
||||
|
||||
// Max length - 80 chars
|
||||
desc = uavcan::DataTypeDescriptor(uavcan::DataTypeKindMessage, 1023, uavcan::DataTypeSignature(0xdeadbeef12345678),
|
||||
"sirius_cybernetics_corporation.marvin.model_a.LongDataTypeName123456789abcdefghi");
|
||||
ASSERT_EQ("sirius_cybernetics_corporation.marvin.model_a.LongDataTypeName123456789abcdefghi:1023m:deadbeef12345678",
|
||||
desc.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST(Dsdl, Signature)
|
||||
ASSERT_EQ("root_ns_a.EmptyService", root_ns_a::EmptyService::getDataTypeFullName());
|
||||
ASSERT_EQ(uavcan::DataTypeKindService, root_ns_a::EmptyService::DataTypeKind);
|
||||
|
||||
ASSERT_EQ(0x41a2582ee72be419, root_ns_a::NestedMessage::getDataTypeSignature().get()); // Computed manually
|
||||
ASSERT_EQ(0x99604d7066e0d713, root_ns_a::NestedMessage::getDataTypeSignature().get()); // Computed manually
|
||||
ASSERT_EQ("root_ns_a.NestedMessage", root_ns_a::NestedMessage::getDataTypeFullName());
|
||||
ASSERT_EQ(uavcan::DataTypeKindMessage, root_ns_a::NestedMessage::DataTypeKind);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ TEST(Dsdl, Streaming)
|
||||
"status: \n"
|
||||
" uptime_sec: 0\n"
|
||||
" status_code: 0\n"
|
||||
" vendor_specific_status_code: 0\n"
|
||||
"software_version: \n"
|
||||
" major: 0\n"
|
||||
" minor: 0\n"
|
||||
|
||||
@@ -1278,3 +1278,21 @@ TEST(Array, FuzzyComparison)
|
||||
uavcan::YamlStreamer<ArrayDynamic64>::stream(std::cout, array_d64, 0);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
TEST(Array, CaseConversion)
|
||||
{
|
||||
Array<IntegerSpec<8, SignednessUnsigned, CastModeTruncate>, ArrayModeDynamic, 30> str;
|
||||
|
||||
str.convertToLowerCaseASCII();
|
||||
str.convertToUpperCaseASCII();
|
||||
|
||||
ASSERT_STREQ("", str.c_str());
|
||||
|
||||
str = "Hello World!";
|
||||
|
||||
ASSERT_STREQ("Hello World!", str.c_str());
|
||||
str.convertToLowerCaseASCII();
|
||||
ASSERT_STREQ("hello world!", str.c_str());
|
||||
str.convertToUpperCaseASCII();
|
||||
ASSERT_STREQ("HELLO WORLD!", str.c_str());
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* The slave must only register the timestamp and adjust nothing
|
||||
*/
|
||||
uavcan::protocol::GlobalTimeSync gts;
|
||||
gts.prev_utc_usec = 0;
|
||||
gts.previous_transmission_timestamp_usec = 0;
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10));
|
||||
ASSERT_EQ(0, slave_clock.utc);
|
||||
ASSERT_EQ(1000000, master_clock.utc);
|
||||
@@ -54,7 +54,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* Slave must adjust now
|
||||
*/
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(1000000, slave_clock.utc);
|
||||
ASSERT_EQ(1000000, master_clock.utc);
|
||||
@@ -72,7 +72,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* Will update
|
||||
*/
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(2000000, slave_clock.utc);
|
||||
ASSERT_EQ(2000000, master_clock.utc);
|
||||
@@ -88,7 +88,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
* Will adjust
|
||||
*/
|
||||
gts_pub.broadcast(gts);
|
||||
gts.prev_utc_usec = master_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(3000000, slave_clock.utc);
|
||||
ASSERT_EQ(3000000, master_clock.utc);
|
||||
@@ -117,9 +117,9 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
/*
|
||||
* Update step, no adjustment yet
|
||||
*/
|
||||
gts.prev_utc_usec = 0;
|
||||
gts.previous_transmission_timestamp_usec = 0;
|
||||
gts_pub2.broadcast(gts);
|
||||
gts.prev_utc_usec = master2_clock.utc;
|
||||
gts.previous_transmission_timestamp_usec = master2_clock.utc;
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(4000000, slave_clock.utc);
|
||||
ASSERT_EQ(100, master2_clock.utc);
|
||||
@@ -142,7 +142,7 @@ TEST(GlobalTimeSyncSlave, Basic)
|
||||
/*
|
||||
* Another master will be ignored now
|
||||
*/
|
||||
gts.prev_utc_usec = 99999999;
|
||||
gts.previous_transmission_timestamp_usec = 99999999;
|
||||
// Update
|
||||
gts_pub.broadcast(gts);
|
||||
nodes.spinBoth(uavcan::MonotonicDuration());
|
||||
|
||||
@@ -20,7 +20,7 @@ static void publishNodeStatus(CanDriverMock& can, uavcan::NodeID node_id, uavcan
|
||||
|
||||
// Manual message publication
|
||||
ASSERT_LT(0, uavcan::protocol::NodeStatus::encode(msg, codec));
|
||||
ASSERT_GE(7, buffer.getMaxWritePos());
|
||||
ASSERT_GE(8, buffer.getMaxWritePos());
|
||||
|
||||
// DataTypeID data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
|
||||
// uint_fast8_t frame_index, TransferID transfer_id, bool last_frame
|
||||
|
||||
@@ -48,15 +48,15 @@ TEST(NodeStatusProvider, Basic)
|
||||
|
||||
// Checking the publishing rate settings
|
||||
ASSERT_EQ(uavcan::MonotonicDuration::fromMSec(uavcan::protocol::NodeStatus::MAX_PUBLICATION_PERIOD_MS),
|
||||
nsp.getStatusPublishingPeriod());
|
||||
nsp.getStatusPublicationPeriod());
|
||||
|
||||
nsp.setStatusPublishingPeriod(uavcan::MonotonicDuration());
|
||||
nsp.setStatusPublicationPeriod(uavcan::MonotonicDuration());
|
||||
ASSERT_EQ(uavcan::MonotonicDuration::fromMSec(uavcan::protocol::NodeStatus::MIN_PUBLICATION_PERIOD_MS),
|
||||
nsp.getStatusPublishingPeriod());
|
||||
nsp.getStatusPublicationPeriod());
|
||||
|
||||
nsp.setStatusPublishingPeriod(uavcan::MonotonicDuration::fromMSec(3600 * 1000 * 24));
|
||||
nsp.setStatusPublicationPeriod(uavcan::MonotonicDuration::fromMSec(3600 * 1000 * 24));
|
||||
ASSERT_EQ(uavcan::MonotonicDuration::fromMSec(uavcan::protocol::NodeStatus::MAX_PUBLICATION_PERIOD_MS),
|
||||
nsp.getStatusPublishingPeriod());
|
||||
nsp.getStatusPublicationPeriod());
|
||||
|
||||
/*
|
||||
* Initial status publication
|
||||
@@ -70,6 +70,22 @@ TEST(NodeStatusProvider, Basic)
|
||||
|
||||
ASSERT_TRUE(status_sub.collector.msg.get()); // Was published at startup
|
||||
ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_OK, status_sub.collector.msg->status_code);
|
||||
ASSERT_EQ(0, status_sub.collector.msg->vendor_specific_status_code);
|
||||
ASSERT_GE(1, status_sub.collector.msg->uptime_sec);
|
||||
|
||||
/*
|
||||
* Altering the vendor-specific status code, forcePublish()-ing it and checking the result
|
||||
*/
|
||||
ASSERT_EQ(0, nsp.getVendorSpecificStatusCode());
|
||||
nsp.setVendorSpecificStatusCode(1234);
|
||||
ASSERT_EQ(1234, nsp.getVendorSpecificStatusCode());
|
||||
|
||||
ASSERT_LE(0, nsp.forcePublish());
|
||||
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10));
|
||||
|
||||
ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_OK, status_sub.collector.msg->status_code);
|
||||
ASSERT_EQ(1234, status_sub.collector.msg->vendor_specific_status_code);
|
||||
ASSERT_GE(1, status_sub.collector.msg->uptime_sec);
|
||||
|
||||
/*
|
||||
|
||||
@@ -12,9 +12,9 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
typedef std::map<std::string, double> KeyValue;
|
||||
KeyValue kv;
|
||||
|
||||
virtual void getParamNameByIndex(ParamIndex index, ParamName& out_name) const
|
||||
virtual void getParamNameByIndex(Index index, Name& out_name) const
|
||||
{
|
||||
ParamIndex current_idx = 0;
|
||||
Index current_idx = 0;
|
||||
for (KeyValue::const_iterator it = kv.begin(); it != kv.end(); ++it, ++current_idx)
|
||||
{
|
||||
if (current_idx == index)
|
||||
@@ -25,8 +25,9 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
}
|
||||
}
|
||||
|
||||
virtual void assignParamValue(const ParamName& name, const ParamValue& value)
|
||||
virtual void assignParamValue(const Name& name, const Value& value)
|
||||
{
|
||||
assert(!name.empty());
|
||||
std::cout << "ASSIGN [" << name.c_str() << "]\n" << value << "\n---" << std::endl;
|
||||
KeyValue::iterator it = kv.find(name.c_str());
|
||||
if (it != kv.end())
|
||||
@@ -43,6 +44,10 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
{
|
||||
it->second = double(value.value_float[0]);
|
||||
}
|
||||
else if (!value.value_string.empty())
|
||||
{
|
||||
it->second = std::atof(value.value_string[0].value.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
@@ -50,8 +55,9 @@ struct ParamServerTestManager : public uavcan::IParamManager
|
||||
}
|
||||
}
|
||||
|
||||
virtual void readParamValue(const ParamName& name, ParamValue& out_value) const
|
||||
virtual void readParamValue(const Name& name, Value& out_value) const
|
||||
{
|
||||
assert(!name.empty());
|
||||
KeyValue::const_iterator it = kv.find(name.c_str());
|
||||
if (it != kv.end())
|
||||
{
|
||||
@@ -93,23 +99,23 @@ TEST(ParamServer, Basic)
|
||||
|
||||
uavcan::GlobalDataTypeRegistry::instance().reset();
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::GetSet> _reg1;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::SaveErase> _reg2;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::param::ExecuteOpcode> _reg2;
|
||||
|
||||
ASSERT_LE(0, server.start(&mgr));
|
||||
|
||||
ServiceClientWithCollector<uavcan::protocol::param::GetSet> get_set_cln(nodes.b);
|
||||
ServiceClientWithCollector<uavcan::protocol::param::SaveErase> save_erase_cln(nodes.b);
|
||||
ServiceClientWithCollector<uavcan::protocol::param::ExecuteOpcode> save_erase_cln(nodes.b);
|
||||
|
||||
/*
|
||||
* Save/erase
|
||||
*/
|
||||
uavcan::protocol::param::SaveErase::Request save_erase_rq;
|
||||
save_erase_rq.opcode = uavcan::protocol::param::SaveErase::Request::OPCODE_SAVE;
|
||||
uavcan::protocol::param::ExecuteOpcode::Request save_erase_rq;
|
||||
save_erase_rq.opcode = uavcan::protocol::param::ExecuteOpcode::Request::OPCODE_SAVE;
|
||||
doCall(save_erase_cln, save_erase_rq, nodes);
|
||||
ASSERT_TRUE(save_erase_cln.collector.result.get());
|
||||
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
||||
|
||||
save_erase_rq.opcode = uavcan::protocol::param::SaveErase::Request::OPCODE_ERASE;
|
||||
save_erase_rq.opcode = uavcan::protocol::param::ExecuteOpcode::Request::OPCODE_ERASE;
|
||||
doCall(save_erase_cln, save_erase_rq, nodes);
|
||||
ASSERT_TRUE(save_erase_cln.collector.result->response.ok);
|
||||
|
||||
@@ -151,7 +157,11 @@ TEST(ParamServer, Basic)
|
||||
// Set by index
|
||||
get_set_rq = uavcan::protocol::param::GetSet::Request();
|
||||
get_set_rq.index = 0;
|
||||
get_set_rq.value.value_int.push_back(424242);
|
||||
{
|
||||
uavcan::protocol::param::String str;
|
||||
str.value = "424242";
|
||||
get_set_rq.value.value_string.push_back(str);
|
||||
}
|
||||
doCall(get_set_cln, get_set_rq, nodes);
|
||||
ASSERT_STREQ("foobar", get_set_cln.collector.result->response.name.c_str());
|
||||
ASSERT_FLOAT_EQ(424242, get_set_cln.collector.result->response.value.value_float[0]);
|
||||
|
||||
Reference in New Issue
Block a user