Fixed inclusion loops

This commit is contained in:
Pavel Kirienko
2014-03-11 21:00:28 +04:00
parent 6eee97fb05
commit befea376c2
24 changed files with 644 additions and 627 deletions
+2 -1
View File
@@ -6,6 +6,7 @@
#include <cassert>
#include <cstring>
#include <string>
#include <stdint.h>
#include <algorithm>
#include <uavcan/internal/transport/transfer.hpp>
@@ -93,7 +94,7 @@ class DataTypeDescriptor
const char* full_name_;
public:
enum { MaxDataTypeID = Frame::MaxDataTypeID };
enum { MaxDataTypeID = 1023 };
enum { MaxFullNameLen = 80 };
DataTypeDescriptor()
@@ -9,9 +9,9 @@
#include <stdint.h>
#include <algorithm>
#include <uavcan/data_type.hpp>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/internal/fatal_error.hpp>
#include <uavcan/internal/linked_list.hpp>
#include <uavcan/internal/impl_constants.hpp>
#if UAVCAN_DEBUG
#include <uavcan/internal/debug.hpp>
#endif
@@ -8,11 +8,12 @@
#include <stdint.h>
#include <string>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/internal/transport/transfer_buffer.hpp>
namespace uavcan
{
class ITransferBuffer;
void bitarray_copy(const unsigned char *src_org, int src_offset, int src_len, unsigned char *dst_org, int dst_offset);
class BitStream
@@ -0,0 +1,120 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#pragma once
#include <cassert>
#include <algorithm>
#include <string>
#include <uavcan/internal/transport/transfer.hpp>
#include <uavcan/internal/transport/can_io.hpp>
#include <uavcan/data_type.hpp>
namespace uavcan
{
struct CanRxFrame;
class Frame
{
uint8_t payload_[sizeof(CanFrame::data)];
TransferType transfer_type_;
uint_fast16_t data_type_id_;
uint_fast8_t payload_len_;
NodeID src_node_id_;
NodeID dst_node_id_;
uint_fast8_t frame_index_;
TransferID transfer_id_;
bool last_frame_;
public:
enum { MaxIndex = 62 }; // 63 (or 0b111111) is reserved
Frame()
: transfer_type_(TransferType(NumTransferTypes)) // That is invalid value
, data_type_id_(0)
, payload_len_(0)
, frame_index_(0)
, transfer_id_(0)
, last_frame_(false)
{ }
Frame(uint_fast16_t data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
uint_fast8_t frame_index, TransferID transfer_id, bool last_frame = false)
: transfer_type_(transfer_type)
, data_type_id_(data_type_id)
, payload_len_(0)
, src_node_id_(src_node_id)
, dst_node_id_(dst_node_id)
, frame_index_(frame_index)
, transfer_id_(transfer_id)
, last_frame_(last_frame)
{
assert((transfer_type == TransferTypeMessageBroadcast) == dst_node_id.isBroadcast());
assert(data_type_id <= DataTypeDescriptor::MaxDataTypeID);
assert(src_node_id != dst_node_id);
assert(frame_index <= MaxIndex);
}
int getMaxPayloadLen() const;
int setPayload(const uint8_t* data, int len);
int getPayloadLen() const { return payload_len_; }
const uint8_t* getPayloadPtr() const { return payload_; }
TransferType getTransferType() const { return transfer_type_; }
uint_fast16_t getDataTypeID() const { return data_type_id_; }
NodeID getSrcNodeID() const { return src_node_id_; }
NodeID getDstNodeID() const { return dst_node_id_; }
TransferID getTransferID() const { return transfer_id_; }
uint_fast8_t getIndex() const { return frame_index_; }
bool isLast() const { return last_frame_; }
void makeLast() { last_frame_ = true; }
void setIndex(uint_fast8_t index) { frame_index_ = index; }
bool isFirst() const { return frame_index_ == 0; }
bool parse(const CanFrame& can_frame);
bool compile(CanFrame& can_frame) const;
bool isValid() const;
bool operator!=(const Frame& rhs) const { return !operator==(rhs); }
bool operator==(const Frame& rhs) const;
std::string toString() const;
};
class RxFrame : public Frame
{
MonotonicTime ts_mono_;
UtcTime ts_utc_;
uint8_t iface_index_;
public:
RxFrame()
: iface_index_(0)
{ }
RxFrame(const Frame& frame, MonotonicTime ts_mono, UtcTime ts_utc, uint8_t iface_index)
: ts_mono_(ts_mono)
, ts_utc_(ts_utc)
, iface_index_(iface_index)
{
*static_cast<Frame*>(this) = frame;
}
bool parse(const CanRxFrame& can_frame);
MonotonicTime getMonotonicTimestamp() const { return ts_mono_; }
UtcTime getUtcTimestamp() const { return ts_utc_; }
uint8_t getIfaceIndex() const { return iface_index_; }
std::string toString() const;
};
}
@@ -9,6 +9,7 @@
#include <uavcan/internal/map.hpp>
#include <uavcan/internal/debug.hpp>
#include <uavcan/internal/transport/transfer.hpp>
#include <uavcan/time.hpp>
namespace uavcan
{
@@ -5,15 +5,11 @@
#pragma once
#include <cassert>
#include <algorithm>
#include <string>
#include <uavcan/can_driver.hpp>
#include <stdint.h>
namespace uavcan
{
struct CanRxFrame;
enum { MaxTransferPayloadLen = 439 }; ///< According to the standard
enum { MaxSingleFrameTransferPayloadLen = 7 };
@@ -28,40 +24,6 @@ enum TransferType
};
class NodeID
{
enum
{
ValueBroadcast = 0,
ValueInvalid = 0xFF
};
uint8_t value_;
public:
enum { BitLen = 7 };
enum { Max = (1 << BitLen) - 1 };
static const NodeID Broadcast;
NodeID() : value_(ValueInvalid) { }
NodeID(uint8_t value)
: value_(value)
{
assert(isValid());
}
uint8_t get() const { return value_; }
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_; }
};
class TransferID
{
uint8_t value_;
@@ -102,106 +64,37 @@ public:
};
class Frame
class NodeID
{
uint8_t payload_[sizeof(CanFrame::data)];
TransferType transfer_type_;
uint_fast16_t data_type_id_;
uint_fast8_t payload_len_;
NodeID src_node_id_;
NodeID dst_node_id_;
uint_fast8_t frame_index_;
TransferID transfer_id_;
bool last_frame_;
enum
{
ValueBroadcast = 0,
ValueInvalid = 0xFF
};
uint8_t value_;
public:
enum { MaxDataTypeID = 1023 };
enum { MaxIndex = 62 }; // 63 (or 0b111111) is reserved
enum { BitLen = 7 };
enum { Max = (1 << BitLen) - 1 };
Frame()
: transfer_type_(TransferType(NumTransferTypes)) // That is invalid value
, data_type_id_(0)
, payload_len_(0)
, frame_index_(0)
, transfer_id_(0)
, last_frame_(false)
{ }
static const NodeID Broadcast;
Frame(uint_fast16_t data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
uint_fast8_t frame_index, TransferID transfer_id, bool last_frame = false)
: transfer_type_(transfer_type)
, data_type_id_(data_type_id)
, payload_len_(0)
, src_node_id_(src_node_id)
, dst_node_id_(dst_node_id)
, frame_index_(frame_index)
, transfer_id_(transfer_id)
, last_frame_(last_frame)
NodeID() : value_(ValueInvalid) { }
NodeID(uint8_t value)
: value_(value)
{
assert((transfer_type == TransferTypeMessageBroadcast) == dst_node_id.isBroadcast());
assert(data_type_id <= MaxDataTypeID);
assert(src_node_id != dst_node_id);
assert(frame_index <= MaxIndex);
assert(isValid());
}
int getMaxPayloadLen() const;
int setPayload(const uint8_t* data, int len);
uint8_t get() const { return value_; }
int getPayloadLen() const { return payload_len_; }
const uint8_t* getPayloadPtr() const { return payload_; }
bool isValid() const { return value_ <= Max; }
bool isBroadcast() const { return value_ == ValueBroadcast; }
bool isUnicast() const { return (value_ <= Max) && (value_ != ValueBroadcast); }
TransferType getTransferType() const { return transfer_type_; }
uint_fast16_t getDataTypeID() const { return data_type_id_; }
NodeID getSrcNodeID() const { return src_node_id_; }
NodeID getDstNodeID() const { return dst_node_id_; }
TransferID getTransferID() const { return transfer_id_; }
uint_fast8_t getIndex() const { return frame_index_; }
bool isLast() const { return last_frame_; }
void makeLast() { last_frame_ = true; }
void setIndex(uint_fast8_t index) { frame_index_ = index; }
bool isFirst() const { return frame_index_ == 0; }
bool parse(const CanFrame& can_frame);
bool compile(CanFrame& can_frame) const;
bool isValid() const;
bool operator!=(const Frame& rhs) const { return !operator==(rhs); }
bool operator==(const Frame& rhs) const;
std::string toString() const;
};
class RxFrame : public Frame
{
MonotonicTime ts_mono_;
UtcTime ts_utc_;
uint8_t iface_index_;
public:
RxFrame()
: iface_index_(0)
{ }
RxFrame(const Frame& frame, MonotonicTime ts_mono, UtcTime ts_utc, uint8_t iface_index)
: ts_mono_(ts_mono)
, ts_utc_(ts_utc)
, iface_index_(iface_index)
{
*static_cast<Frame*>(this) = frame;
}
bool parse(const CanRxFrame& can_frame);
MonotonicTime getMonotonicTimestamp() const { return ts_mono_; }
UtcTime getUtcTimestamp() const { return ts_utc_; }
uint8_t getIfaceIndex() const { return iface_index_; }
std::string toString() const;
bool operator!=(NodeID rhs) const { return !operator==(rhs); }
bool operator==(NodeID rhs) const { return value_ == rhs.value_; }
};
}
@@ -7,7 +7,7 @@
#include <stdint.h>
#include <algorithm>
#include <limits>
#include <uavcan/internal/transport/transfer.hpp>
#include <uavcan/internal/transport/frame.hpp>
#include <uavcan/internal/linked_list.hpp>
#include <uavcan/internal/dynamic_memory.hpp>
#include <uavcan/internal/impl_constants.hpp>
@@ -5,7 +5,7 @@
#pragma once
#include <cstdlib>
#include <uavcan/internal/transport/transfer.hpp>
#include <uavcan/internal/transport/frame.hpp>
#include <uavcan/internal/transport/transfer_buffer.hpp>
namespace uavcan
+19 -11
View File
@@ -10,15 +10,8 @@
#include <sstream>
#include <cstdio>
#include <uavcan/util/compile_time.hpp>
#include <uavcan/Timestamp.hpp>
// TODO: Fix inclusion loops!
namespace uavcan
{
struct Timestamp_;
typedef Timestamp_ Timestamp;
}
namespace uavcan
{
@@ -182,9 +175,24 @@ class UtcTime : public TimeBase<UtcTime, UtcDuration>
{
public:
UtcTime() { }
UtcTime(const Timestamp& ts); // Implicit
UtcTime& operator=(const Timestamp& ts);
operator Timestamp() const;
UtcTime(const Timestamp& ts) // Implicit
{
operator=(ts);
}
UtcTime& operator=(const Timestamp& ts)
{
*this = fromUSec(ts.husec * Timestamp::USEC_PER_LSB);
return *this;
}
operator Timestamp() const
{
Timestamp ts;
ts.husec = toUSec() / Timestamp::USEC_PER_LSB;
return ts;
}
};
@@ -4,8 +4,6 @@
#pragma once
#include <cassert>
namespace uavcan
{
/**