mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-17 06:10:35 +08:00
Strict sign conversions
This commit is contained in:
@@ -101,8 +101,8 @@ if (DEBUG_BUILD)
|
||||
message(STATUS "Debug build (note: requires gtest)")
|
||||
|
||||
if (COMPILER_IS_GCC_COMPATIBLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wfloat-equal -Wconversion")
|
||||
set(exec_common_flags "-Wno-conversion -Wno-float-equal")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wfloat-equal -Wconversion -Wsign-conversion")
|
||||
set(exec_common_flags "-Wno-conversion -Wno-float-equal -Wno-sign-conversion")
|
||||
set(cpp03_flags "-std=c++03 -Wno-variadic-macros -Wno-long-long")
|
||||
set(optim_flags "-O3 -DNDEBUG -g0")
|
||||
else ()
|
||||
|
||||
@@ -540,16 +540,16 @@ public:
|
||||
{
|
||||
if (new_size > size())
|
||||
{
|
||||
unsigned cnt = new_size - size();
|
||||
while (cnt--)
|
||||
SizeType cnt = SizeType(new_size - size());
|
||||
while (cnt-- > 0)
|
||||
{
|
||||
push_back(filler);
|
||||
}
|
||||
}
|
||||
else if (new_size < size())
|
||||
{
|
||||
unsigned cnt = size() - new_size;
|
||||
while (cnt--)
|
||||
SizeType cnt = SizeType(size() - new_size);
|
||||
while (cnt-- > 0)
|
||||
{
|
||||
pop_back();
|
||||
}
|
||||
@@ -623,7 +623,7 @@ public:
|
||||
}
|
||||
while (*ch)
|
||||
{
|
||||
push_back(*ch++);
|
||||
push_back(ValueType(*ch++)); // Value type is likely to be unsigned char, so conversion may be required.
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -642,7 +642,7 @@ public:
|
||||
}
|
||||
while (*ch)
|
||||
{
|
||||
push_back(*ch++);
|
||||
push_back(ValueType(*ch++));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset);
|
||||
void bitarrayCopy(const unsigned char* src_org, unsigned src_offset, unsigned src_len,
|
||||
unsigned char* dst_org, unsigned dst_offset);
|
||||
|
||||
/**
|
||||
* This class treats a chunk of memory as an array of bits.
|
||||
@@ -24,13 +25,13 @@ class UAVCAN_EXPORT BitStream
|
||||
static const unsigned MaxBytesPerRW = 16;
|
||||
|
||||
ITransferBuffer& buf_;
|
||||
int bit_offset_;
|
||||
unsigned bit_offset_;
|
||||
uint8_t byte_cache_;
|
||||
|
||||
static inline unsigned bitlenToBytelen(unsigned bits) { return (bits + 7) / 8; }
|
||||
|
||||
static inline void copyBitArray(const uint8_t* src_org, int src_offset, int src_len,
|
||||
uint8_t* dst_org, int dst_offset)
|
||||
static inline void copyBitArray(const uint8_t* src_org, unsigned src_offset, unsigned src_len,
|
||||
uint8_t* dst_org, unsigned dst_offset)
|
||||
{
|
||||
bitarrayCopy(reinterpret_cast<const unsigned char*>(src_org), src_offset, src_len,
|
||||
reinterpret_cast<unsigned char*>(dst_org), dst_offset);
|
||||
@@ -64,8 +65,8 @@ public:
|
||||
* Zero - Out of buffer space
|
||||
* Positive - OK
|
||||
*/
|
||||
int write(const uint8_t* bytes, const int bitlen);
|
||||
int read(uint8_t* bytes, const int bitlen);
|
||||
int write(const uint8_t* bytes, const unsigned bitlen);
|
||||
int read(uint8_t* bytes, const unsigned bitlen);
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
|
||||
@@ -86,7 +86,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
static void truncate(StorageType& value) { value &= mask(); }
|
||||
static void truncate(StorageType& value) { value = value & StorageType(mask()); }
|
||||
|
||||
static void validate()
|
||||
{
|
||||
|
||||
@@ -140,12 +140,12 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uint64_t(usec_ + r.toUSec()) < usec_)
|
||||
if (uint64_t(int64_t(usec_) + r.toUSec()) < usec_)
|
||||
{
|
||||
return fromUSec(NumericTraits<uint64_t>::max());
|
||||
}
|
||||
}
|
||||
return fromUSec(usec_ + r.toUSec());
|
||||
return fromUSec(uint64_t(int64_t(usec_) + r.toUSec()));
|
||||
}
|
||||
|
||||
T operator-(const D& r) const
|
||||
@@ -154,7 +154,7 @@ public:
|
||||
}
|
||||
D operator-(const T& r) const
|
||||
{
|
||||
return D::fromUSec((usec_ > r.usec_) ? (usec_ - r.usec_) : -(r.usec_ - usec_));
|
||||
return D::fromUSec((usec_ > r.usec_) ? int64_t(usec_ - r.usec_) : -int64_t(r.usec_ - usec_));
|
||||
}
|
||||
|
||||
T& operator+=(const D& r)
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
#else
|
||||
void add(uint8_t byte)
|
||||
{
|
||||
value_ = ((value_ << 8) ^ Table[((value_ >> 8) ^ byte) & 0xFFU]) & 0xFFFFU;
|
||||
value_ = uint16_t(uint16_t((value_ << 8) ^ Table[uint16_t((value_ >> 8) ^ byte) & 0xFFU]) & 0xFFFFU);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ class UAVCAN_EXPORT Dispatcher : Noncopyable
|
||||
void cleanup(MonotonicTime ts);
|
||||
void handleFrame(const RxFrame& frame);
|
||||
|
||||
int getNumEntries() const { return list_.getLength(); }
|
||||
unsigned getNumEntries() const { return list_.getLength(); }
|
||||
};
|
||||
|
||||
ListenerRegistry lmsg_;
|
||||
@@ -137,9 +137,9 @@ public:
|
||||
bool hasPublisher(DataTypeID dtid) const;
|
||||
bool hasServer(DataTypeID dtid) const;
|
||||
|
||||
int getNumMessageListeners() const { return lmsg_.getNumEntries(); }
|
||||
int getNumServiceRequestListeners() const { return lsrv_req_.getNumEntries(); }
|
||||
int getNumServiceResponseListeners() const { return lsrv_resp_.getNumEntries(); }
|
||||
unsigned getNumMessageListeners() const { return lmsg_.getNumEntries(); }
|
||||
unsigned getNumServiceRequestListeners() const { return lsrv_req_.getNumEntries(); }
|
||||
unsigned getNumServiceResponseListeners() const { return lsrv_resp_.getNumEntries(); }
|
||||
|
||||
IOutgoingTransferRegistry& getOutgoingTransferRegistry() { return outgoing_transfer_reg_; }
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
* Send with explicit Transfer ID.
|
||||
* Should be used only for service responses, where response TID should match request TID.
|
||||
*/
|
||||
int send(const uint8_t* payload, int payload_len, MonotonicTime tx_deadline,
|
||||
int send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
||||
TransferID tid);
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
* Send with automatic Transfer ID.
|
||||
* TID is managed by OutgoingTransferRegistry.
|
||||
*/
|
||||
int send(const uint8_t* payload, int payload_len, MonotonicTime tx_deadline,
|
||||
int send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id);
|
||||
};
|
||||
|
||||
|
||||
@@ -68,39 +68,39 @@ std::string CanFrame::toString(StringRepresentation mode) const
|
||||
char buf[50];
|
||||
char* wpos = buf;
|
||||
char* const epos = buf + sizeof(buf);
|
||||
fill(buf, buf + sizeof(buf), uint8_t(0));
|
||||
fill(buf, buf + sizeof(buf), '\0');
|
||||
|
||||
if (id & FlagEFF)
|
||||
{
|
||||
wpos += snprintf(wpos, epos - wpos, "0x%08x ", unsigned(id & MaskExtID));
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), "0x%08x ", unsigned(id & MaskExtID));
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* const fmt = (mode == StrAligned) ? " 0x%03x " : "0x%03x ";
|
||||
wpos += snprintf(wpos, epos - wpos, fmt, unsigned(id & MaskStdID));
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), fmt, unsigned(id & MaskStdID));
|
||||
}
|
||||
|
||||
if (id & FlagRTR)
|
||||
{
|
||||
wpos += snprintf(wpos, epos - wpos, " RTR");
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), " RTR");
|
||||
}
|
||||
else if (id & FlagERR)
|
||||
{
|
||||
wpos += snprintf(wpos, epos - wpos, " ERR");
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), " ERR");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int dlen = 0; dlen < dlc; dlen++) // hex bytes
|
||||
{
|
||||
wpos += snprintf(wpos, epos - wpos, " %02x", unsigned(data[dlen]));
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), " %02x", unsigned(data[dlen]));
|
||||
}
|
||||
|
||||
while ((mode == StrAligned) && (wpos < buf + AsciiColumnOffset)) // alignment
|
||||
while ((mode == StrAligned) && (wpos < buf + AsciiColumnOffset)) // alignment
|
||||
{
|
||||
*wpos++ = ' ';
|
||||
}
|
||||
|
||||
wpos += snprintf(wpos, epos - wpos, " \'"); // ascii
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), " \'"); // ascii
|
||||
for (int dlen = 0; dlen < dlc; dlen++)
|
||||
{
|
||||
uint8_t ch = data[dlen];
|
||||
@@ -108,9 +108,9 @@ std::string CanFrame::toString(StringRepresentation mode) const
|
||||
{
|
||||
ch = '.';
|
||||
}
|
||||
wpos += snprintf(wpos, epos - wpos, "%c", ch);
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), "%c", ch);
|
||||
}
|
||||
wpos += snprintf(wpos, epos - wpos, "\'");
|
||||
wpos += snprintf(wpos, unsigned(epos - wpos), "\'");
|
||||
}
|
||||
(void)wpos;
|
||||
return std::string(buf);
|
||||
|
||||
@@ -22,45 +22,39 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, unsigned char* dst_org, int dst_offset)
|
||||
void bitarrayCopy(const unsigned char* src_org, unsigned src_offset, unsigned src_len,
|
||||
unsigned char* dst_org, unsigned dst_offset)
|
||||
{
|
||||
static const unsigned char reverse_mask[] = { 0x55U, 0x80U, 0xC0U, 0xE0U, 0xF0U, 0xF8U, 0xFCU, 0xFEU, 0xFFU };
|
||||
static const unsigned char reverse_mask_xor[] = { 0xFFU, 0x7FU, 0x3FU, 0x1FU, 0x0FU, 0x07U, 0x03U, 0x01U, 0x00U };
|
||||
|
||||
if (src_len > 0)
|
||||
if (src_len > 0U)
|
||||
{
|
||||
const unsigned char* src;
|
||||
unsigned char* dst;
|
||||
int src_offset_modulo;
|
||||
int dst_offset_modulo;
|
||||
const unsigned char *src = src_org + (src_offset / CHAR_BIT);
|
||||
unsigned char *dst = dst_org + (dst_offset / CHAR_BIT);
|
||||
|
||||
src = src_org + (src_offset / CHAR_BIT);
|
||||
dst = dst_org + (dst_offset / CHAR_BIT);
|
||||
|
||||
src_offset_modulo = src_offset % CHAR_BIT;
|
||||
dst_offset_modulo = dst_offset % CHAR_BIT;
|
||||
const unsigned src_offset_modulo = src_offset % CHAR_BIT;
|
||||
const unsigned dst_offset_modulo = dst_offset % CHAR_BIT;
|
||||
|
||||
if (src_offset_modulo == dst_offset_modulo)
|
||||
{
|
||||
int byte_len;
|
||||
int src_len_modulo;
|
||||
if (src_offset_modulo)
|
||||
if (src_offset_modulo > 0U)
|
||||
{
|
||||
unsigned char c = reverse_mask_xor[dst_offset_modulo] & *src++;
|
||||
PREPARE_FIRST_COPY();
|
||||
*dst++ |= c;
|
||||
}
|
||||
|
||||
byte_len = src_len / CHAR_BIT;
|
||||
src_len_modulo = src_len % CHAR_BIT;
|
||||
const unsigned byte_len = src_len / CHAR_BIT;
|
||||
const unsigned src_len_modulo = src_len % CHAR_BIT;
|
||||
|
||||
if (byte_len)
|
||||
if (byte_len > 0U)
|
||||
{
|
||||
(void)std::memcpy(dst, src, byte_len);
|
||||
src += byte_len;
|
||||
dst += byte_len;
|
||||
}
|
||||
if (src_len_modulo)
|
||||
if (src_len_modulo > 0U)
|
||||
{
|
||||
*dst &= reverse_mask_xor[src_len_modulo];
|
||||
*dst |= reverse_mask[src_len_modulo] & *src;
|
||||
@@ -68,11 +62,9 @@ void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, uns
|
||||
}
|
||||
else
|
||||
{
|
||||
int bit_diff_ls;
|
||||
int bit_diff_rs;
|
||||
int byte_len;
|
||||
int src_len_modulo;
|
||||
unsigned char c;
|
||||
unsigned bit_diff_ls = 0U;
|
||||
unsigned bit_diff_rs = 0U;
|
||||
unsigned char c = 0U;
|
||||
/*
|
||||
* Begin: Line things up on destination.
|
||||
*/
|
||||
@@ -98,7 +90,7 @@ void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, uns
|
||||
/*
|
||||
* Middle: copy with only shifting the source.
|
||||
*/
|
||||
byte_len = src_len / CHAR_BIT;
|
||||
int byte_len = int(src_len / CHAR_BIT);
|
||||
|
||||
while (--byte_len >= 0)
|
||||
{
|
||||
@@ -110,8 +102,8 @@ void bitarrayCopy(const unsigned char* src_org, int src_offset, int src_len, uns
|
||||
/*
|
||||
* End: copy the remaing bits;
|
||||
*/
|
||||
src_len_modulo = src_len % CHAR_BIT;
|
||||
if (src_len_modulo)
|
||||
unsigned src_len_modulo = src_len % CHAR_BIT;
|
||||
if (src_len_modulo > 0U)
|
||||
{
|
||||
c = static_cast<unsigned char>(*src++ << bit_diff_ls);
|
||||
c = static_cast<unsigned char>(c | (*src >> bit_diff_rs));
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace uavcan
|
||||
const unsigned BitStream::MaxBytesPerRW;
|
||||
const unsigned BitStream::MaxBitsPerRW;
|
||||
|
||||
int BitStream::write(const uint8_t* bytes, const int bitlen)
|
||||
int BitStream::write(const uint8_t* bytes, const unsigned 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];
|
||||
@@ -25,7 +25,7 @@ int BitStream::write(const uint8_t* bytes, const int bitlen)
|
||||
fill(tmp, tmp + bytelen, uint8_t(0));
|
||||
copyBitArray(bytes, 0, bitlen, tmp, bit_offset_ % 8);
|
||||
|
||||
const int new_bit_offset = bit_offset_ + bitlen;
|
||||
const unsigned new_bit_offset = bit_offset_ + bitlen;
|
||||
|
||||
// Bitcopy algorithm resets skipped bits in the first byte. Restore them back.
|
||||
tmp[0] |= byte_cache_;
|
||||
@@ -52,7 +52,7 @@ int BitStream::write(const uint8_t* bytes, const int bitlen)
|
||||
return ResultOk;
|
||||
}
|
||||
|
||||
int BitStream::read(uint8_t* bytes, const int bitlen)
|
||||
int BitStream::read(uint8_t* bytes, const unsigned bitlen)
|
||||
{
|
||||
uint8_t tmp[MaxBytesPerRW + 1];
|
||||
|
||||
@@ -81,10 +81,10 @@ std::string BitStream::toString() const
|
||||
std::string out;
|
||||
out.reserve(128);
|
||||
|
||||
for (int offset = 0; true; offset++)
|
||||
for (unsigned offset = 0; true; offset++)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
if (1 != buf_.read(offset, &byte, 1))
|
||||
if (1U != buf_.read(offset, &byte, 1U))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ uint16_t IEEE754Converter::nativeNonIeeeToHalf(float value)
|
||||
hbits |= uint16_t((exp + 14) << 10);
|
||||
}
|
||||
const int32_t ival = static_cast<int32_t>(value);
|
||||
hbits = uint16_t(hbits | (((ival < 0) ? (-ival) : ival) & 0x3FFU));
|
||||
hbits = uint16_t(hbits | (uint32_t((ival < 0) ? (-ival) : ival) & 0x3FFU));
|
||||
float diff = std::fabs(value - static_cast<float>(ival));
|
||||
hbits = uint16_t(hbits + (diff >= 0.5F));
|
||||
return hbits;
|
||||
@@ -80,7 +80,7 @@ float IEEE754Converter::halfToNativeNonIeee(uint16_t value)
|
||||
}
|
||||
else if (abs > 0x3FFU)
|
||||
{
|
||||
out = std::ldexp(static_cast<float>((value & 0x3FFU) | 0x400U), (abs >> 10) - 25);
|
||||
out = std::ldexp(static_cast<float>((value & 0x3FFU) | 0x400U), int(abs >> 10) - 25);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace uavcan
|
||||
void ScalarCodec::swapByteOrder(uint8_t* const bytes, const unsigned len)
|
||||
{
|
||||
UAVCAN_ASSERT(bytes);
|
||||
for (int i = 0, j = len - 1; i < j; i++, j--)
|
||||
for (unsigned i = 0, j = len - 1; i < j; i++, j--)
|
||||
{
|
||||
const uint8_t c = bytes[i];
|
||||
bytes[i] = bytes[j];
|
||||
|
||||
@@ -207,7 +207,7 @@ DataTypeSignature GlobalDataTypeRegistry::computeAggregateSignature(DataTypeKind
|
||||
const DataTypeDescriptor& desc = p->descriptor;
|
||||
const int dtid = desc.getID().get();
|
||||
|
||||
if (inout_id_mask[dtid])
|
||||
if (inout_id_mask[unsigned(dtid)])
|
||||
{
|
||||
if (signature_initialized)
|
||||
{
|
||||
@@ -224,7 +224,7 @@ DataTypeSignature GlobalDataTypeRegistry::computeAggregateSignature(DataTypeKind
|
||||
prev_dtid++;
|
||||
while (prev_dtid < dtid)
|
||||
{
|
||||
inout_id_mask[prev_dtid++] = false; // Erasing bits for missing types
|
||||
inout_id_mask[unsigned(prev_dtid++)] = false; // Erasing bits for missing types
|
||||
}
|
||||
UAVCAN_ASSERT(prev_dtid == dtid);
|
||||
|
||||
@@ -233,7 +233,7 @@ DataTypeSignature GlobalDataTypeRegistry::computeAggregateSignature(DataTypeKind
|
||||
prev_dtid++;
|
||||
while (prev_dtid <= DataTypeID::Max)
|
||||
{
|
||||
inout_id_mask[prev_dtid++] = false;
|
||||
inout_id_mask[unsigned(prev_dtid++)] = false;
|
||||
}
|
||||
|
||||
return signature;
|
||||
|
||||
@@ -172,7 +172,7 @@ int Scheduler::spin(MonotonicTime deadline)
|
||||
}
|
||||
|
||||
const MonotonicTime ts = deadline_scheduler_.pollAndGetMonotonicTime(getSystemClock());
|
||||
pollCleanup(ts, retval);
|
||||
pollCleanup(ts, unsigned(retval));
|
||||
if (ts >= deadline)
|
||||
{
|
||||
break;
|
||||
|
||||
@@ -66,7 +66,7 @@ void NodeStatusMonitor::handleTimerEvent(const TimerEvent&)
|
||||
if (entry.time_since_last_update_ms100 >= 0 &&
|
||||
entry.status_code != protocol::NodeStatus::STATUS_OFFLINE)
|
||||
{
|
||||
entry.time_since_last_update_ms100 = int8_t(entry.time_since_last_update_ms100 + TimerPeriodMs100);
|
||||
entry.time_since_last_update_ms100 = int8_t(entry.time_since_last_update_ms100 + int8_t(TimerPeriodMs100));
|
||||
if (entry.time_since_last_update_ms100 >= OfflineTimeoutMs100)
|
||||
{
|
||||
Entry new_entry_value;
|
||||
|
||||
@@ -32,7 +32,7 @@ void PanicBroadcaster::panic(const char* short_reason)
|
||||
{
|
||||
break;
|
||||
}
|
||||
msg_.reason_text.push_back(*p);
|
||||
msg_.reason_text.push_back(protocol::Panic::FieldTypes::reason_text::ValueType(*p));
|
||||
p++;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ int CanIOManager::sendToIface(uint8_t iface_index, const CanFrame& frame, Monoto
|
||||
}
|
||||
if (res > 0)
|
||||
{
|
||||
counters_[iface_index].frames_tx += res;
|
||||
counters_[iface_index].frames_tx += unsigned(res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ CanIOManager::CanIOManager(ICanDriver& driver, IPoolAllocator& allocator, ISyste
|
||||
|
||||
if (mem_blocks_per_iface == 0)
|
||||
{
|
||||
mem_blocks_per_iface = allocator.getNumBlocks() / (num_ifaces_ + 1) + 1;
|
||||
mem_blocks_per_iface = allocator.getNumBlocks() / (num_ifaces_ + 1U) + 1U;
|
||||
}
|
||||
UAVCAN_TRACE("CanIOManager", "Memory blocks per iface: %u, total: %u",
|
||||
unsigned(mem_blocks_per_iface), unsigned(allocator.getNumBlocks()));
|
||||
|
||||
@@ -43,7 +43,7 @@ int Frame::setPayload(const uint8_t* data, unsigned len)
|
||||
len = min(unsigned(maxlen), len);
|
||||
(void)copy(data, data + len, payload_);
|
||||
payload_len_ = uint_fast8_t(len);
|
||||
return len;
|
||||
return int(len);
|
||||
}
|
||||
|
||||
template <int OFFSET, int WIDTH>
|
||||
@@ -216,13 +216,13 @@ std::string Frame::toString() const
|
||||
|
||||
for (unsigned i = 0; i < payload_len_; i++)
|
||||
{
|
||||
ofs += snprintf(buf + ofs, BUFLEN - ofs, "%02x", payload_[i]);
|
||||
ofs += snprintf(buf + ofs, unsigned(BUFLEN - ofs), "%02x", payload_[i]);
|
||||
if ((i + 1) < payload_len_)
|
||||
{
|
||||
ofs += snprintf(buf + ofs, BUFLEN - ofs, " ");
|
||||
ofs += snprintf(buf + ofs, unsigned(BUFLEN - ofs), " ");
|
||||
}
|
||||
}
|
||||
(void)snprintf(buf + ofs, BUFLEN - ofs, "]");
|
||||
(void)snprintf(buf + ofs, unsigned(BUFLEN - ofs), "]");
|
||||
return std::string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -147,7 +147,7 @@ int DynamicTransferBufferManagerEntry::read(unsigned offset, uint8_t* data, unsi
|
||||
}
|
||||
|
||||
UAVCAN_ASSERT(left_to_read == 0);
|
||||
return len;
|
||||
return int(len);
|
||||
}
|
||||
|
||||
int DynamicTransferBufferManagerEntry::write(unsigned offset, const uint8_t* data, unsigned len)
|
||||
@@ -215,9 +215,10 @@ int DynamicTransferBufferManagerEntry::write(unsigned offset, const uint8_t* dat
|
||||
new_block->write(inptr, offset, total_offset, left_to_write);
|
||||
}
|
||||
|
||||
const int actually_written = len - left_to_write;
|
||||
UAVCAN_ASSERT(len >= left_to_write);
|
||||
const unsigned actually_written = len - left_to_write;
|
||||
max_write_pos_ = max(uint16_t(offset + actually_written), uint16_t(max_write_pos_));
|
||||
return actually_written;
|
||||
return int(actually_written);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -240,7 +241,7 @@ int StaticTransferBufferImpl::read(unsigned offset, uint8_t* data, unsigned len)
|
||||
}
|
||||
UAVCAN_ASSERT((offset + len) <= max_write_pos_);
|
||||
(void)copy(data_ + offset, data_ + offset + len, data);
|
||||
return len;
|
||||
return int(len);
|
||||
}
|
||||
|
||||
int StaticTransferBufferImpl::write(unsigned offset, const uint8_t* data, unsigned len)
|
||||
@@ -261,7 +262,7 @@ int StaticTransferBufferImpl::write(unsigned offset, const uint8_t* data, unsign
|
||||
UAVCAN_ASSERT((offset + len) <= size_);
|
||||
(void)copy(data, data + len, data_ + offset);
|
||||
max_write_pos_ = max(uint16_t(offset + len), uint16_t(max_write_pos_));
|
||||
return len;
|
||||
return int(len);
|
||||
}
|
||||
|
||||
void StaticTransferBufferImpl::reset()
|
||||
|
||||
@@ -47,7 +47,7 @@ int SingleFrameIncomingTransfer::read(unsigned offset, uint8_t* data, unsigned l
|
||||
}
|
||||
UAVCAN_ASSERT((offset + len) <= payload_len_);
|
||||
(void)copy(payload_ + offset, payload_ + offset + len, data);
|
||||
return len;
|
||||
return int(len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -115,8 +115,8 @@ bool TransferListenerBase::checkPayloadCrc(const uint16_t compare_with, const IT
|
||||
{
|
||||
break;
|
||||
}
|
||||
offset += res;
|
||||
crc.add(buf, res);
|
||||
offset += unsigned(res);
|
||||
crc.add(buf, unsigned(res));
|
||||
}
|
||||
if (crc.get() != compare_with)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ void TransferReceiver::updateTransferTimings()
|
||||
|
||||
if ((!prev_prev_ts.isZero()) && (!prev_transfer_ts_.isZero()) && (prev_transfer_ts_ >= prev_prev_ts))
|
||||
{
|
||||
uint64_t interval_usec = (prev_transfer_ts_ - prev_prev_ts).toUSec();
|
||||
uint64_t interval_usec = uint64_t((prev_transfer_ts_ - prev_prev_ts).toUSec());
|
||||
interval_usec = min(interval_usec, uint64_t(MaxTransferIntervalUSec));
|
||||
interval_usec = max(interval_usec, uint64_t(MinTransferIntervalUSec));
|
||||
transfer_interval_usec_ = static_cast<uint32_t>((uint64_t(transfer_interval_usec_) * 7 + interval_usec) / 8);
|
||||
|
||||
@@ -15,7 +15,7 @@ void TransferSender::registerError()
|
||||
dispatcher_.getTransferPerfCounter().addError();
|
||||
}
|
||||
|
||||
int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime tx_deadline,
|
||||
int TransferSender::send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
||||
TransferID tid)
|
||||
{
|
||||
@@ -28,10 +28,10 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
|
||||
Frame frame(data_type_.getID(), transfer_type, dispatcher_.getNodeID(), dst_node_id, 0, tid);
|
||||
|
||||
if (frame.getMaxPayloadLen() >= payload_len) // Single Frame Transfer
|
||||
if (frame.getMaxPayloadLen() >= int(payload_len)) // Single Frame Transfer
|
||||
{
|
||||
const int res = frame.setPayload(payload, payload_len);
|
||||
if (res != payload_len)
|
||||
if (res != int(payload_len))
|
||||
{
|
||||
UAVCAN_ASSERT(0);
|
||||
UAVCAN_TRACE("TransferSender", "Frame payload write failure, %i", res);
|
||||
@@ -64,7 +64,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
return write_res;
|
||||
}
|
||||
offset = write_res - 2;
|
||||
UAVCAN_ASSERT(payload_len > offset);
|
||||
UAVCAN_ASSERT(int(payload_len) > offset);
|
||||
}
|
||||
|
||||
int next_frame_index = 1;
|
||||
@@ -84,7 +84,8 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
}
|
||||
frame.setIndex(next_frame_index++);
|
||||
|
||||
const int write_res = frame.setPayload(payload + offset, payload_len - offset);
|
||||
UAVCAN_ASSERT(offset >= 0);
|
||||
const int write_res = frame.setPayload(payload + offset, payload_len - unsigned(offset));
|
||||
if (write_res < 0)
|
||||
{
|
||||
UAVCAN_TRACE("TransferSender", "Frame payload write failure, %i", write_res);
|
||||
@@ -93,8 +94,8 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
}
|
||||
|
||||
offset += write_res;
|
||||
UAVCAN_ASSERT(offset <= payload_len);
|
||||
if (offset >= payload_len)
|
||||
UAVCAN_ASSERT(offset <= int(payload_len));
|
||||
if (offset >= int(payload_len))
|
||||
{
|
||||
frame.makeLast();
|
||||
}
|
||||
@@ -105,7 +106,7 @@ int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime
|
||||
return -ErrLogic; // Return path analysis is apparently broken. There should be no warning, this 'return' is unreachable.
|
||||
}
|
||||
|
||||
int TransferSender::send(const uint8_t* payload, int payload_len, MonotonicTime tx_deadline,
|
||||
int TransferSender::send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id)
|
||||
{
|
||||
const OutgoingTransferRegistryKey otr_key(data_type_.getID(), transfer_type, dst_node_id);
|
||||
|
||||
Reference in New Issue
Block a user