mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-17 14:10:34 +08:00
GDTR collision checks, ordered storage
This commit is contained in:
@@ -30,6 +30,17 @@ class GlobalDataTypeRegistry : Noncopyable
|
||||
{ }
|
||||
};
|
||||
|
||||
struct EntryInsertionComparator
|
||||
{
|
||||
const uint16_t id;
|
||||
EntryInsertionComparator(Entry* dtd) : id(dtd->decriptor.getID()) { }
|
||||
bool operator()(const Entry* entry) const
|
||||
{
|
||||
assert(entry);
|
||||
return entry->decriptor.getID() > id;
|
||||
}
|
||||
};
|
||||
|
||||
typedef LinkedListRoot<Entry> List;
|
||||
List msgs_;
|
||||
List srvs_;
|
||||
|
||||
@@ -63,7 +63,33 @@ bool GlobalDataTypeRegistry::add(Entry* dtd)
|
||||
if (!list)
|
||||
return false;
|
||||
|
||||
list->insert(dtd);
|
||||
{ // Collision check
|
||||
Entry* p = list->get();
|
||||
while (p)
|
||||
{
|
||||
if (p->decriptor.getID() == dtd->decriptor.getID()) // ID collision
|
||||
return false;
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
}
|
||||
list->insertBefore(dtd, EntryInsertionComparator(dtd));
|
||||
|
||||
#if UAVCAN_DEBUG
|
||||
{ // Order check
|
||||
Entry* p = list->get();
|
||||
int id = -1;
|
||||
while (p)
|
||||
{
|
||||
if (id >= p->decriptor.getID())
|
||||
{
|
||||
assert(0);
|
||||
std::abort();
|
||||
}
|
||||
id = p->decriptor.getID();
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ TEST(GlobalDataTypeRegistry, Basic)
|
||||
/*
|
||||
* These types will be necessary for the aggregate signature test
|
||||
*/
|
||||
ASSERT_FALSE(GlobalDataTypeRegistry::instance().assign<DataTypeC>(741)); // COLLISION - error
|
||||
ASSERT_TRUE(GlobalDataTypeRegistry::instance().assign<DataTypeC>(DataTypeC::DefaultDataTypeID));
|
||||
uavcan::DefaultDataTypeRegistrator<DataTypeD> reg_DataTypeD;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user