Fixed type signedness through the entire codebase; driver interfaces do not use starndard types now

This commit is contained in:
Pavel Kirienko
2014-03-29 22:40:15 +04:00
parent bdec81bbfa
commit 74ecfe0cc8
43 changed files with 209 additions and 210 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ public:
}
}
void add(const uint8_t* bytes, unsigned int len)
void add(const uint8_t* bytes, unsigned len)
{
assert(bytes);
while (len--)
+9 -9
View File
@@ -37,7 +37,7 @@ struct CanFrame
std::fill(data, data + sizeof(data), 0);
}
CanFrame(uint32_t id, const uint8_t* data, unsigned int dlc)
CanFrame(uint32_t id, const uint8_t* data, uint8_t dlc)
: id(id)
, dlc(dlc)
{
@@ -113,7 +113,7 @@ public:
* If the frame wasn't transmitted upon TX deadline, the driver should discard it.
* @return 1 = one frame transmitted, 0 = TX buffer full, negative for error.
*/
virtual int send(const CanFrame& frame, MonotonicTime tx_deadline, CanIOFlags flags) = 0;
virtual int16_t send(const CanFrame& frame, MonotonicTime tx_deadline, CanIOFlags flags) = 0;
/**
* Non-blocking reception.
@@ -127,19 +127,19 @@ public:
* @param [out] out_ts_utc UTC timestamp, optional, zero if unknown.
* @return 1 = one frame received, 0 = RX buffer empty, negative for error.
*/
virtual int receive(CanFrame& out_frame, MonotonicTime& out_ts_monotonic, UtcTime& out_ts_utc,
CanIOFlags& out_flags) = 0;
virtual int16_t receive(CanFrame& out_frame, MonotonicTime& out_ts_monotonic, UtcTime& out_ts_utc,
CanIOFlags& out_flags) = 0;
/**
* Configure the hardware CAN filters. @ref CanFilterConfig.
* @return 0 = success, negative for error.
*/
virtual int configureFilters(const CanFilterConfig* filter_configs, int num_configs) = 0;
virtual int16_t configureFilters(const CanFilterConfig* filter_configs, uint16_t num_configs) = 0;
/**
* Number of available hardware filters.
*/
virtual int getNumFilters() const = 0;
virtual uint16_t getNumFilters() const = 0;
/**
* Continuously incrementing counter of hardware errors.
@@ -158,12 +158,12 @@ public:
/**
* Returns the interface by index, or null pointer if the index is out of range.
*/
virtual ICanIface* getIface(int iface_index) = 0;
virtual ICanIface* getIface(uint8_t iface_index) = 0;
/**
* Total number of available CAN interfaces.
*/
virtual int getNumIfaces() const = 0;
virtual uint8_t getNumIfaces() const = 0;
/**
* Block until the deadline, or one of the specified interfaces becomes available for read or write.
@@ -173,7 +173,7 @@ public:
* @param [in] blocking_deadline Zero means non-blocking operation.
* @return Positive number of ready interfaces or negative error code.
*/
virtual int select(CanSelectMasks& inout_masks, MonotonicTime blocking_deadline) = 0;
virtual int16_t select(CanSelectMasks& inout_masks, MonotonicTime blocking_deadline) = 0;
};
}
+2 -2
View File
@@ -48,10 +48,10 @@ public:
T* get() const { return root_; }
bool isEmpty() const { return get() == NULL; }
unsigned int getLength() const
unsigned getLength() const
{
T* node = root_;
unsigned int cnt = 0;
unsigned cnt = 0;
while (node)
{
cnt++;
+11 -11
View File
@@ -21,7 +21,7 @@ namespace uavcan
* Key's default constructor must initialize the object into invalid state.
* Size of Key + Value + padding must not exceed MemPoolBlockSize.
*/
template <typename Key, typename Value, unsigned int NumStaticEntries>
template <typename Key, typename Value, unsigned NumStaticEntries>
class Map : Noncopyable
{
UAVCAN_PACKED_BEGIN
@@ -88,7 +88,7 @@ class Map : Noncopyable
KVPair* find(const Key& key)
{
for (unsigned int i = 0; i < NumStaticEntries; i++)
for (unsigned i = 0; i < NumStaticEntries; i++)
{
if (static_[i].match(key))
{
@@ -115,7 +115,7 @@ class Map : Noncopyable
{
// Looking for first EMPTY static entry
KVPair* stat = NULL;
for (unsigned int i = 0; i < NumStaticEntries; i++)
for (unsigned i = 0; i < NumStaticEntries; i++)
{
if (static_[i].match(Key()))
{
@@ -252,9 +252,9 @@ public:
template <typename Predicate>
void removeWhere(Predicate predicate)
{
unsigned int num_removed = 0;
unsigned num_removed = 0;
for (unsigned int i = 0; i < NumStaticEntries; i++)
for (unsigned i = 0; i < NumStaticEntries; i++)
{
if (!static_[i].match(Key()))
{
@@ -294,7 +294,7 @@ public:
template <typename Predicate>
const Key* findFirstKey(Predicate predicate) const
{
for (unsigned int i = 0; i < NumStaticEntries; i++)
for (unsigned i = 0; i < NumStaticEntries; i++)
{
if (!static_[i].match(Key()))
{
@@ -332,10 +332,10 @@ public:
bool isEmpty() const { return (getNumStaticPairs() == 0) && (getNumDynamicPairs() == 0); }
/// For testing
unsigned int getNumStaticPairs() const
unsigned getNumStaticPairs() const
{
unsigned int num = 0;
for (unsigned int i = 0; i < NumStaticEntries; i++)
unsigned num = 0;
for (unsigned i = 0; i < NumStaticEntries; i++)
{
if (!static_[i].match(Key()))
{
@@ -346,9 +346,9 @@ public:
}
/// For testing
unsigned int getNumDynamicPairs() const
unsigned getNumDynamicPairs() const
{
unsigned int num = 0;
unsigned num = 0;
KVGroup* p = list_.get();
while (p)
{
+13 -13
View File
@@ -26,12 +26,12 @@ namespace uavcan
enum ArrayMode { ArrayModeStatic, ArrayModeDynamic };
template <unsigned int Size>
template <unsigned Size>
class StaticArrayBase
{
public:
enum { SizeBitLen = 0 };
typedef unsigned int SizeType;
typedef unsigned SizeType;
SizeType size() const { return Size; }
SizeType capacity() const { return Size; }
@@ -55,7 +55,7 @@ protected:
};
template <unsigned int MaxSize>
template <unsigned MaxSize>
class DynamicArrayBase
{
protected:
@@ -121,7 +121,7 @@ public:
/**
* Statically allocated array with optional dynamic-like behavior
*/
template <typename T, ArrayMode ArrayMode, unsigned int MaxSize>
template <typename T, ArrayMode ArrayMode, unsigned MaxSize>
class ArrayImpl : public Select<ArrayMode == ArrayModeDynamic,
DynamicArrayBase<MaxSize>, StaticArrayBase<MaxSize> >::Result
{
@@ -196,7 +196,7 @@ public:
/**
* Bit array specialization
*/
template <unsigned int MaxSize, ArrayMode ArrayMode, CastMode CastMode>
template <unsigned MaxSize, ArrayMode ArrayMode, CastMode CastMode>
class ArrayImpl<IntegerSpec<1, SignednessUnsigned, CastMode>, ArrayMode, MaxSize>
: public std::bitset<MaxSize>
, public Select<ArrayMode == ArrayModeDynamic, DynamicArrayBase<MaxSize>, StaticArrayBase<MaxSize> >::Result
@@ -226,7 +226,7 @@ public:
template <typename T, ArrayMode ArrayMode> class ArrayImpl<T, ArrayMode, 0>;
template <typename T, ArrayMode ArrayMode, unsigned int MaxSize_>
template <typename T, ArrayMode ArrayMode, unsigned MaxSize_>
class Array : public ArrayImpl<T, ArrayMode, MaxSize_>
{
typedef ArrayImpl<T, ArrayMode, MaxSize_> Base;
@@ -377,7 +377,7 @@ public:
{
if (new_size > size())
{
unsigned int cnt = new_size - size();
unsigned cnt = new_size - size();
while (cnt--)
{
push_back(filler);
@@ -385,7 +385,7 @@ public:
}
else if (new_size < size())
{
unsigned int cnt = size() - new_size;
unsigned cnt = size() - new_size;
while (cnt--)
{
pop_back();
@@ -464,7 +464,7 @@ public:
return *this;
}
template <uavcan::ArrayMode RhsArrayMode, unsigned int RhsMaxSize>
template <uavcan::ArrayMode RhsArrayMode, unsigned RhsMaxSize>
SelfType& operator+=(const Array<T, RhsArrayMode, RhsMaxSize>& rhs)
{
typedef Array<T, RhsArrayMode, RhsMaxSize> Rhs;
@@ -520,20 +520,20 @@ public:
typedef SizeType size_type;
};
template <typename R, typename T, ArrayMode ArrayMode, unsigned int MaxSize>
template <typename R, typename T, ArrayMode ArrayMode, unsigned MaxSize>
inline bool operator==(const R& rhs, const Array<T, ArrayMode, MaxSize>& lhs)
{
return lhs.operator==(rhs);
}
template <typename R, typename T, ArrayMode ArrayMode, unsigned int MaxSize>
template <typename R, typename T, ArrayMode ArrayMode, unsigned MaxSize>
inline bool operator!=(const R& rhs, const Array<T, ArrayMode, MaxSize>& lhs)
{
return lhs.operator!=(rhs);
}
template <typename T, ArrayMode ArrayMode, unsigned int MaxSize>
template <typename T, ArrayMode ArrayMode, unsigned MaxSize>
class YamlStreamer<Array<T, ArrayMode, MaxSize> >
{
typedef Array<T, ArrayMode, MaxSize> ArrayType;
@@ -545,7 +545,7 @@ class YamlStreamer<Array<T, ArrayMode, MaxSize> >
return true;
}
static const char Good[] = {'\n', '\r', '\t'};
for (unsigned int i = 0; i < sizeof(Good) / sizeof(Good[0]); i++)
for (unsigned i = 0; i < sizeof(Good) / sizeof(Good[0]); i++)
{
if (Good[i] == c)
{
@@ -24,7 +24,7 @@ class BitStream
int bit_offset_;
uint8_t byte_cache_;
static inline unsigned int bitlenToBytelen(unsigned int bits) { return (bits + 7) / 8; }
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)
@@ -23,7 +23,7 @@
namespace uavcan
{
template <unsigned int BitLen>
template <unsigned BitLen>
struct NativeFloatSelector
{
struct ErrorNoSuchFloat;
@@ -46,7 +46,7 @@ public:
/// UAVCAN requires rounding to nearest for all float conversions
static std::float_round_style roundstyle() { return std::round_to_nearest; }
template <unsigned int BitLen>
template <unsigned BitLen>
static typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType
toIeee(typename NativeFloatSelector<BitLen>::Type value)
{
@@ -58,7 +58,7 @@ public:
return u.i;
}
template <unsigned int BitLen>
template <unsigned BitLen>
static typename NativeFloatSelector<BitLen>::Type
toNative(typename IntegerSpec<BitLen, SignednessUnsigned, CastModeTruncate>::StorageType value)
{
@@ -83,7 +83,7 @@ IEEE754Converter::toNative<16>(typename IntegerSpec<16, SignednessUnsigned, Cast
return halfToNativeNonIeee(value);
}
template <unsigned int BitLen> struct IEEE754Limits;
template <unsigned BitLen> struct IEEE754Limits;
template <> struct IEEE754Limits<16>
{
static typename NativeFloatSelector<16>::Type max() { return 65504.0; }
@@ -101,7 +101,7 @@ template <> struct IEEE754Limits<64>
};
template <unsigned int BitLen_, CastMode CastMode>
template <unsigned BitLen_, CastMode CastMode>
class FloatSpec : public IEEE754Limits<BitLen_>
{
FloatSpec();
@@ -183,7 +183,7 @@ private:
};
template <unsigned int BitLen, CastMode CastMode>
template <unsigned BitLen, CastMode CastMode>
struct YamlStreamer<FloatSpec<BitLen, CastMode> >
{
typedef typename FloatSpec<BitLen, CastMode>::StorageType StorageType;
@@ -16,7 +16,7 @@ namespace uavcan
enum Signedness { SignednessUnsigned, SignednessSigned };
template <unsigned int BitLen_, Signedness Signedness, CastMode CastMode>
template <unsigned BitLen_, Signedness Signedness, CastMode CastMode>
class IntegerSpec
{
struct ErrorNoSuchInteger;
@@ -124,14 +124,14 @@ struct IsIntegerSpec
enum { Result = 0 };
};
template <unsigned int BitLen, Signedness Signedness, CastMode CastMode>
template <unsigned BitLen, Signedness Signedness, CastMode CastMode>
struct IsIntegerSpec<IntegerSpec<BitLen, Signedness, CastMode> >
{
enum { Result = 1 };
};
template <unsigned int BitLen, Signedness Signedness, CastMode CastMode>
template <unsigned BitLen, Signedness Signedness, CastMode CastMode>
struct YamlStreamer<IntegerSpec<BitLen, Signedness, CastMode> >
{
typedef IntegerSpec<BitLen, Signedness, CastMode> RawType;
@@ -142,7 +142,7 @@ struct YamlStreamer<IntegerSpec<BitLen, Signedness, CastMode> >
{
// Get rid of character types - we want its integer representation, not ASCII code
typedef typename Select<(sizeof(StorageType) >= sizeof(int)), StorageType,
typename Select<RawType::IsSigned, int, unsigned int>::Result >::Result TempType;
typename Select<RawType::IsSigned, int, unsigned>::Result >::Result TempType;
s << TempType(value);
}
};
@@ -68,7 +68,7 @@ static Stream& operator<<(Stream& s, const ReceivedDataStructure<DataType>& rds)
}
template <typename DataStruct_, unsigned int NumStaticReceivers_, unsigned int NumStaticBufs_>
template <typename DataStruct_, unsigned NumStaticReceivers_, unsigned NumStaticBufs_>
class TransferListenerInstantiationHelper
{
enum { DataTypeMaxByteLen = BitLenToByteLen<DataStruct_::MaxBitLen>::Result };
@@ -109,8 +109,8 @@ public:
void getDataTypeIDMask(DataTypeKind kind, DataTypeIDMask& mask) const;
unsigned int getNumMessageTypes() const { return msgs_.getLength(); }
unsigned int getNumServiceTypes() const { return srvs_.getLength(); }
unsigned getNumMessageTypes() const { return msgs_.getLength(); }
unsigned getNumServiceTypes() const { return srvs_.getLength(); }
#if UAVCAN_DEBUG
/// Required for unit testing
@@ -14,7 +14,7 @@ class IMarshalBuffer : public ITransferBuffer
{
public:
virtual const uint8_t* getDataPtr() const = 0;
virtual unsigned int getDataLength() const = 0;
virtual unsigned getDataLength() const = 0;
};
@@ -22,30 +22,30 @@ class IMarshalBufferProvider
{
public:
virtual ~IMarshalBufferProvider() { }
virtual IMarshalBuffer* getBuffer(unsigned int size) = 0;
virtual IMarshalBuffer* getBuffer(unsigned size) = 0;
};
template <unsigned int MaxSize_ = MaxTransferPayloadLen>
template <unsigned MaxSize_ = MaxTransferPayloadLen>
class MarshalBufferProvider : public IMarshalBufferProvider
{
class Buffer : public IMarshalBuffer
{
StaticTransferBuffer<MaxSize_> buf_;
int read(unsigned int offset, uint8_t* data, unsigned int len) const
int read(unsigned offset, uint8_t* data, unsigned len) const
{
return buf_.read(offset, data, len);
}
int write(unsigned int offset, const uint8_t* data, unsigned int len)
int write(unsigned offset, const uint8_t* data, unsigned len)
{
return buf_.write(offset, data, len);
}
const uint8_t* getDataPtr() const { return buf_.getRawPtr(); }
unsigned int getDataLength() const { return buf_.getMaxWritePos(); }
unsigned getDataLength() const { return buf_.getMaxWritePos(); }
public:
void reset() { buf_.reset(); }
@@ -56,7 +56,7 @@ class MarshalBufferProvider : public IMarshalBufferProvider
public:
enum { MaxSize = MaxSize_ };
IMarshalBuffer* getBuffer(unsigned int size)
IMarshalBuffer* getBuffer(unsigned size)
{
if (size > MaxSize)
{
+2 -2
View File
@@ -27,8 +27,8 @@ namespace uavcan
{
template <std::size_t MemPoolSize_,
unsigned int OutgoingTransferRegistryStaticEntries = 10,
unsigned int OutgoingTransferMaxPayloadLen = MaxTransferPayloadLen>
unsigned OutgoingTransferRegistryStaticEntries = 10,
unsigned OutgoingTransferMaxPayloadLen = MaxTransferPayloadLen>
class Node : public INode
{
enum
+1 -1
View File
@@ -49,7 +49,7 @@ public:
void add(DeadlineHandler* mdh);
void remove(DeadlineHandler* mdh);
bool doesExist(const DeadlineHandler* mdh) const;
unsigned int getNumHandlers() const { return handlers_.getLength(); }
unsigned getNumHandlers() const { return handlers_.getLength(); }
MonotonicTime pollAndGetMonotonicTime(ISystemClock& sysclock);
MonotonicTime getEarliestDeadline() const;
@@ -27,8 +27,8 @@ template <typename DataType_,
typename Callback = void (*)(const ReceivedDataStructure<typename DataType_::Request>&,
typename DataType_::Response&),
#endif
unsigned int NumStaticReceivers = 2,
unsigned int NumStaticBufs = 1>
unsigned NumStaticReceivers = 2,
unsigned NumStaticBufs = 1>
class ServiceServer : public GenericSubscriber<DataType_, typename DataType_::Request,
typename TransferListenerInstantiationHelper<typename DataType_::Request,
NumStaticReceivers,
+2 -2
View File
@@ -25,8 +25,8 @@ template <typename DataType_,
#else
typename Callback = void (*)(const ReceivedDataStructure<DataType_>&),
#endif
unsigned int NumStaticReceivers = 2,
unsigned int NumStaticBufs = 1>
unsigned NumStaticReceivers = 2,
unsigned NumStaticBufs = 1>
class Subscriber : public GenericSubscriber<DataType_, DataType_,
typename TransferListenerInstantiationHelper<DataType_,
NumStaticReceivers,
@@ -150,9 +150,9 @@ class CanIOManager : Noncopyable
CanTxQueue tx_queues_[MaxCanIfaces];
IfaceFrameCounters counters_[MaxCanIfaces];
int sendToIface(int iface_index, const CanFrame& frame, MonotonicTime tx_deadline, CanIOFlags flags);
int sendFromTxQueue(int iface_index);
int makePendingTxMask() const;
int sendToIface(uint8_t iface_index, const CanFrame& frame, MonotonicTime tx_deadline, CanIOFlags flags);
int sendFromTxQueue(uint8_t iface_index);
uint8_t makePendingTxMask() const;
public:
CanIOManager(ICanDriver& driver, IAllocator& allocator, ISystemClock& sysclock)
@@ -168,9 +168,9 @@ public:
}
}
int getNumIfaces() const;
uint8_t getNumIfaces() const;
CanIfacePerfCounters getIfacePerfCounters(int iface_index) const;
CanIfacePerfCounters getIfacePerfCounters(uint8_t iface_index) const;
/**
* Returns:
@@ -179,7 +179,7 @@ public:
* negative - failure
*/
int send(const CanFrame& frame, MonotonicTime tx_deadline, MonotonicTime blocking_deadline,
int iface_mask, CanTxQueue::Qos qos, CanIOFlags flags);
uint8_t iface_mask, CanTxQueue::Qos qos, CanIOFlags flags);
int receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline, CanIOFlags& out_flags);
};
+1 -1
View File
@@ -40,7 +40,7 @@ public:
value_ = ((value_ << 8) ^ Table[((value_ >> 8) ^ byte) & 0xFF]) & 0xFFFF;
}
void add(const uint8_t* bytes, unsigned int len)
void add(const uint8_t* bytes, unsigned len)
{
assert(bytes);
while (len--)
@@ -48,7 +48,7 @@ public:
void add(LoopbackFrameListenerBase* listener);
void remove(LoopbackFrameListenerBase* listener);
bool doesExist(const LoopbackFrameListenerBase* listener) const;
unsigned int getNumListeners() const { return listeners_.getLength(); }
unsigned getNumListeners() const { return listeners_.getLength(); }
void invokeListeners(RxFrame& frame);
};
+2 -2
View File
@@ -57,9 +57,9 @@ public:
}
int getMaxPayloadLen() const;
int setPayload(const uint8_t* data, int len);
int setPayload(const uint8_t* data, unsigned len);
int getPayloadLen() const { return payload_len_; }
unsigned getPayloadLen() const { return payload_len_; }
const uint8_t* getPayloadPtr() const { return payload_; }
TransferType getTransferType() const { return transfer_type_; }
@@ -27,7 +27,7 @@ public:
void addError() { errors_++; }
void addErrors(unsigned int errors)
void addErrors(unsigned errors)
{
errors_ += errors;
}
@@ -25,8 +25,8 @@ class ITransferBuffer
public:
virtual ~ITransferBuffer() { }
virtual int read(unsigned int offset, uint8_t* data, unsigned int len) const = 0;
virtual int write(unsigned int offset, const uint8_t* data, unsigned int len) = 0;
virtual int read(unsigned offset, uint8_t* data, unsigned len) const = 0;
virtual int write(unsigned offset, const uint8_t* data, unsigned len) = 0;
};
/**
@@ -108,21 +108,21 @@ class DynamicTransferBufferManagerEntry
static Block* instantiate(IAllocator& allocator);
static void destroy(Block*& obj, IAllocator& allocator);
void read(uint8_t*& outptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_read);
void write(const uint8_t*& inptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_write);
void read(uint8_t*& outptr, unsigned target_offset,
unsigned& total_offset, unsigned& left_to_read);
void write(const uint8_t*& inptr, unsigned target_offset,
unsigned& total_offset, unsigned& left_to_write);
};
IAllocator& allocator_;
LinkedListRoot<Block> blocks_; // Blocks are ordered from lower to higher buffer offset
unsigned int max_write_pos_;
const unsigned int max_size_;
unsigned max_write_pos_;
const unsigned max_size_;
void resetImpl();
public:
DynamicTransferBufferManagerEntry(IAllocator& allocator, unsigned int max_size)
DynamicTransferBufferManagerEntry(IAllocator& allocator, unsigned max_size)
: allocator_(allocator)
, max_write_pos_(0)
, max_size_(max_size)
@@ -137,22 +137,22 @@ public:
resetImpl();
}
static DynamicTransferBufferManagerEntry* instantiate(IAllocator& allocator, unsigned int max_size);
static DynamicTransferBufferManagerEntry* instantiate(IAllocator& allocator, unsigned max_size);
static void destroy(DynamicTransferBufferManagerEntry*& obj, IAllocator& allocator);
int read(unsigned int offset, uint8_t* data, unsigned int len) const;
int write(unsigned int offset, const uint8_t* data, unsigned int len);
int read(unsigned offset, uint8_t* data, unsigned len) const;
int write(unsigned offset, const uint8_t* data, unsigned len);
};
UAVCAN_PACKED_END
/**
* Standalone static buffer
*/
template <unsigned int Size>
template <unsigned Size>
class StaticTransferBuffer : public ITransferBuffer
{
uint8_t data_[Size];
unsigned int max_write_pos_;
unsigned max_write_pos_;
public:
StaticTransferBuffer()
@@ -162,7 +162,7 @@ public:
std::fill(data_, data_ + Size, 0);
}
int read(unsigned int offset, uint8_t* data, unsigned int len) const
int read(unsigned offset, uint8_t* data, unsigned len) const
{
if (!data)
{
@@ -182,7 +182,7 @@ public:
return len;
}
int write(unsigned int offset, const uint8_t* data, unsigned int len)
int write(unsigned offset, const uint8_t* data, unsigned len)
{
if (!data)
{
@@ -214,14 +214,14 @@ public:
uint8_t* getRawPtr() { return data_; }
const uint8_t* getRawPtr() const { return data_; }
unsigned int getMaxWritePos() const { return max_write_pos_; }
void setMaxWritePos(unsigned int value) { max_write_pos_ = value; }
unsigned getMaxWritePos() const { return max_write_pos_; }
void setMaxWritePos(unsigned value) { max_write_pos_ = value; }
};
/**
* Statically allocated storage for buffer manager
*/
template <unsigned int Size>
template <unsigned Size>
class StaticTransferBufferManagerEntry : public TransferBufferManagerEntry
{
StaticTransferBuffer<Size> buf_;
@@ -232,12 +232,12 @@ class StaticTransferBufferManagerEntry : public TransferBufferManagerEntry
}
public:
int read(unsigned int offset, uint8_t* data, unsigned int len) const
int read(unsigned offset, uint8_t* data, unsigned len) const
{
return buf_.read(offset, data, len);
}
int write(unsigned int offset, const uint8_t* data, unsigned int len)
int write(unsigned offset, const uint8_t* data, unsigned len)
{
return buf_.write(offset, data, len);
}
@@ -310,7 +310,7 @@ public:
/**
* Buffer manager implementation.
*/
template <unsigned int MaxBufSize, unsigned int NumStaticBufs>
template <unsigned MaxBufSize, unsigned NumStaticBufs>
class TransferBufferManager : public ITransferBufferManager, Noncopyable
{
typedef StaticTransferBufferManagerEntry<MaxBufSize> StaticBufferType;
@@ -321,7 +321,7 @@ class TransferBufferManager : public ITransferBufferManager, Noncopyable
StaticBufferType* findFirstStatic(const TransferBufferManagerKey& key)
{
for (unsigned int i = 0; i < NumStaticBufs; i++)
for (unsigned i = 0; i < NumStaticBufs; i++)
{
if (static_buffers_[i].getKey() == key)
{
@@ -476,12 +476,12 @@ public:
bool isEmpty() const { return (getNumStaticBuffers() == 0) && (getNumDynamicBuffers() == 0); }
unsigned int getNumDynamicBuffers() const { return dynamic_buffers_.getLength(); }
unsigned getNumDynamicBuffers() const { return dynamic_buffers_.getLength(); }
unsigned int getNumStaticBuffers() const
unsigned getNumStaticBuffers() const
{
unsigned int res = 0;
for (unsigned int i = 0; i < NumStaticBufs; i++)
unsigned res = 0;
for (unsigned i = 0; i < NumStaticBufs; i++)
{
if (!static_buffers_[i].isEmpty())
{
@@ -31,7 +31,7 @@ class IncomingTransfer : public ITransferBuffer
uint8_t iface_index_;
/// That's a no-op, asserts in debug builds
int write(unsigned int offset, const uint8_t* data, unsigned int len);
int write(unsigned offset, const uint8_t* data, unsigned len);
protected:
IncomingTransfer(MonotonicTime ts_mono, UtcTime ts_utc, TransferType transfer_type,
@@ -67,7 +67,7 @@ class SingleFrameIncomingTransfer : public IncomingTransfer
const uint8_t payload_len_;
public:
SingleFrameIncomingTransfer(const RxFrame& frm);
int read(unsigned int offset, uint8_t* data, unsigned int len) const;
int read(unsigned offset, uint8_t* data, unsigned len) const;
};
/**
@@ -79,7 +79,7 @@ class MultiFrameIncomingTransfer : public IncomingTransfer, Noncopyable
public:
MultiFrameIncomingTransfer(MonotonicTime ts_mono, UtcTime ts_utc, const RxFrame& last_frame,
TransferBufferAccessor& tba);
int read(unsigned int offset, uint8_t* data, unsigned int len) const;
int read(unsigned offset, uint8_t* data, unsigned len) const;
void release() { buf_acc_.remove(); }
};
@@ -117,7 +117,7 @@ public:
/**
* This class should be derived by transfer receivers (subscribers, servers).
*/
template <unsigned int MaxBufSize, unsigned int NumStaticBufs, unsigned int NumStaticReceivers>
template <unsigned MaxBufSize, unsigned NumStaticBufs, unsigned NumStaticReceivers>
class TransferListener : public TransferListenerBase
{
typedef TransferBufferManager<MaxBufSize, NumStaticBufs> BufferManager;
@@ -203,7 +203,7 @@ public:
/**
* This class should be derived by callers.
*/
template <unsigned int MaxBufSize>
template <unsigned MaxBufSize>
class ServiceResponseTransferListener : public TransferListener<MaxBufSize, 1, 1>
{
public:
+3 -3
View File
@@ -32,12 +32,12 @@ std::string CanFrame::toString(StringRepresentation mode) const
if (id & FlagEFF)
{
wpos += snprintf(wpos, epos - wpos, "0x%08x ", (unsigned int)(id & MaskExtID));
wpos += snprintf(wpos, 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 int)(id & MaskStdID));
wpos += snprintf(wpos, epos - wpos, fmt, unsigned(id & MaskStdID));
}
if (id & FlagRTR)
@@ -53,7 +53,7 @@ std::string CanFrame::toString(StringRepresentation mode) const
{
for (int dlen = 0; dlen < dlc; dlen++) // hex bytes
{
wpos += snprintf(wpos, epos - wpos, " %02x", (unsigned int)data[dlen]);
wpos += snprintf(wpos, epos - wpos, " %02x", unsigned(data[dlen]));
}
while (mode == StrAligned && wpos < buf + ASCII_COLUMN_OFFSET) // alignment
+20 -20
View File
@@ -212,9 +212,9 @@ bool CanTxQueue::topPriorityHigherOrEqual(const CanFrame& rhs_frame) const
/*
* CanIOManager
*/
int CanIOManager::sendToIface(int iface_index, const CanFrame& frame, MonotonicTime tx_deadline, CanIOFlags flags)
int CanIOManager::sendToIface(uint8_t iface_index, const CanFrame& frame, MonotonicTime tx_deadline, CanIOFlags flags)
{
assert(iface_index >= 0 && iface_index < MaxCanIfaces);
assert(iface_index < MaxCanIfaces);
ICanIface* const iface = driver_.getIface(iface_index);
if (iface == NULL)
{
@@ -234,9 +234,9 @@ int CanIOManager::sendToIface(int iface_index, const CanFrame& frame, MonotonicT
return res;
}
int CanIOManager::sendFromTxQueue(int iface_index)
int CanIOManager::sendFromTxQueue(uint8_t iface_index)
{
assert(iface_index >= 0 && iface_index < MaxCanIfaces);
assert(iface_index < MaxCanIfaces);
CanTxQueue::Entry* entry = tx_queues_[iface_index].peek();
if (entry == NULL)
{
@@ -250,10 +250,10 @@ int CanIOManager::sendFromTxQueue(int iface_index)
return res;
}
int CanIOManager::makePendingTxMask() const
uint8_t CanIOManager::makePendingTxMask() const
{
int write_mask = 0;
for (int i = 0; i < getNumIfaces(); i++)
uint8_t write_mask = 0;
for (uint8_t i = 0; i < getNumIfaces(); i++)
{
if (!tx_queues_[i].isEmpty())
{
@@ -263,17 +263,17 @@ int CanIOManager::makePendingTxMask() const
return write_mask;
}
int CanIOManager::getNumIfaces() const
uint8_t CanIOManager::getNumIfaces() const
{
const int num = driver_.getNumIfaces();
const uint8_t num = driver_.getNumIfaces();
assert(num > 0 && num <= MaxCanIfaces);
return std::min(std::max(num, 0), (int)MaxCanIfaces);
return std::min(std::max(num, uint8_t(0)), uint8_t(MaxCanIfaces));
}
CanIfacePerfCounters CanIOManager::getIfacePerfCounters(int iface_index) const
CanIfacePerfCounters CanIOManager::getIfacePerfCounters(uint8_t iface_index) const
{
ICanIface* const iface = driver_.getIface(iface_index);
if (iface == NULL || iface_index >= MaxCanIfaces || iface_index < 0)
if (iface == NULL || iface_index >= MaxCanIfaces)
{
assert(0);
return CanIfacePerfCounters();
@@ -286,10 +286,10 @@ CanIfacePerfCounters CanIOManager::getIfacePerfCounters(int iface_index) const
}
int CanIOManager::send(const CanFrame& frame, MonotonicTime tx_deadline, MonotonicTime blocking_deadline,
int iface_mask, CanTxQueue::Qos qos, CanIOFlags flags)
uint8_t iface_mask, CanTxQueue::Qos qos, CanIOFlags flags)
{
const int num_ifaces = getNumIfaces();
const int all_ifaces_mask = (1 << num_ifaces) - 1;
const uint8_t num_ifaces = getNumIfaces();
const uint8_t all_ifaces_mask = (1U << num_ifaces) - 1;
iface_mask &= all_ifaces_mask;
if (blocking_deadline > tx_deadline)
@@ -317,7 +317,7 @@ int CanIOManager::send(const CanFrame& frame, MonotonicTime tx_deadline, Monoton
}
// Transmission
for (int i = 0; i < num_ifaces; i++)
for (uint8_t i = 0; i < num_ifaces; i++)
{
if (masks.write & (1 << i))
{
@@ -357,7 +357,7 @@ int CanIOManager::send(const CanFrame& frame, MonotonicTime tx_deadline, Monoton
UAVCAN_TRACE("CanIOManager", "Send: Premature timeout in select(), will try again");
continue;
}
for (int i = 0; i < num_ifaces; i++)
for (uint8_t i = 0; i < num_ifaces; i++)
{
if (iface_mask & (1 << i))
{
@@ -372,7 +372,7 @@ int CanIOManager::send(const CanFrame& frame, MonotonicTime tx_deadline, Monoton
int CanIOManager::receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline, CanIOFlags& out_flags)
{
const int num_ifaces = getNumIfaces();
const uint8_t num_ifaces = getNumIfaces();
while (true)
{
@@ -388,7 +388,7 @@ int CanIOManager::receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline
}
// Write - if buffers are not empty, one frame will be sent for each iface per one receive() call
for (int i = 0; i < num_ifaces; i++)
for (uint8_t i = 0; i < num_ifaces; i++)
{
if (masks.write & (1 << i))
{
@@ -397,7 +397,7 @@ int CanIOManager::receive(CanRxFrame& out_frame, MonotonicTime blocking_deadline
}
// Read
for (int i = 0; i < num_ifaces; i++)
for (uint8_t i = 0; i < num_ifaces; i++)
{
if (masks.read & (1 << i))
{
+7 -5
View File
@@ -33,14 +33,16 @@ int Frame::getMaxPayloadLen() const
}
}
int Frame::setPayload(const uint8_t* data, int len)
int Frame::setPayload(const uint8_t* data, unsigned len)
{
len = std::min(getMaxPayloadLen(), len);
if (len >= 0)
const int maxlen = getMaxPayloadLen();
if (maxlen < 0)
{
std::copy(data, data + len, payload_);
payload_len_ = len;
return maxlen;
}
len = std::min(unsigned(maxlen), len);
std::copy(data, data + len, payload_);
payload_len_ = len;
return len;
}
+13 -12
View File
@@ -43,11 +43,11 @@ void DynamicTransferBufferManagerEntry::Block::destroy(Block*& obj, IAllocator&
}
}
void DynamicTransferBufferManagerEntry::Block::read(uint8_t*& outptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_read)
void DynamicTransferBufferManagerEntry::Block::read(uint8_t*& outptr, unsigned target_offset,
unsigned& total_offset, unsigned& left_to_read)
{
assert(outptr);
for (int i = 0; (i < Block::Size) && (left_to_read > 0); i++, total_offset++)
for (unsigned i = 0; (i < Block::Size) && (left_to_read > 0); i++, total_offset++)
{
if (total_offset >= target_offset)
{
@@ -57,11 +57,11 @@ void DynamicTransferBufferManagerEntry::Block::read(uint8_t*& outptr, unsigned i
}
}
void DynamicTransferBufferManagerEntry::Block::write(const uint8_t*& inptr, unsigned int target_offset,
unsigned int& total_offset, unsigned int& left_to_write)
void DynamicTransferBufferManagerEntry::Block::write(const uint8_t*& inptr, unsigned target_offset,
unsigned& total_offset, unsigned& left_to_write)
{
assert(inptr);
for (int i = 0; (i < Block::Size) && (left_to_write > 0); i++, total_offset++)
for (unsigned i = 0; (i < Block::Size) && (left_to_write > 0); i++, total_offset++)
{
if (total_offset >= target_offset)
{
@@ -75,7 +75,7 @@ void DynamicTransferBufferManagerEntry::Block::write(const uint8_t*& inptr, unsi
* DynamicTransferBuffer
*/
DynamicTransferBufferManagerEntry* DynamicTransferBufferManagerEntry::instantiate(IAllocator& allocator,
unsigned int max_size)
unsigned max_size)
{
void* const praw = allocator.allocate(sizeof(DynamicTransferBufferManagerEntry));
if (praw == NULL)
@@ -108,7 +108,7 @@ void DynamicTransferBufferManagerEntry::resetImpl()
}
}
int DynamicTransferBufferManagerEntry::read(unsigned int offset, uint8_t* data, unsigned int len) const
int DynamicTransferBufferManagerEntry::read(unsigned offset, uint8_t* data, unsigned len) const
{
if (!data)
{
@@ -126,7 +126,8 @@ int DynamicTransferBufferManagerEntry::read(unsigned int offset, uint8_t* data,
assert((offset + len) <= max_write_pos_);
// This shall be optimized.
unsigned int total_offset = 0, left_to_read = len;
unsigned total_offset = 0;
unsigned left_to_read = len;
uint8_t* outptr = data;
Block* p = blocks_.get();
while (p)
@@ -143,7 +144,7 @@ int DynamicTransferBufferManagerEntry::read(unsigned int offset, uint8_t* data,
return len;
}
int DynamicTransferBufferManagerEntry::write(unsigned int offset, const uint8_t* data, unsigned int len)
int DynamicTransferBufferManagerEntry::write(unsigned offset, const uint8_t* data, unsigned len)
{
if (!data)
{
@@ -161,8 +162,8 @@ int DynamicTransferBufferManagerEntry::write(unsigned int offset, const uint8_t*
}
assert((offset + len) <= max_size_);
unsigned int total_offset = 0;
unsigned int left_to_write = len;
unsigned total_offset = 0;
unsigned left_to_write = len;
const uint8_t* inptr = data;
Block* p = blocks_.get();
Block* last_written_block = NULL;
@@ -12,7 +12,7 @@ namespace uavcan
/*
* IncomingTransfer
*/
int IncomingTransfer::write(unsigned int, const uint8_t*, unsigned int)
int IncomingTransfer::write(unsigned, const uint8_t*, unsigned)
{
assert(0); // Incoming transfer container is read-only
return -ErrLogic;
@@ -30,7 +30,7 @@ SingleFrameIncomingTransfer::SingleFrameIncomingTransfer(const RxFrame& frm)
assert(frm.isValid());
}
int SingleFrameIncomingTransfer::read(unsigned int offset, uint8_t* data, unsigned int len) const
int SingleFrameIncomingTransfer::read(unsigned offset, uint8_t* data, unsigned len) const
{
if (data == NULL)
{
@@ -63,7 +63,7 @@ MultiFrameIncomingTransfer::MultiFrameIncomingTransfer(MonotonicTime ts_mono, Ut
assert(last_frame.isLast());
}
int MultiFrameIncomingTransfer::read(unsigned int offset, uint8_t* data, unsigned int len) const
int MultiFrameIncomingTransfer::read(unsigned offset, uint8_t* data, unsigned len) const
{
const ITransferBuffer* const tbb = const_cast<TransferBufferAccessor&>(buf_acc_).access();
if (tbb == NULL)
@@ -80,7 +80,7 @@ int MultiFrameIncomingTransfer::read(unsigned int offset, uint8_t* data, unsigne
bool TransferListenerBase::checkPayloadCrc(const uint16_t compare_with, const ITransferBuffer& tbb) const
{
TransferCRC crc = crc_base_;
unsigned int offset = 0;
unsigned offset = 0;
while (true)
{
uint8_t buf[16];
+4 -4
View File
@@ -127,7 +127,7 @@ TEST(Map, Basic)
ASSERT_EQ("D", *map->access("4"));
// Adding some new dynamics
unsigned int max_key_integer = 0;
unsigned max_key_integer = 0;
for (int i = 0; i < 100; i++)
{
const std::string key = toString(i);
@@ -155,15 +155,15 @@ TEST(Map, Basic)
// Removing odd values - nearly half of them
ASSERT_EQ(2, map->getNumStaticPairs());
const unsigned int num_dynamics_old = map->getNumDynamicPairs();
const unsigned num_dynamics_old = map->getNumDynamicPairs();
map->removeWhere(oddValuePredicate);
ASSERT_EQ(2, map->getNumStaticPairs());
const unsigned int num_dynamics_new = map->getNumDynamicPairs();
const unsigned num_dynamics_new = map->getNumDynamicPairs();
std::cout << "Num of dynamic pairs reduced from " << num_dynamics_old << " to " << num_dynamics_new << std::endl;
ASSERT_LT(num_dynamics_new, num_dynamics_old);
// Making sure there's no odd values left
for (unsigned int kv_int = 0; kv_int <= max_key_integer; kv_int++)
for (unsigned kv_int = 0; kv_int <= max_key_integer; kv_int++)
{
const std::string* val = map->access(toString(kv_int));
if (val)
+1 -1
View File
@@ -135,7 +135,7 @@ TEST(BitStream, BitByBit)
uavcan::BitStream bs_wr(buf);
std::string binary_string;
unsigned int counter = 0;
unsigned counter = 0;
for (int byte = 0; byte < NUM_BYTES; byte++)
{
for (int bit = 0; bit < 8; bit++, counter++)
+1 -1
View File
@@ -66,7 +66,7 @@ TEST(Scheduler, Timers)
ASSERT_GT(1100, tcc.events_b.size());
{
uavcan::MonotonicTime next_expected_deadline = start_ts + durMono(1000);
for (unsigned int i = 0; i < tcc.events_b.size(); i++)
for (unsigned i = 0; i < tcc.events_b.size(); i++)
{
ASSERT_TRUE(areTimestampsClose(tcc.events_b[i].scheduled_time, next_expected_deadline));
ASSERT_TRUE(areTimestampsClose(tcc.events_b[i].scheduled_time, tcc.events_b[i].real_time));
+4 -4
View File
@@ -137,7 +137,7 @@ TEST(Subscriber, Basic)
ASSERT_EQ(2, node.getDispatcher().getNumMessageListeners());
for (unsigned int i = 0; i < rx_frames.size(); i++)
for (unsigned i = 0; i < rx_frames.size(); i++)
{
can_driver.ifaces[0].pushRx(rx_frames[i]);
can_driver.ifaces[1].pushRx(rx_frames[i]);
@@ -149,7 +149,7 @@ TEST(Subscriber, Basic)
* Validation
*/
ASSERT_EQ(listener.extended.size(), rx_frames.size());
for (unsigned int i = 0; i < rx_frames.size(); i++)
for (unsigned i = 0; i < rx_frames.size(); i++)
{
const Listener::ReceivedDataStructureCopy s = listener.extended.at(i);
ASSERT_TRUE(s.msg == expected_msg);
@@ -161,7 +161,7 @@ TEST(Subscriber, Basic)
}
ASSERT_EQ(listener.simple.size(), rx_frames.size());
for (unsigned int i = 0; i < rx_frames.size(); i++)
for (unsigned i = 0; i < rx_frames.size(); i++)
{
ASSERT_TRUE(listener.simple.at(i) == expected_msg);
}
@@ -268,7 +268,7 @@ TEST(Subscriber, SingleFrameTransfer)
ASSERT_EQ(0, sub.getFailureCount());
ASSERT_EQ(4, listener.simple.size());
for (unsigned int i = 0; i < 4; i++)
for (unsigned i = 0; i < 4; i++)
{
ASSERT_TRUE(listener.simple.at(i) == root_ns_a::EmptyMessage());
}
+10 -13
View File
@@ -57,7 +57,7 @@ struct PairableCanDriver : public uavcan::ICanDriver, public uavcan::ICanIface
with->other = this;
}
uavcan::ICanIface* getIface(int iface_index)
uavcan::ICanIface* getIface(uavcan::uint8_t iface_index)
{
if (iface_index == 0)
{
@@ -66,30 +66,27 @@ struct PairableCanDriver : public uavcan::ICanDriver, public uavcan::ICanIface
return NULL;
}
int getNumIfaces() const { return 1; }
uavcan::uint8_t getNumIfaces() const { return 1; }
int select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime blocking_deadline)
uavcan::int16_t select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime blocking_deadline)
{
assert(other);
if (inout_masks.read == 1)
{
inout_masks.read = (read_queue.size() || loopback_queue.size()) ? 1 : 0;
}
if (inout_masks.read || inout_masks.write)
{
return 1;
}
while (clock.getMonotonic() < blocking_deadline)
{
usleep(1000);
}
return 0;
}
int send(const uavcan::CanFrame& frame, uavcan::MonotonicTime, uavcan::CanIOFlags flags)
uavcan::int16_t send(const uavcan::CanFrame& frame, uavcan::MonotonicTime, uavcan::CanIOFlags flags)
{
assert(other);
other->read_queue.push(frame);
@@ -100,8 +97,8 @@ struct PairableCanDriver : public uavcan::ICanDriver, public uavcan::ICanIface
return 1;
}
int receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, uavcan::UtcTime& out_ts_utc,
uavcan::CanIOFlags& out_flags)
uavcan::int16_t receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic,
uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags)
{
assert(other);
out_flags = 0;
@@ -122,9 +119,9 @@ struct PairableCanDriver : public uavcan::ICanDriver, public uavcan::ICanIface
return 1;
}
int configureFilters(const uavcan::CanFilterConfig*, int) { return -1; }
int getNumFilters() const { return 0; }
uint64_t getErrorCount() const { return error_count; }
uavcan::int16_t configureFilters(const uavcan::CanFilterConfig*, uavcan::uint16_t) { return -1; }
uavcan::uint16_t getNumFilters() const { return 0; }
uavcan::uint64_t getErrorCount() const { return error_count; }
};
@@ -159,7 +156,7 @@ struct InterlinkedTestNodes
int spinBoth(uavcan::MonotonicDuration duration)
{
assert(!duration.isNegative());
unsigned int nspins2 = duration.toMSec() / 2;
unsigned nspins2 = duration.toMSec() / 2;
nspins2 = nspins2 ? nspins2 : 1;
while (nspins2 --> 0)
{
@@ -19,8 +19,7 @@ using uavcan::DefaultDataTypeRegistrator;
using uavcan::MonotonicDuration;
template <typename DataType>
static bool validateDataTypeInfoResponse(const std::auto_ptr<ServiceCallResult<GetDataTypeInfo> >& resp,
unsigned int mask)
static bool validateDataTypeInfoResponse(const std::auto_ptr<ServiceCallResult<GetDataTypeInfo> >& resp, unsigned mask)
{
if (!resp.get())
{
@@ -38,7 +38,7 @@ struct GlobalTimeSyncTestNetwork
void spinAll(uavcan::MonotonicDuration duration = uavcan::MonotonicDuration::fromMSec(9))
{
assert(!duration.isNegative());
unsigned int nspins3 = duration.toMSec() / 3;
unsigned nspins3 = duration.toMSec() / 3;
nspins3 = nspins3 ? nspins3 : 2;
while (nspins3 --> 0)
{
+13 -13
View File
@@ -94,7 +94,7 @@ public:
return frame_time.frame;
}
int send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, uavcan::CanIOFlags flags)
uavcan::int16_t send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, uavcan::CanIOFlags flags)
{
assert(this);
EXPECT_TRUE(writeable); // Shall never be called when not writeable
@@ -114,8 +114,8 @@ public:
return 1;
}
int receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, uavcan::UtcTime& out_ts_utc,
uavcan::CanIOFlags& out_flags)
uavcan::int16_t receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic,
uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags)
{
assert(this);
out_flags = uavcan::CanIOFlags();
@@ -149,10 +149,10 @@ public:
// cppcheck-suppress unusedFunction
// cppcheck-suppress functionConst
int configureFilters(const uavcan::CanFilterConfig*, int) { return -1; }
uavcan::int16_t configureFilters(const uavcan::CanFilterConfig*, uavcan::uint16_t) { return -1; }
// cppcheck-suppress unusedFunction
int getNumFilters() const { return 0; }
uint64_t getErrorCount() const { return num_errors; }
uavcan::uint16_t getNumFilters() const { return 0; }
uavcan::uint64_t getErrorCount() const { return num_errors; }
};
class CanDriverMock : public uavcan::ICanDriver
@@ -168,7 +168,7 @@ public:
, select_failure(false)
{ }
int select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime deadline)
uavcan::int16_t select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime deadline)
{
assert(this);
//std::cout << "Write/read masks: " << inout_write_iface_mask << "/" << inout_read_iface_mask << std::endl;
@@ -178,15 +178,15 @@ public:
return -1;
}
const int valid_iface_mask = (1 << getNumIfaces()) - 1;
const uavcan::uint8_t valid_iface_mask = (1 << getNumIfaces()) - 1;
EXPECT_FALSE(inout_masks.write & ~valid_iface_mask);
EXPECT_FALSE(inout_masks.read & ~valid_iface_mask);
int out_write_mask = 0;
int out_read_mask = 0;
uavcan::uint8_t out_write_mask = 0;
uavcan::uint8_t out_read_mask = 0;
for (int i = 0; i < getNumIfaces(); i++)
{
const int mask = 1 << i;
const uavcan::uint8_t mask = 1 << i;
if ((inout_masks.write & mask) && ifaces.at(i).writeable)
{
out_write_mask |= mask;
@@ -222,8 +222,8 @@ public:
return 1; // This value is not being checked anyway, it just has to be greater than zero
}
uavcan::ICanIface* getIface(int iface_index) { return &ifaces.at(iface_index); }
int getNumIfaces() const { return ifaces.size(); }
uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) { return &ifaces.at(iface_index); }
uavcan::uint8_t getNumIfaces() const { return ifaces.size(); }
};
enum FrameType { STD, EXT };
+1 -1
View File
@@ -305,7 +305,7 @@ TEST(Dispatcher, Spin)
struct DispatcherTestLoopbackFrameListener : public uavcan::LoopbackFrameListenerBase
{
uavcan::RxFrame last_frame;
unsigned int count;
unsigned count;
DispatcherTestLoopbackFrameListener(uavcan::Dispatcher& dispatcher)
: uavcan::LoopbackFrameListenerBase(dispatcher)
+2 -2
View File
@@ -83,7 +83,7 @@ TEST(Frame, FrameParsing)
Frame frame;
ASSERT_FALSE(frame.parse(can));
for (unsigned int i = 0; i < sizeof(CanFrame::data); i++)
for (unsigned i = 0; i < sizeof(CanFrame::data); i++)
{
can.data[i] = i | (i << 4);
}
@@ -225,7 +225,7 @@ TEST(Frame, FrameToString)
uavcan::MonotonicTime::getMax(), uavcan::UtcTime::getMax(), 3);
uint8_t data[8];
for (unsigned int i = 0; i < sizeof(data); i++)
for (unsigned i = 0; i < sizeof(data); i++)
{
data[i] = i;
}
@@ -14,7 +14,7 @@ static uavcan::RxFrame makeFrame()
uavcan::Frame(123, uavcan::TransferTypeMessageBroadcast, 1, uavcan::NodeID::Broadcast, 0, 1, true),
tsMono(123), tsUtc(456), 0);
uint8_t data[8];
for (unsigned int i = 0; i < sizeof(data); i++)
for (unsigned i = 0; i < sizeof(data); i++)
{
data[i] = i;
}
@@ -24,7 +24,7 @@ static uavcan::RxFrame makeFrame()
static bool match(const uavcan::IncomingTransfer& it, const uavcan::RxFrame& frame,
const uint8_t* payload, unsigned int payload_len)
const uint8_t* payload, unsigned payload_len)
{
// Fields extracted from the frame struct
EXPECT_EQ(it.getMonotonicTimestamp(), frame.getMonotonicTimestamp());
@@ -34,7 +34,7 @@ static bool match(const uavcan::IncomingTransfer& it, const uavcan::RxFrame& fra
EXPECT_EQ(it.getTransferType(), frame.getTransferType());
// Payload comparison
static const unsigned int BUFLEN = 1024;
static const unsigned BUFLEN = 1024;
uint8_t buf_reference[BUFLEN], buf_actual[BUFLEN];
if (payload_len > BUFLEN)
+5 -5
View File
@@ -25,18 +25,18 @@ static bool allEqual(const T a)
template <typename T>
static void fill(const T a, int value)
{
for (unsigned int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
for (unsigned i = 0; i < sizeof(a) / sizeof(a[0]); i++)
{
a[i] = value;
}
}
static bool matchAgainst(const std::string& data, const uavcan::ITransferBuffer& tbb,
unsigned int offset = 0, int len = -1)
unsigned offset = 0, int len = -1)
{
uint8_t local_buffer[1024];
fill(local_buffer, 0);
assert((len < 0) || (sizeof(local_buffer) >= static_cast<unsigned int>(len)));
assert((len < 0) || (sizeof(local_buffer) >= static_cast<unsigned>(len)));
if (len < 0)
{
@@ -66,7 +66,7 @@ static bool matchAgainst(const std::string& data, const uavcan::ITransferBuffer&
return equals;
}
static bool matchAgainstTestData(const uavcan::ITransferBuffer& tbb, unsigned int offset, int len = -1)
static bool matchAgainstTestData(const uavcan::ITransferBuffer& tbb, unsigned offset, int len = -1)
{
return matchAgainst(TEST_DATA, tbb, offset, len);
}
@@ -213,7 +213,7 @@ static const int MGR_MAX_BUFFER_SIZE = 100;
TEST(TransferBufferManager, TestDataValidation)
{
for (unsigned int i = 0; i < sizeof(MGR_TEST_DATA) / sizeof(MGR_TEST_DATA[0]); i++)
for (unsigned i = 0; i < sizeof(MGR_TEST_DATA) / sizeof(MGR_TEST_DATA[0]); i++)
{
ASSERT_LT(MGR_MAX_BUFFER_SIZE, MGR_TEST_DATA[i].length());
}
@@ -45,7 +45,7 @@ struct RxFrameGenerator
const uavcan::TransferBufferManagerKey RxFrameGenerator::DEFAULT_KEY(42, uavcan::TransferTypeMessageBroadcast);
template <unsigned int BUFSIZE>
template <unsigned BUFSIZE>
struct Context
{
uavcan::PoolManager<1> poolmgr; // We don't need dynamic memory for this test
+1 -1
View File
@@ -162,7 +162,7 @@ TEST(TransferSender, Basic)
struct TransferSenderTestLoopbackFrameListener : public uavcan::LoopbackFrameListenerBase
{
uavcan::RxFrame last_frame;
unsigned int count;
unsigned count;
TransferSenderTestLoopbackFrameListener(uavcan::Dispatcher& dispatcher)
: uavcan::LoopbackFrameListenerBase(dispatcher)
@@ -50,7 +50,7 @@ TEST(TransferTestHelpers, MFTSerialization)
for (std::vector<uavcan::RxFrame>::const_iterator it = ser.begin(); it != ser.end(); ++it)
{
std::cout << "\t'";
for (int i = 0; i < it->getPayloadLen(); i++)
for (unsigned i = 0; i < it->getPayloadLen(); i++)
{
uint8_t ch = it->getPayloadPtr()[i];
if (ch < 0x20 || ch > 0x7E)
@@ -33,7 +33,7 @@ struct Transfer
, dst_node_id() // default is invalid
, data_type(data_type)
{
unsigned int offset = 0;
unsigned offset = 0;
while (true)
{
uint8_t buf[256];
@@ -111,7 +111,7 @@ struct Transfer
* In reality, uavcan::TransferListener should accept only specific transfer types
* which are dispatched/filtered by uavcan::Dispatcher.
*/
template <unsigned int MAX_BUF_SIZE, unsigned int NUM_STATIC_BUFS, unsigned int NUM_STATIC_RECEIVERS>
template <unsigned MAX_BUF_SIZE, unsigned NUM_STATIC_BUFS, unsigned NUM_STATIC_RECEIVERS>
class TestListener : public uavcan::TransferListener<MAX_BUF_SIZE, NUM_STATIC_BUFS, NUM_STATIC_RECEIVERS>
{
typedef uavcan::TransferListener<MAX_BUF_SIZE, NUM_STATIC_BUFS, NUM_STATIC_RECEIVERS> Base;
@@ -194,8 +194,8 @@ std::vector<uavcan::RxFrame> serializeTransfer(const Transfer& transfer)
raw_payload.insert(raw_payload.end(), transfer.payload.begin(), transfer.payload.end());
std::vector<uavcan::RxFrame> output;
unsigned int frame_index = 0;
unsigned int offset = 0;
unsigned frame_index = 0;
unsigned offset = 0;
uavcan::MonotonicTime ts_monotonic = transfer.ts_monotonic;
uavcan::UtcTime ts_utc = transfer.ts_utc;
@@ -274,7 +274,7 @@ public:
void send(const std::vector<std::vector<uavcan::RxFrame> >& sers)
{
unsigned int index = 0;
unsigned index = 0;
while (true)
{
// Sending all transfers concurrently
@@ -297,7 +297,7 @@ public:
}
}
void send(const Transfer* transfers, unsigned int num_transfers)
void send(const Transfer* transfers, unsigned num_transfers)
{
std::vector<std::vector<uavcan::RxFrame> > sers;
while (num_transfers--)