Style fix: All constants are CamelCase now

This commit is contained in:
Pavel Kirienko
2014-02-21 18:45:23 +04:00
parent a155e6f859
commit 47a2b01a14
41 changed files with 473 additions and 472 deletions
+10 -10
View File
@@ -18,10 +18,10 @@ namespace uavcan
#pragma pack(push, 1)
struct CanFrame
{
static const uint32_t MASK_STDID = 0x000007FF;
static const uint32_t MASK_EXTID = 0x1FFFFFFF;
static const uint32_t FLAG_EFF = 1 << 31; ///< Extended frame format
static const uint32_t FLAG_RTR = 1 << 30; ///< Remote transmission request
static const uint32_t MaskStdID = 0x000007FF;
static const uint32_t MaskExtID = 0x1FFFFFFF;
static const uint32_t FlagEFF = 1 << 31; ///< Extended frame format
static const uint32_t FlagRTR = 1 << 30; ///< Remote transmission request
uint32_t id; ///< CAN ID with flags (above)
uint8_t data[8];
@@ -48,21 +48,21 @@ struct CanFrame
return (id == rhs.id) && (dlc == rhs.dlc) && std::equal(data, data + dlc, rhs.data);
}
bool isExtended() const { return id & FLAG_EFF; }
bool isRemoteTransmissionRequest() const { return id & FLAG_RTR; }
bool isExtended() const { return id & FlagEFF; }
bool isRemoteTransmissionRequest() const { return id & FlagRTR; }
enum StringRepresentation { STR_TIGHT, STR_ALIGNED };
std::string toString(StringRepresentation mode = STR_TIGHT) const;
enum StringRepresentation { StrTight, StrAligned };
std::string toString(StringRepresentation mode = StrTight) const;
// TODO: priority comparison for EXT vs STD frames
bool priorityHigherThan(const CanFrame& rhs) const
{
return (id & CanFrame::MASK_EXTID) < (rhs.id & CanFrame::MASK_EXTID);
return (id & CanFrame::MaskExtID) < (rhs.id & CanFrame::MaskExtID);
}
bool priorityLowerThan(const CanFrame& rhs) const
{
return (id & CanFrame::MASK_EXTID) > (rhs.id & CanFrame::MASK_EXTID);
return (id & CanFrame::MaskExtID) > (rhs.id & CanFrame::MaskExtID);
}
};
#pragma pack(pop)
@@ -12,31 +12,31 @@ namespace uavcan
enum DataTypeKind
{
DATA_TYPE_KIND_SERVICE,
DATA_TYPE_KIND_MESSAGE,
NUM_DATA_TYPE_KINDS
DataTypeKindService,
DataTypeKindMessage,
NumDataTypeKinds
};
struct DataTypeHash
{
enum { NUM_BYTES = 16 };
uint8_t value[NUM_BYTES];
enum { NumBytes = 16 };
uint8_t value[NumBytes];
DataTypeHash()
{
std::fill(value, value + NUM_BYTES, 0);
std::fill(value, value + NumBytes, 0);
}
DataTypeHash(const uint8_t source[NUM_BYTES])
DataTypeHash(const uint8_t source[NumBytes])
{
std::copy(source, source + NUM_BYTES, value);
std::copy(source, source + NumBytes, value);
}
bool operator!=(const DataTypeHash& rhs) const { return !operator==(rhs); }
bool operator==(const DataTypeHash& rhs) const
{
return std::equal(value, value + NUM_BYTES, rhs.value);
return std::equal(value, value + NumBytes, rhs.value);
}
};
@@ -34,10 +34,10 @@ public:
};
template <int MAX_POOLS>
template <int MaxPools>
class PoolManager : public IAllocator, Noncopyable
{
IPoolAllocator* pools_[MAX_POOLS];
IPoolAllocator* pools_[MaxPools];
static bool sortComparePoolAllocators(const IPoolAllocator* a, const IPoolAllocator* b)
{
@@ -56,7 +56,7 @@ public:
{
assert(pool);
bool retval = false;
for (int i = 0; i < MAX_POOLS; i++)
for (int i = 0; i < MaxPools; i++)
{
assert(pools_[i] != pool);
if (pools_[i] == NULL || pools_[i] == pool)
@@ -67,13 +67,13 @@ public:
}
}
// We need to keep the pools in order, so that smallest blocks go first
std::sort(pools_, pools_ + MAX_POOLS, &PoolManager::sortComparePoolAllocators);
std::sort(pools_, pools_ + MaxPools, &PoolManager::sortComparePoolAllocators);
return retval;
}
void* allocate(std::size_t size)
{
for (int i = 0; i < MAX_POOLS; i++)
for (int i = 0; i < MaxPools; i++)
{
if (pools_[i] == NULL)
break;
@@ -86,7 +86,7 @@ public:
void deallocate(const void* ptr)
{
for (int i = 0; i < MAX_POOLS; i++)
for (int i = 0; i < MaxPools; i++)
{
if (pools_[i] == NULL)
{
@@ -103,37 +103,37 @@ public:
};
template <std::size_t POOL_SIZE, std::size_t BLOCK_SIZE>
template <std::size_t PoolSize, std::size_t BlockSize>
class PoolAllocator : public IPoolAllocator, Noncopyable
{
union Node
{
uint8_t data[BLOCK_SIZE];
uint8_t data[BlockSize];
Node* next;
};
Node* free_list_;
uint8_t pool_[POOL_SIZE] __attribute__((aligned(16))); // TODO: compiler-independent alignment
uint8_t pool_[PoolSize] __attribute__((aligned(16))); // TODO: compiler-independent alignment
// Noncopyable
PoolAllocator(const PoolAllocator&);
PoolAllocator& operator=(const PoolAllocator&);
public:
static const int NUM_BLOCKS = int(POOL_SIZE / BLOCK_SIZE);
static const int NumBlocks = int(PoolSize / BlockSize);
PoolAllocator()
: free_list_(reinterpret_cast<Node*>(pool_)) // TODO: alignment
{
memset(pool_, 0, POOL_SIZE);
for (int i = 0; i < NUM_BLOCKS - 1; i++)
memset(pool_, 0, PoolSize);
for (int i = 0; i < NumBlocks - 1; i++)
free_list_[i].next = free_list_ + i + 1;
free_list_[NUM_BLOCKS - 1].next = NULL;
free_list_[NumBlocks - 1].next = NULL;
}
void* allocate(std::size_t size)
{
if (free_list_ == NULL || size > BLOCK_SIZE)
if (free_list_ == NULL || size > BlockSize)
return NULL;
void* pmem = free_list_;
free_list_ = free_list_->next;
@@ -156,10 +156,10 @@ public:
{
return
ptr >= pool_ &&
ptr < (pool_ + POOL_SIZE);
ptr < (pool_ + PoolSize);
}
std::size_t getBlockSize() const { return BLOCK_SIZE; }
std::size_t getBlockSize() const { return BlockSize; }
int getNumFreeBlocks() const
{
@@ -168,7 +168,7 @@ public:
while (p)
{
num++;
assert(num <= NUM_BLOCKS);
assert(num <= NumBlocks);
p = p->next;
}
return num;
@@ -176,7 +176,7 @@ public:
int getNumUsedBlocks() const
{
return NUM_BLOCKS - getNumFreeBlocks();
return NumBlocks - getNumFreeBlocks();
}
};
@@ -15,19 +15,19 @@ namespace uavcan
* fit this size; otherwise compilation fails.
*/
#if UAVCAN_MEM_POOL_BLOCK_SIZE
enum { MEM_POOL_BLOCK_SIZE = UAVCAN_MEM_POOL_BLOCK_SIZE };
enum { MemPoolBlockSize = UAVCAN_MEM_POOL_BLOCK_SIZE };
#else
enum { MEM_POOL_BLOCK_SIZE = 32 + sizeof(void*) * 2 };
enum { MemPoolBlockSize = 32 + sizeof(void*) * 2 };
#endif
enum { MEM_POOL_ALIGNMENT = 8 };
enum { MemPoolAlignment = 8 };
typedef char _alignment_check_for_MEM_POOL_BLOCK_SIZE[((MEM_POOL_BLOCK_SIZE & (MEM_POOL_ALIGNMENT - 1)) == 0) ? 1 : -1];
typedef char _alignment_check_for_MEM_POOL_BLOCK_SIZE[((MemPoolBlockSize & (MemPoolAlignment - 1)) == 0) ? 1 : -1];
template <typename T>
struct IsDynamicallyAllocatable
{
static void check() { StaticAssert<sizeof(T) <= MEM_POOL_BLOCK_SIZE>::check(); }
static void check() { StaticAssert<sizeof(T) <= MemPoolBlockSize>::check(); }
};
}
+8 -8
View File
@@ -20,9 +20,9 @@ namespace uavcan
* Both key and value must be copyable, assignable and default constructible.
* Key must implement a comparison operator.
* Key's default constructor must initialize the object into invalid state.
* Size of Key + Value + padding must not exceed MEM_POOL_BLOCK_SIZE.
* Size of Key + Value + padding must not exceed MemPoolBlockSize.
*/
template <typename Key, typename Value, unsigned int NUM_STATIC_ENTRIES>
template <typename Key, typename Value, unsigned int NumStaticEntries>
class Map : Noncopyable
{
#pragma pack(push, 1)
@@ -37,7 +37,7 @@ class Map : Noncopyable
struct KVGroup : LinkedListNode<KVGroup>
{
enum { NUM_KV = (MEM_POOL_BLOCK_SIZE - sizeof(LinkedListNode<KVGroup>)) / sizeof(KVPair) };
enum { NUM_KV = (MemPoolBlockSize - sizeof(LinkedListNode<KVGroup>)) / sizeof(KVPair) };
KVPair kvs[NUM_KV];
KVGroup()
@@ -76,11 +76,11 @@ class Map : Noncopyable
LinkedListRoot<KVGroup> list_;
IAllocator& allocator_;
KVPair static_[NUM_STATIC_ENTRIES];
KVPair static_[NumStaticEntries];
KVPair* find(const Key& key)
{
for (unsigned int i = 0; i < NUM_STATIC_ENTRIES; i++)
for (unsigned int i = 0; i < NumStaticEntries; i++)
if (static_[i].match(key))
return static_ + i;
@@ -101,7 +101,7 @@ class Map : Noncopyable
{
// Looking for first EMPTY static entry
KVPair* stat = NULL;
for (unsigned int i = 0; i < NUM_STATIC_ENTRIES; i++)
for (unsigned int i = 0; i < NumStaticEntries; i++)
{
if (static_[i].match(Key()))
{
@@ -232,7 +232,7 @@ public:
{
unsigned int num_removed = 0;
for (unsigned int i = 0; i < NUM_STATIC_ENTRIES; i++)
for (unsigned int i = 0; i < NumStaticEntries; i++)
{
if (!static_[i].match(Key()))
{
@@ -280,7 +280,7 @@ public:
unsigned int getNumStaticPairs() const
{
unsigned int num = 0;
for (unsigned int i = 0; i < NUM_STATIC_ENTRIES; i++)
for (unsigned int i = 0; i < NumStaticEntries; i++)
if (!static_[i].match(Key()))
num++;
return num;
@@ -18,7 +18,7 @@ extern "C" void bitarray_copy(const unsigned char *src_org, int src_offset, int
class BitStream
{
enum { MAX_BYTES_PER_RW = 16 };
enum { MaxBytesPerRW = 16 };
ITransferBuffer& buf_;
int bit_offset_;
@@ -34,12 +34,12 @@ class BitStream
}
public:
enum { MAX_BITS_PER_RW = MAX_BYTES_PER_RW * 8 };
enum { MaxBitsPerRW = MaxBytesPerRW * 8 };
enum
{
RESULT_OUT_OF_BUFFER = 0,
RESULT_OK = 1
ResultOutOfBuffer = 0,
ResultOk = 1
};
BitStream(ITransferBuffer& buf)
@@ -18,10 +18,10 @@ class ScalarCodec
{
BitStream& stream_;
template <int SIZE>
static void swapByteOrder(uint8_t (&bytes)[SIZE])
template <int Size>
static void swapByteOrder(uint8_t (&bytes)[Size])
{
for (int i = 0, j = SIZE - 1; i < j; i++, j--)
for (int i = 0, j = Size - 1; i < j; i++, j--)
{
const uint8_t c = bytes[i];
bytes[i] = bytes[j];
@@ -29,9 +29,9 @@ class ScalarCodec
}
}
template <int BITLEN, int SIZE>
static typename EnableIf<(BITLEN > 8)>::Type
convertByteOrder(uint8_t (&bytes)[SIZE])
template <int BitLen, int Size>
static typename EnableIf<(BitLen > 8)>::Type
convertByteOrder(uint8_t (&bytes)[Size])
{
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN)
static const bool big_endian = BYTE_ORDER == BIG_ENDIAN;
@@ -50,50 +50,50 @@ class ScalarCodec
swapByteOrder(bytes);
}
template <int BITLEN, int SIZE>
static typename EnableIf<(BITLEN <= 8)>::Type
convertByteOrder(uint8_t (&bytes)[SIZE])
template <int BitLen, int Size>
static typename EnableIf<(BitLen <= 8)>::Type
convertByteOrder(uint8_t (&bytes)[Size])
{
(void)bytes;
}
template <int BITLEN, typename T>
static typename EnableIf<std::numeric_limits<T>::is_signed && ((sizeof(T) * 8) > BITLEN)>::Type
template <int BitLen, typename T>
static typename EnableIf<std::numeric_limits<T>::is_signed && ((sizeof(T) * 8) > BitLen)>::Type
fixTwosComplement(T& value)
{
StaticAssert<std::numeric_limits<T>::is_integer>::check(); // Not applicable to floating point types
if (value & (T(1) << (BITLEN - 1))) // The most significant bit is set --> negative
value |= 0xFFFFFFFFFFFFFFFF & ~((T(1) << BITLEN) - 1);
if (value & (T(1) << (BitLen - 1))) // The most significant bit is set --> negative
value |= 0xFFFFFFFFFFFFFFFF & ~((T(1) << BitLen) - 1);
}
template <int BITLEN, typename T>
static typename EnableIf<!std::numeric_limits<T>::is_signed || ((sizeof(T) * 8) == BITLEN)>::Type
template <int BitLen, typename T>
static typename EnableIf<!std::numeric_limits<T>::is_signed || ((sizeof(T) * 8) == BitLen)>::Type
fixTwosComplement(T& value)
{
(void)value;
}
template <int BITLEN, typename T>
static typename EnableIf<((sizeof(T) * 8) > BITLEN)>::Type
template <int BitLen, typename T>
static typename EnableIf<((sizeof(T) * 8) > BitLen)>::Type
clearExtraBits(T& value)
{
value &= (T(1) << BITLEN) - 1; // Signedness doesn't matter
value &= (T(1) << BitLen) - 1; // Signedness doesn't matter
}
template <int BITLEN, typename T>
static typename EnableIf<((sizeof(T) * 8) == BITLEN)>::Type
template <int BitLen, typename T>
static typename EnableIf<((sizeof(T) * 8) == BitLen)>::Type
clearExtraBits(T& value)
{
(void)value;
}
template <int BITLEN, typename T>
template <int BitLen, typename T>
void validate()
{
StaticAssert<((sizeof(T) * 8) >= BITLEN)>::check();
StaticAssert<(BITLEN <= BitStream::MAX_BITS_PER_RW)>::check();
StaticAssert<std::numeric_limits<T>::is_signed ? (BITLEN > 1) : 1>::check();
StaticAssert<((sizeof(T) * 8) >= BitLen)>::check();
StaticAssert<(BitLen <= BitStream::MaxBitsPerRW)>::check();
StaticAssert<std::numeric_limits<T>::is_signed ? (BitLen > 1) : 1>::check();
}
public:
@@ -101,10 +101,10 @@ public:
: stream_(stream)
{ }
template <int BITLEN, typename T>
template <int BitLen, typename T>
int encode(const T value)
{
validate<BITLEN, T>();
validate<BitLen, T>();
union ByteUnion
{
T value;
@@ -112,19 +112,19 @@ public:
} byte_union;
byte_union.value = value;
clearExtraBits<BITLEN>(byte_union.value);
convertByteOrder<BITLEN>(byte_union.bytes);
clearExtraBits<BitLen>(byte_union.value);
convertByteOrder<BitLen>(byte_union.bytes);
// Underlying stream class assumes that more significant bits have lower index, so we need to shift some.
byte_union.bytes[BITLEN / 8] <<= (8 - (BITLEN % 8)) & 7;
byte_union.bytes[BitLen / 8] <<= (8 - (BitLen % 8)) & 7;
return stream_.write(byte_union.bytes, BITLEN);
return stream_.write(byte_union.bytes, BitLen);
}
template <int BITLEN, typename T>
template <int BitLen, typename T>
int decode(T& value)
{
validate<BITLEN, T>();
validate<BitLen, T>();
union ByteUnion
{
T value;
@@ -132,14 +132,14 @@ public:
} byte_union;
std::fill(byte_union.bytes, byte_union.bytes + sizeof(T), 0);
const int read_res = stream_.read(byte_union.bytes, BITLEN);
const int read_res = stream_.read(byte_union.bytes, BitLen);
if (read_res <= 0)
return read_res;
byte_union.bytes[BITLEN / 8] >>= (8 - (BITLEN % 8)) & 7; // As in encode(), vice versa
byte_union.bytes[BitLen / 8] >>= (8 - (BitLen % 8)) & 7; // As in encode(), vice versa
convertByteOrder<BITLEN>(byte_union.bytes);
fixTwosComplement<BITLEN>(byte_union.value);
convertByteOrder<BitLen>(byte_union.bytes);
fixTwosComplement<BitLen>(byte_union.value);
value = byte_union.value;
return read_res;
@@ -29,14 +29,14 @@ struct CanRxFrame : public CanFrame
, iface_index(0)
{ }
std::string toString(StringRepresentation mode = STR_TIGHT) const;
std::string toString(StringRepresentation mode = StrTight) const;
};
class CanTxQueue : Noncopyable
{
public:
enum Qos { VOLATILE, PERSISTENT };
enum Qos { Volatile, Persistent };
struct Entry : public LinkedListNode<Entry> // Not required to be packed - fits the block in any case
{
@@ -49,7 +49,7 @@ public:
, frame(frame)
, qos(uint8_t(qos))
{
assert(qos == VOLATILE || qos == PERSISTENT);
assert(qos == Volatile || qos == Persistent);
IsDynamicallyAllocatable<Entry>::check();
}
@@ -116,13 +116,13 @@ public:
class CanIOManager : Noncopyable
{
public:
enum { MAX_IFACES = 3 };
enum { MaxIfaces = 3 };
private:
ICanDriver& driver_;
ISystemClock& sysclock_;
CanTxQueue tx_queues_[MAX_IFACES];
CanTxQueue tx_queues_[MaxIfaces];
// Noncopyable
CanIOManager(CanIOManager&);
@@ -138,9 +138,9 @@ public:
: driver_(driver)
, sysclock_(sysclock)
{
assert(driver.getNumIfaces() <= MAX_IFACES);
assert(driver.getNumIfaces() <= MaxIfaces);
// We can't initialize member array with non-default constructors in C++03
for (int i = 0; i < MAX_IFACES; i++)
for (int i = 0; i < MaxIfaces; i++)
{
tx_queues_[i].~CanTxQueue();
new (tx_queues_ + i) CanTxQueue(&allocator, &sysclock);
@@ -16,10 +16,12 @@ namespace uavcan
*/
class Crc16
{
static const uint16_t TABLE[256];
static const uint16_t Table[256];
uint16_t value_;
public:
enum { NumBytes = 2 };
Crc16()
: value_(0x0000)
{ }
@@ -37,7 +37,7 @@ class Dispatcher : Noncopyable
};
public:
enum Mode { UNIQUE_LISTENER, MANY_LISTENERS };
enum Mode { UniqueListener, ManyListeners };
bool add(TransferListenerBase* listener, Mode mode);
void remove(TransferListenerBase* listener);
@@ -31,12 +31,12 @@ public:
, transfer_type_(transfer_type)
, destination_node_id_(destination_node_id)
{
assert((transfer_type == TRANSFER_TYPE_MESSAGE_BROADCAST) == destination_node_id.isBroadcast());
assert((transfer_type == TransferTypeMessageBroadcast) == destination_node_id.isBroadcast());
/* Service response transfers must use the same Transfer ID as matching service request transfer,
* so this registry is not applicable for service response transfers at all.
*/
assert(transfer_type != TRANSFER_TYPE_SERVICE_RESPONSE);
assert(transfer_type != TransferTypeServiceResponse);
}
bool operator==(const OutgoingTransferRegistryKey& rhs) const
@@ -59,7 +59,7 @@ public:
};
template <int NUM_STATIC_ENTRIES>
template <int NumStaticEntries>
class OutgoingTransferRegistry : public IOutgoingTransferRegistry, Noncopyable
{
#pragma pack(push, 1)
@@ -88,7 +88,7 @@ class OutgoingTransferRegistry : public IOutgoingTransferRegistry, Noncopyable
}
};
Map<OutgoingTransferRegistryKey, Value, NUM_STATIC_ENTRIES> map_;
Map<OutgoingTransferRegistryKey, Value, NumStaticEntries> map_;
public:
OutgoingTransferRegistry(IAllocator& allocator)
@@ -12,15 +12,15 @@
namespace uavcan
{
enum { MAX_TRANSFER_PAYLOAD_LEN = 439 }; ///< According to the standard
enum { MaxTransferPayloadLen = 439 }; ///< According to the standard
enum TransferType
{
TRANSFER_TYPE_SERVICE_RESPONSE = 0,
TRANSFER_TYPE_SERVICE_REQUEST = 1,
TRANSFER_TYPE_MESSAGE_BROADCAST = 2,
TRANSFER_TYPE_MESSAGE_UNICAST = 3,
NUM_TRANSFER_TYPES = 4
TransferTypeServiceResponse = 0,
TransferTypeServiceRequest = 1,
TransferTypeMessageBroadcast = 2,
TransferTypeMessageUnicast = 3,
NumTransferTypes = 4
};
@@ -28,18 +28,18 @@ class NodeID
{
enum
{
VALUE_BROADCAST = 0,
VALUE_INVALID = 0xFF
ValueBroadcast = 0,
ValueInvalid = 0xFF
};
uint8_t value_;
public:
enum { BITLEN = 7 };
enum { MAX = (1 << BITLEN) - 1 };
enum { BitLen = 7 };
enum { Max = (1 << BitLen) - 1 };
static const NodeID BROADCAST;
static const NodeID Broadcast;
NodeID() : value_(VALUE_INVALID) { }
NodeID() : value_(ValueInvalid) { }
NodeID(uint8_t value)
: value_(value)
@@ -49,9 +49,9 @@ public:
uint8_t get() const { return value_; }
bool isValid() const { return value_ <= MAX; }
bool isBroadcast() const { return value_ == VALUE_BROADCAST; }
bool isUnicast() const { return (value_ <= MAX) && (value_ != VALUE_BROADCAST); }
bool isValid() const { return value_ <= Max; }
bool isBroadcast() const { return value_ == ValueBroadcast; }
bool isUnicast() const { return (value_ <= Max) && (value_ != ValueBroadcast); }
bool operator!=(NodeID rhs) const { return !operator==(rhs); }
bool operator==(NodeID rhs) const { return value_ == rhs.value_; }
@@ -63,8 +63,8 @@ class TransferID
uint8_t value_;
public:
enum { BITLEN = 3 };
enum { MAX = (1 << BITLEN) - 1 };
enum { BitLen = 3 };
enum { Max = (1 << BitLen) - 1 };
TransferID()
: value_(0)
@@ -73,7 +73,7 @@ public:
TransferID(uint8_t value) // implicit
: value_(value)
{
value_ &= MAX;
value_ &= Max;
assert(value == value_);
}
@@ -82,12 +82,12 @@ public:
void increment()
{
value_ = (value_ + 1) & MAX;
value_ = (value_ + 1) & Max;
}
uint8_t get() const
{
assert(value_ <= MAX);
assert(value_ <= Max);
return value_;
}
@@ -111,11 +111,11 @@ class Frame
bool last_frame_;
public:
enum { DATA_TYPE_ID_MAX = 1023 };
enum { INDEX_MAX = 62 }; // 63 (or 0b111111) is reserved
enum { MaxDataTypeID = 1023 };
enum { MaxIndex = 62 }; // 63 (or 0b111111) is reserved
Frame()
: transfer_type_(TransferType(NUM_TRANSFER_TYPES)) // That is invalid value
: transfer_type_(TransferType(NumTransferTypes)) // That is invalid value
, data_type_id_(0)
, payload_len_(0)
, frame_index_(0)
@@ -134,10 +134,10 @@ public:
, transfer_id_(transfer_id)
, last_frame_(last_frame)
{
assert((transfer_type == TRANSFER_TYPE_MESSAGE_BROADCAST) == dst_node_id.isBroadcast());
assert(data_type_id <= DATA_TYPE_ID_MAX);
assert((transfer_type == TransferTypeMessageBroadcast) == dst_node_id.isBroadcast());
assert(data_type_id <= MaxDataTypeID);
assert(src_node_id != dst_node_id);
assert(frame_index <= INDEX_MAX);
assert(frame_index <= MaxIndex);
}
int getMaxPayloadLen() const;
@@ -99,8 +99,8 @@ class DynamicTransferBufferManagerEntry : public TransferBufferManagerEntry,
{
struct Block : LinkedListNode<Block>
{
enum { SIZE = MEM_POOL_BLOCK_SIZE - sizeof(LinkedListNode<Block>) };
uint8_t data[SIZE];
enum { Size = MemPoolBlockSize - sizeof(LinkedListNode<Block>) };
uint8_t data[Size];
static Block* instantiate(IAllocator& allocator);
static void destroy(Block*& obj, IAllocator& allocator);
@@ -124,7 +124,7 @@ public:
, max_write_pos_(0)
, max_size_(max_size)
{
StaticAssert<(Block::SIZE > 8)>::check();
StaticAssert<(Block::Size > 8)>::check();
IsDynamicallyAllocatable<Block>::check();
IsDynamicallyAllocatable<DynamicTransferBufferManagerEntry>::check();
}
@@ -145,18 +145,18 @@ public:
/**
* Standalone static buffer
*/
template <unsigned int SIZE>
template <unsigned int Size>
class StaticTransferBuffer : public ITransferBuffer
{
uint8_t data_[SIZE];
uint8_t data_[Size];
unsigned int max_write_pos_;
public:
StaticTransferBuffer()
: max_write_pos_(0)
{
StaticAssert<(SIZE > 0)>::check();
std::fill(data_, data_ + SIZE, 0);
StaticAssert<(Size > 0)>::check();
std::fill(data_, data_ + Size, 0);
}
int read(unsigned int offset, uint8_t* data, unsigned int len) const
@@ -182,11 +182,11 @@ public:
assert(0);
return -1;
}
if (offset >= SIZE)
if (offset >= Size)
return 0;
if ((offset + len) > SIZE)
len = SIZE - offset;
assert((offset + len) <= SIZE);
if ((offset + len) > Size)
len = Size - offset;
assert((offset + len) <= Size);
std::copy(data, data + len, data_ + offset);
max_write_pos_ = std::max(offset + len, max_write_pos_);
return len;
@@ -196,7 +196,7 @@ public:
{
max_write_pos_ = 0;
#if UAVCAN_DEBUG
std::fill(data_, data_ + SIZE, 0);
std::fill(data_, data_ + Size, 0);
#endif
}
@@ -207,10 +207,10 @@ public:
/**
* Statically allocated storage for buffer manager
*/
template <unsigned int SIZE>
template <unsigned int Size>
class StaticTransferBufferManagerEntry : public TransferBufferManagerEntry
{
StaticTransferBuffer<SIZE> buf_;
StaticTransferBuffer<Size> buf_;
void resetImpl()
{
@@ -238,19 +238,19 @@ public:
// Resetting self and moving all data from the source
TransferBufferManagerEntry::reset(tbme->getKey());
const int res = tbme->read(0, buf_.getRawPtr(), SIZE);
const int res = tbme->read(0, buf_.getRawPtr(), Size);
if (res < 0)
{
TransferBufferManagerEntry::reset();
return false;
}
buf_.setMaxWritePos(res);
if (res < int(SIZE))
if (res < int(Size))
return true;
// Now we need to make sure that all data can fit the storage
uint8_t dummy = 0;
if (tbme->read(SIZE, &dummy, 1) > 0)
if (tbme->read(Size, &dummy, 1) > 0)
{
TransferBufferManagerEntry::reset(); // Damn, the buffer was too large
return false;
@@ -294,18 +294,18 @@ public:
/**
* Buffer manager implementation.
*/
template <unsigned int MAX_BUF_SIZE, unsigned int NUM_STATIC_BUFS>
template <unsigned int MaxBufSize, unsigned int NumStaticBufs>
class TransferBufferManager : public ITransferBufferManager, Noncopyable
{
typedef StaticTransferBufferManagerEntry<MAX_BUF_SIZE> StaticBufferType;
typedef StaticTransferBufferManagerEntry<MaxBufSize> StaticBufferType;
StaticBufferType static_buffers_[NUM_STATIC_BUFS];
StaticBufferType static_buffers_[NumStaticBufs];
LinkedListRoot<DynamicTransferBufferManagerEntry> dynamic_buffers_;
IAllocator& allocator_;
StaticBufferType* findFirstStatic(const TransferBufferManagerKey& key)
{
for (unsigned int i = 0; i < NUM_STATIC_BUFS; i++)
for (unsigned int i = 0; i < NumStaticBufs; i++)
{
if (static_buffers_[i].getKey() == key)
return static_buffers_ + i;
@@ -350,7 +350,7 @@ class TransferBufferManager : public ITransferBufferManager, Noncopyable
* This should never happen during normal operation because dynamic buffers are limited in growth.
*/
UAVCAN_TRACE("TransferBufferManager", "Storage optimization: MIGRATION FAILURE %s MAXSIZE %u",
dyn->getKey().toString().c_str(), MAX_BUF_SIZE);
dyn->getKey().toString().c_str(), MaxBufSize);
assert(0);
sb->reset();
break;
@@ -362,8 +362,8 @@ public:
TransferBufferManager(IAllocator& allocator)
: allocator_(allocator)
{
StaticAssert<(MAX_BUF_SIZE > 0)>::check();
StaticAssert<(NUM_STATIC_BUFS > 0)>::check();
StaticAssert<(MaxBufSize > 0)>::check();
StaticAssert<(NumStaticBufs > 0)>::check();
}
~TransferBufferManager()
@@ -403,7 +403,7 @@ public:
TransferBufferManagerEntry* tbme = findFirstStatic(TransferBufferManagerKey());
if (tbme == NULL)
{
DynamicTransferBufferManagerEntry* dyn = DynamicTransferBufferManagerEntry::instantiate(allocator_, MAX_BUF_SIZE);
DynamicTransferBufferManagerEntry* dyn = DynamicTransferBufferManagerEntry::instantiate(allocator_, MaxBufSize);
tbme = dyn;
if (dyn == NULL)
return NULL; // Epic fail.
@@ -454,7 +454,7 @@ public:
unsigned int getNumStaticBuffers() const
{
unsigned int res = 0;
for (unsigned int i = 0; i < NUM_STATIC_BUFS; i++)
for (unsigned int i = 0; i < NumStaticBufs; i++)
{
if (!static_buffers_[i].isEmpty())
res++;
@@ -95,7 +95,7 @@ class TransferListenerBase : public LinkedListNode<TransferListenerBase>
protected:
TransferListenerBase(const DataTypeDescriptor& data_type)
: data_type_(data_type)
, crc_base_(data_type.hash.value, DataTypeHash::NUM_BYTES)
, crc_base_(data_type.hash.value, DataTypeHash::NumBytes)
{ }
virtual ~TransferListenerBase() { }
@@ -114,12 +114,12 @@ public:
/**
* This class should be derived by transfer receivers (subscribers, servers, callers).
*/
template <unsigned int MAX_BUF_SIZE, unsigned int NUM_STATIC_BUFS, unsigned int NUM_STATIC_RECEIVERS>
template <unsigned int MaxBufSize, unsigned int NumStaticBufs, unsigned int NumStaticReceivers>
class TransferListener : public TransferListenerBase, Noncopyable
{
typedef TransferBufferManager<MAX_BUF_SIZE, NUM_STATIC_BUFS> BufferManager;
typedef TransferBufferManager<MaxBufSize, NumStaticBufs> BufferManager;
BufferManager bufmgr_;
Map<TransferBufferManagerKey, TransferReceiver, NUM_STATIC_RECEIVERS> receivers_;
Map<TransferBufferManagerKey, TransferReceiver, NumStaticReceivers> receivers_;
void handleFrame(const RxFrame& frame)
{
@@ -185,7 +185,7 @@ public:
, bufmgr_(allocator)
, receivers_(allocator)
{
StaticAssert<(NUM_STATIC_RECEIVERS >= NUM_STATIC_BUFS)>::check(); // Otherwise it would be meaningless
StaticAssert<(NumStaticReceivers >= NumStaticBufs)>::check(); // Otherwise it would be meaningless
}
~TransferListener()
@@ -15,15 +15,15 @@ namespace uavcan
class TransferReceiver
{
public:
enum ResultCode { RESULT_NOT_COMPLETE, RESULT_COMPLETE, RESULT_SINGLE_FRAME };
enum ResultCode { ResultNotComplete, ResultComplete, ResultSingleFrame };
static const uint32_t DEFAULT_TRANSFER_INTERVAL = 500 * 1000UL;
static const uint32_t MIN_TRANSFER_INTERVAL = 1 * 1000UL;
static const uint32_t MAX_TRANSFER_INTERVAL = 10 * 1000 * 1000UL;
static const uint32_t DefaultTransferInterval = 500 * 1000UL;
static const uint32_t MinTransferInterval = 1 * 1000UL;
static const uint32_t MaxTransferInterval = 10 * 1000 * 1000UL;
private:
enum TidRelation { TID_SAME, TID_REPEAT, TID_FUTURE };
enum { IFACE_INDEX_NOTSET = 0xFF };
enum TidRelation { TidSame, TidRepeat, TidFuture };
enum { IfaceIndexNotSet = 0xFF };
uint64_t prev_transfer_ts_monotonic_;
uint64_t this_transfer_ts_monotonic_;
@@ -35,7 +35,7 @@ private:
uint8_t iface_index_;
uint8_t next_frame_index_;
bool isInitialized() const { return iface_index_ != IFACE_INDEX_NOTSET; }
bool isInitialized() const { return iface_index_ != IfaceIndexNotSet; }
TidRelation getTidRelation(const RxFrame& frame) const;
@@ -51,10 +51,10 @@ public:
: prev_transfer_ts_monotonic_(0)
, this_transfer_ts_monotonic_(0)
, first_frame_ts_utc_(0)
, transfer_interval_(DEFAULT_TRANSFER_INTERVAL)
, transfer_interval_(DefaultTransferInterval)
, this_transfer_crc_(0)
, buffer_write_pos_(0)
, iface_index_(IFACE_INDEX_NOTSET)
, iface_index_(IfaceIndexNotSet)
, next_frame_index_(0)
{ }
@@ -16,7 +16,7 @@ namespace uavcan
class TransferSender
{
static const uint64_t DEFAULT_MAX_TRANSFER_INTERVAL = 60 * 1000 * 1000;
static const uint64_t DefaultMaxTransferInterval = 60 * 1000 * 1000;
const uint64_t max_transfer_interval_;
const DataTypeDescriptor& data_type_;
@@ -27,11 +27,11 @@ class TransferSender
public:
TransferSender(Dispatcher& dispatcher, const DataTypeDescriptor& data_type, CanTxQueue::Qos qos,
uint64_t max_transfer_interval = DEFAULT_MAX_TRANSFER_INTERVAL)
uint64_t max_transfer_interval = DefaultMaxTransferInterval)
: max_transfer_interval_(max_transfer_interval)
, data_type_(data_type)
, qos_(qos)
, crc_base_(data_type.hash.value, DataTypeHash::NUM_BYTES)
, crc_base_(data_type.hash.value, DataTypeHash::NumBytes)
, dispatcher_(dispatcher)
{ }
+2 -2
View File
@@ -12,7 +12,7 @@ namespace uavcan
* Usage:
* StaticAssert<expression>::check();
*/
template <bool VALUE>
template <bool Value>
struct StaticAssert;
template <>
@@ -44,7 +44,7 @@ template<typename T>
struct EnableIf<true, T> { typedef T Type; };
template <bool COND, typename TrueType, typename FalseType>
template <bool Condition, typename TrueType, typename FalseType>
struct StaticIf;
template <typename TrueType, typename FalseType>