mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 02:13:33 +08:00
Added config macro UAVCAN_TOSTRING
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
@@ -155,10 +154,12 @@ public:
|
||||
bool match(DataTypeKind kind, const char* name) const;
|
||||
bool match(DataTypeKind kind, DataTypeID id) const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
bool operator!=(const DataTypeDescriptor& rhs) const { return !operator==(rhs); }
|
||||
bool operator==(const DataTypeDescriptor& rhs) const;
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/driver/system_clock.hpp>
|
||||
@@ -58,8 +57,10 @@ struct UAVCAN_EXPORT CanFrame
|
||||
bool isRemoteTransmissionRequest() const { return id & FlagRTR; }
|
||||
bool isErrorFrame() const { return id & FlagERR; }
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
enum StringRepresentation { StrTight, StrAligned };
|
||||
std::string toString(StringRepresentation mode = StrTight) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* CAN frames arbitration rules, particularly STD vs EXT:
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <limits>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/util/compile_time.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
@@ -60,6 +60,18 @@
|
||||
# define UAVCAN_EXPORT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* It might make sense to remove toString() methods for an embedded system
|
||||
*/
|
||||
#ifndef UAVCAN_TOSTRING
|
||||
# define UAVCAN_TOSTRING 1
|
||||
#endif
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
# include <string>
|
||||
# include <cstdio>
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/util/compile_time.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
@@ -65,7 +64,9 @@ public:
|
||||
int write(const uint8_t* bytes, const int bitlen);
|
||||
int read(uint8_t* bytes, const int bitlen);
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <cstdio>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/util/compile_time.hpp>
|
||||
#include <uavcan/Timestamp.hpp>
|
||||
@@ -83,7 +82,9 @@ public:
|
||||
|
||||
enum { StringBufSize = 32 };
|
||||
void toString(char buf[StringBufSize]) const;
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -164,7 +165,9 @@ public:
|
||||
|
||||
enum { StringBufSize = 32 };
|
||||
void toString(char buf[StringBufSize]) const;
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -230,6 +233,8 @@ void TimeBase<T, D>::toString(char buf[StringBufSize]) const
|
||||
}
|
||||
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
|
||||
template <typename D>
|
||||
std::string DurationBase<D>::toString() const
|
||||
{
|
||||
@@ -246,6 +251,8 @@ std::string TimeBase<T, D>::toString() const
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template <typename Stream, typename D>
|
||||
UAVCAN_EXPORT
|
||||
|
||||
@@ -31,7 +31,9 @@ struct UAVCAN_EXPORT CanRxFrame : public CanFrame
|
||||
: iface_index(0)
|
||||
{ }
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString(StringRepresentation mode = StrTight) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -66,7 +68,9 @@ public:
|
||||
bool qosHigherThan(const Entry& rhs) const { return qosHigherThan(rhs.frame, Qos(rhs.qos)); }
|
||||
bool qosLowerThan(const Entry& rhs) const { return qosLowerThan(rhs.frame, Qos(rhs.qos)); }
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <uavcan/transport/transfer.hpp>
|
||||
#include <uavcan/transport/can_io.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
@@ -82,7 +81,9 @@ public:
|
||||
bool operator!=(const Frame& rhs) const { return !operator==(rhs); }
|
||||
bool operator==(const Frame& rhs) const;
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -112,7 +113,9 @@ public:
|
||||
|
||||
uint8_t getIfaceIndex() const { return iface_index_; }
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <uavcan/stdint.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/map.hpp>
|
||||
@@ -52,7 +51,9 @@ public:
|
||||
(destination_node_id_ == rhs.destination_node_id_);
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
UAVCAN_PACKED_END
|
||||
|
||||
|
||||
@@ -61,7 +61,9 @@ public:
|
||||
NodeID getNodeID() const { return node_id_; }
|
||||
TransferType getTransferType() const { return TransferType(transfer_type_); }
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string toString() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <uavcan/driver/can.hpp>
|
||||
|
||||
@@ -57,6 +56,7 @@ bool CanFrame::priorityHigherThan(const CanFrame& rhs) const
|
||||
return clean_id < rhs_clean_id;
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string CanFrame::toString(StringRepresentation mode) const
|
||||
{
|
||||
using namespace std; // For snprintf()
|
||||
@@ -115,5 +115,6 @@ std::string CanFrame::toString(StringRepresentation mode) const
|
||||
}
|
||||
return std::string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <uavcan/marshal/bit_stream.hpp>
|
||||
#include <uavcan/transport/transfer_buffer.hpp>
|
||||
|
||||
@@ -73,6 +72,7 @@ int BitStream::read(uint8_t* bytes, const int bitlen)
|
||||
return ResultOk;
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string BitStream::toString() const
|
||||
{
|
||||
std::string out;
|
||||
@@ -97,5 +97,6 @@ std::string BitStream::toString() const
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <uavcan/transport/can_io.hpp>
|
||||
@@ -15,6 +14,7 @@ namespace uavcan
|
||||
/*
|
||||
* CanRxFrame
|
||||
*/
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string CanRxFrame::toString(StringRepresentation mode) const
|
||||
{
|
||||
std::string out = CanFrame::toString(mode);
|
||||
@@ -25,6 +25,7 @@ std::string CanRxFrame::toString(StringRepresentation mode) const
|
||||
out += '0' + iface_index;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* CanTxQueue::Entry
|
||||
@@ -57,6 +58,7 @@ bool CanTxQueue::Entry::qosLowerThan(const CanFrame& rhs_frame, Qos rhs_qos) con
|
||||
return frame.priorityLowerThan(rhs_frame);
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string CanTxQueue::Entry::toString() const
|
||||
{
|
||||
std::string str_qos;
|
||||
@@ -78,6 +80,7 @@ std::string CanTxQueue::Entry::toString() const
|
||||
}
|
||||
return str_qos + frame.toString();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* CanTxQueue
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <uavcan/transport/frame.hpp>
|
||||
#include <uavcan/transport/can_io.hpp>
|
||||
|
||||
@@ -194,6 +193,7 @@ bool Frame::operator==(const Frame& rhs) const
|
||||
std::equal(payload_, payload_ + payload_len_, rhs.payload_);
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string Frame::toString() const
|
||||
{
|
||||
using namespace std; // For snprintf()
|
||||
@@ -223,6 +223,7 @@ std::string Frame::toString() const
|
||||
ofs += snprintf(buf + ofs, BUFLEN - ofs, "]");
|
||||
return std::string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RxFrame
|
||||
@@ -244,6 +245,7 @@ bool RxFrame::parse(const CanRxFrame& can_frame)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string RxFrame::toString() const
|
||||
{
|
||||
std::string out = Frame::toString();
|
||||
@@ -254,5 +256,6 @@ std::string RxFrame::toString() const
|
||||
out += '0' + iface_index_;
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <uavcan/transport/outgoing_transfer_registry.hpp>
|
||||
|
||||
namespace uavcan
|
||||
@@ -10,6 +9,7 @@ namespace uavcan
|
||||
/*
|
||||
* OutgoingTransferRegistryKey
|
||||
*/
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string OutgoingTransferRegistryKey::toString() const
|
||||
{
|
||||
using namespace std;
|
||||
@@ -18,5 +18,6 @@ std::string OutgoingTransferRegistryKey::toString() const
|
||||
int(data_type_id_.get()), int(transfer_type_), int(destination_node_id_.get()));
|
||||
return std::string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <uavcan/transport/frame.hpp>
|
||||
#include <uavcan/transport/can_io.hpp>
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <uavcan/transport/transfer_buffer.hpp>
|
||||
|
||||
namespace uavcan
|
||||
@@ -13,6 +11,7 @@ namespace uavcan
|
||||
/*
|
||||
* TransferBufferManagerKey
|
||||
*/
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string TransferBufferManagerKey::toString() const
|
||||
{
|
||||
using namespace std; // For snprintf()
|
||||
@@ -20,6 +19,7 @@ std::string TransferBufferManagerKey::toString() const
|
||||
snprintf(buf, sizeof(buf), "nid=%i tt=%i", int(node_id_.get()), int(transfer_type_));
|
||||
return std::string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* DynamicTransferBuffer::Block
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <uavcan/debug.hpp>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <uavcan/data_type.hpp>
|
||||
#include <uavcan/transport/crc.hpp>
|
||||
@@ -54,6 +52,7 @@ bool DataTypeDescriptor::match(DataTypeKind kind, DataTypeID id) const
|
||||
return (kind_ == kind) && (id_ == id);
|
||||
}
|
||||
|
||||
#if UAVCAN_TOSTRING
|
||||
std::string DataTypeDescriptor::toString() const
|
||||
{
|
||||
char kindch = '?';
|
||||
@@ -80,6 +79,7 @@ std::string DataTypeDescriptor::toString() const
|
||||
static_cast<unsigned long long>(signature_.get()));
|
||||
return std::string(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool DataTypeDescriptor::operator==(const DataTypeDescriptor& rhs) const
|
||||
{
|
||||
|
||||
@@ -17,7 +17,8 @@ CPPSRC = src/main.cpp src/dummy.cpp
|
||||
UDEFS = -DUAVCAN_STM32_CHIBIOS=1 \
|
||||
-DUAVCAN_STM32_TIMER_NUMBER=6 \
|
||||
-DUAVCAN_STM32_DEBUG=1 \
|
||||
-DUAVCAN_MEM_POOL_BLOCK_SIZE=56
|
||||
-DUAVCAN_MEM_POOL_BLOCK_SIZE=56 \
|
||||
-DUAVCAN_TOSTRING=0
|
||||
|
||||
include ../../../libuavcan/include.mk
|
||||
CPPSRC += $(LIBUAVCAN_SRC)
|
||||
|
||||
Reference in New Issue
Block a user