mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-19 05:10:34 +08:00
Most enums were replaced with constants, according to MISRA
This commit is contained in:
@@ -63,7 +63,7 @@ std::string CanFrame::toString(StringRepresentation mode) const
|
||||
|
||||
assert(mode == StrTight || mode == StrAligned);
|
||||
|
||||
static const int ASCII_COLUMN_OFFSET = 36;
|
||||
static const unsigned AsciiColumnOffset = 36U;
|
||||
|
||||
char buf[50];
|
||||
char* wpos = buf;
|
||||
@@ -96,7 +96,7 @@ std::string CanFrame::toString(StringRepresentation mode) const
|
||||
wpos += snprintf(wpos, epos - wpos, " %02x", unsigned(data[dlen]));
|
||||
}
|
||||
|
||||
while (mode == StrAligned && wpos < buf + ASCII_COLUMN_OFFSET) // alignment
|
||||
while ((mode == StrAligned) && (wpos < buf + AsciiColumnOffset)) // alignment
|
||||
{
|
||||
*wpos++ = ' ';
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
const unsigned BitStream::MaxBytesPerRW;
|
||||
const unsigned BitStream::MaxBitsPerRW;
|
||||
|
||||
int BitStream::write(const uint8_t* bytes, const int bitlen)
|
||||
{
|
||||
// Temporary buffer is needed to merge new bits with cached unaligned bits from the last write() (see byte_cache_)
|
||||
uint8_t tmp[MaxBytesPerRW + 1];
|
||||
|
||||
// Tmp space must be large enough to accomodate new bits AND unaligned bits from the last write()
|
||||
const int bytelen = bitlenToBytelen(bitlen + (bit_offset_ % 8));
|
||||
const unsigned bytelen = bitlenToBytelen(bitlen + (bit_offset_ % 8));
|
||||
assert(MaxBytesPerRW >= bytelen);
|
||||
tmp[0] = tmp[bytelen - 1] = 0;
|
||||
|
||||
@@ -40,7 +43,7 @@ int BitStream::write(const uint8_t* bytes, const int bitlen)
|
||||
{
|
||||
return write_res;
|
||||
}
|
||||
if (write_res < bytelen)
|
||||
if (static_cast<unsigned>(write_res) < bytelen)
|
||||
{
|
||||
return ResultOutOfBuffer;
|
||||
}
|
||||
@@ -53,7 +56,7 @@ int BitStream::read(uint8_t* bytes, const int bitlen)
|
||||
{
|
||||
uint8_t tmp[MaxBytesPerRW + 1];
|
||||
|
||||
const int bytelen = bitlenToBytelen(bitlen + (bit_offset_ % 8));
|
||||
const unsigned bytelen = bitlenToBytelen(bitlen + (bit_offset_ % 8));
|
||||
assert(MaxBytesPerRW >= bytelen);
|
||||
|
||||
const int read_res = buf_.read(bit_offset_ / 8, tmp, bytelen);
|
||||
@@ -61,7 +64,7 @@ int BitStream::read(uint8_t* bytes, const int bitlen)
|
||||
{
|
||||
return read_res;
|
||||
}
|
||||
if (read_res < bytelen)
|
||||
if (static_cast<unsigned>(read_res) < bytelen)
|
||||
{
|
||||
return ResultOutOfBuffer;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
const unsigned NodeStatusMonitor::TimerPeriodMs100;
|
||||
|
||||
NodeStatusMonitor::Entry& NodeStatusMonitor::getEntry(NodeID node_id) const
|
||||
{
|
||||
if (node_id.get() < 1 || node_id.get() > NodeID::Max)
|
||||
@@ -55,7 +57,7 @@ void NodeStatusMonitor::handleNodeStatus(const ReceivedDataStructure<protocol::N
|
||||
|
||||
void NodeStatusMonitor::handleTimerEvent(const TimerEvent&)
|
||||
{
|
||||
enum { OfflineTimeoutMs100 = protocol::NodeStatus::OFFLINE_TIMEOUT_MS / 100 };
|
||||
const int OfflineTimeoutMs100 = protocol::NodeStatus::OFFLINE_TIMEOUT_MS / 100;
|
||||
|
||||
for (int i = 1; i <= NodeID::Max; i++)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,19 @@
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
/**
|
||||
* TransferID
|
||||
*/
|
||||
const uint8_t TransferID::BitLen;
|
||||
const uint8_t TransferID::Max;
|
||||
|
||||
/**
|
||||
* NodeID
|
||||
*/
|
||||
const uint8_t NodeID::ValueBroadcast;
|
||||
const uint8_t NodeID::ValueInvalid;
|
||||
const uint8_t NodeID::BitLen;
|
||||
const uint8_t NodeID::Max;
|
||||
const NodeID NodeID::Broadcast(ValueBroadcast);
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace uavcan
|
||||
const uint32_t TransferReceiver::MinTransferIntervalUSec;
|
||||
const uint32_t TransferReceiver::MaxTransferIntervalUSec;
|
||||
const uint32_t TransferReceiver::DefaultTransferIntervalUSec;
|
||||
const uint8_t TransferReceiver::IfaceIndexNotSet;
|
||||
|
||||
void TransferReceiver::registerError() const
|
||||
{
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
/*
|
||||
* DataTypeID
|
||||
*/
|
||||
const uint16_t DataTypeID::Max;
|
||||
|
||||
/*
|
||||
* DataTypeSignatureCRC
|
||||
*/
|
||||
@@ -71,6 +76,8 @@ TransferCRC DataTypeSignature::toTransferCRC() const
|
||||
/*
|
||||
* DataTypeDescriptor
|
||||
*/
|
||||
const unsigned DataTypeDescriptor::MaxFullNameLen;
|
||||
|
||||
bool DataTypeDescriptor::match(DataTypeKind kind, const char* name) const
|
||||
{
|
||||
return (kind_ == kind) && !std::strcmp(full_name_, name);
|
||||
|
||||
Reference in New Issue
Block a user