mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-14 04:10:34 +08:00
Type safe DataTypeID class
This commit is contained in:
@@ -45,7 +45,7 @@ bool DataTypeDescriptor::match(DataTypeKind kind, const char* name) const
|
||||
return (kind_ == kind) && !std::strcmp(full_name_, name);
|
||||
}
|
||||
|
||||
bool DataTypeDescriptor::match(DataTypeKind kind, uint16_t id) const
|
||||
bool DataTypeDescriptor::match(DataTypeKind kind, DataTypeID id) const
|
||||
{
|
||||
return (kind_ == kind) && (id_ == id);
|
||||
}
|
||||
@@ -61,7 +61,8 @@ std::string DataTypeDescriptor::toString() const
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
os << full_name_ << ":" << id_ << kindch << ":" << std::hex << std::setfill('0') << std::setw(16) << signature_.get();
|
||||
os << full_name_ << ":" << id_.get() << kindch << ":" << std::hex
|
||||
<< std::setfill('0') << std::setw(16) << signature_.get();
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::remove(Entry* dtd)
|
||||
|
||||
GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* dtd)
|
||||
{
|
||||
if (!dtd || (dtd->descriptor.getID() > DataTypeDescriptor::MaxDataTypeID))
|
||||
if (!dtd || (dtd->descriptor.getID() > DataTypeID::Max))
|
||||
{
|
||||
assert(0);
|
||||
return RegistResultInvalidParams;
|
||||
@@ -93,12 +93,12 @@ GlobalDataTypeRegistry::RegistResult GlobalDataTypeRegistry::registImpl(Entry* d
|
||||
int id = -1;
|
||||
while (p)
|
||||
{
|
||||
if (id >= p->descriptor.getID())
|
||||
if (id >= p->descriptor.getID().get())
|
||||
{
|
||||
assert(0);
|
||||
std::abort();
|
||||
}
|
||||
id = p->descriptor.getID();
|
||||
id = p->descriptor.getID().get();
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
}
|
||||
@@ -158,8 +158,9 @@ DataTypeSignature GlobalDataTypeRegistry::computeAggregateSignature(DataTypeKind
|
||||
while (p)
|
||||
{
|
||||
const DataTypeDescriptor& desc = p->descriptor;
|
||||
const int dtid = desc.getID().get();
|
||||
|
||||
if (inout_id_mask[desc.getID()])
|
||||
if (inout_id_mask[dtid])
|
||||
{
|
||||
if (signature_initialized)
|
||||
signature.extend(desc.getSignature());
|
||||
@@ -168,16 +169,16 @@ DataTypeSignature GlobalDataTypeRegistry::computeAggregateSignature(DataTypeKind
|
||||
signature_initialized = true;
|
||||
}
|
||||
|
||||
assert(prev_dtid < desc.getID()); // Making sure that list is ordered properly
|
||||
assert(prev_dtid < dtid); // Making sure that list is ordered properly
|
||||
prev_dtid++;
|
||||
while (prev_dtid < desc.getID())
|
||||
while (prev_dtid < dtid)
|
||||
inout_id_mask[prev_dtid++] = false; // Erasing bits for missing types
|
||||
assert(prev_dtid == desc.getID());
|
||||
assert(prev_dtid == dtid);
|
||||
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
prev_dtid++;
|
||||
while (prev_dtid <= DataTypeDescriptor::MaxDataTypeID)
|
||||
while (prev_dtid <= DataTypeID::Max)
|
||||
inout_id_mask[prev_dtid++] = false;
|
||||
|
||||
return signature;
|
||||
@@ -196,7 +197,7 @@ void GlobalDataTypeRegistry::getDataTypeIDMask(DataTypeKind kind, DataTypeIDMask
|
||||
while (p)
|
||||
{
|
||||
assert(p->descriptor.getKind() == kind);
|
||||
mask[p->descriptor.getID()] = true;
|
||||
mask[p->descriptor.getID().get()] = true;
|
||||
p = p->getNextListNode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ bool Frame::compile(CanFrame& out_can_frame) const
|
||||
bitpack<4, 6>(frame_index_) |
|
||||
bitpack<10, 7>(src_node_id_.get()) |
|
||||
bitpack<17, 2>(transfer_type_) |
|
||||
bitpack<19, 10>(data_type_id_);
|
||||
bitpack<19, 10>(data_type_id_.get());
|
||||
|
||||
switch (transfer_type_)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ bool Frame::isValid() const
|
||||
((transfer_type_ == TransferTypeMessageBroadcast) != dst_node_id_.isBroadcast()) ||
|
||||
(transfer_type_ >= NumTransferTypes) ||
|
||||
(payload_len_ > getMaxPayloadLen()) ||
|
||||
(data_type_id_ > DataTypeDescriptor::MaxDataTypeID);
|
||||
(!data_type_id_.isValid());
|
||||
|
||||
return !invalid;
|
||||
}
|
||||
@@ -192,8 +192,8 @@ std::string Frame::toString() const
|
||||
static const int BUFLEN = 100;
|
||||
char buf[BUFLEN];
|
||||
int ofs = std::snprintf(buf, BUFLEN, "dtid=%i tt=%i snid=%i dnid=%i idx=%i last=%i tid=%i payload=[",
|
||||
int(data_type_id_), int(transfer_type_), int(src_node_id_.get()), int(dst_node_id_.get()),
|
||||
int(frame_index_), int(last_frame_), int(transfer_id_.get()));
|
||||
int(data_type_id_.get()), int(transfer_type_), int(src_node_id_.get()),
|
||||
int(dst_node_id_.get()), int(frame_index_), int(last_frame_), int(transfer_id_.get()));
|
||||
|
||||
for (int i = 0; i < payload_len_; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user