From d4e49d518a13c01bf15c6c34f6e64bff1fec80a8 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 28 May 2015 13:49:01 +0300 Subject: [PATCH] First step towards introducing the global RX object buffer --- .../include/uavcan/node/marshal_buffer.hpp | 11 ++++--- libuavcan/include/uavcan/node/node.hpp | 31 ++++++++++--------- libuavcan/src/node/uc_generic_publisher.cpp | 4 +-- libuavcan/test/node/test_node.hpp | 2 +- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/libuavcan/include/uavcan/node/marshal_buffer.hpp b/libuavcan/include/uavcan/node/marshal_buffer.hpp index 35a7e0885a..3dad463a83 100644 --- a/libuavcan/include/uavcan/node/marshal_buffer.hpp +++ b/libuavcan/include/uavcan/node/marshal_buffer.hpp @@ -18,7 +18,8 @@ class UAVCAN_EXPORT IMarshalBuffer : public ITransferBuffer { public: virtual const uint8_t* getDataPtr() const = 0; - virtual unsigned getDataLength() const = 0; + virtual unsigned getMaxWritePos() const = 0; + virtual unsigned getSize() const = 0; }; /** @@ -43,10 +44,8 @@ public: /** * Default implementation of marshal buffer provider. - * This implementation provides the buffer large enough to - * serialize any UAVCAN data structure. */ -template +template class UAVCAN_EXPORT MarshalBufferProvider : public IMarshalBufferProvider { class Buffer : public IMarshalBuffer @@ -65,7 +64,9 @@ class UAVCAN_EXPORT MarshalBufferProvider : public IMarshalBufferProvider virtual const uint8_t* getDataPtr() const { return buf_.getRawPtr(); } - virtual unsigned getDataLength() const { return buf_.getMaxWritePos(); } + virtual unsigned getMaxWritePos() const { return buf_.getMaxWritePos(); } + + virtual unsigned getSize() const { return MaxSize_; } public: void reset() { buf_.reset(); } diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index 65b478b7a7..5175bd2115 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -47,21 +47,24 @@ namespace uavcan * be allocated in the memory pool if needed. * Default value is acceptable for any use case. * - * @tparam OutgoingTransferMaxPayloadLen Maximum outgoing transfer payload length. - * It's pointless to make this value larger than - * @ref MaxTransferPayloadLen, which is default. - * Note that in tiny mode the default value is actually - * smaller than @ref MaxTransferPayloadLen (may cause - * run-time failures). + * @tparam MarshalBufferSize Size of the marshal buffer, that is used to provide short-term temporary storage for: + * 1. Serialized data for TX transfers; + * 2. De-serialized data for RX transfers. + * The buffer must be large enough to accommodate largest serialized TX transfer and + * largest de-serialized RX data structure. The former value is constant for UAVCAN, the + * latter is platform-dependent (depends on the field padding, memory alignment, pointer + * size, etc.). + * The default value should be enough for all use cases on virtually all platforms. + * If this value is not large enough, transport objects (such as Subscriber<>, + * Publisher<>, Service*<>) will be failing at run time during initialization. */ template class UAVCAN_EXPORT Node : public INode { @@ -73,7 +76,7 @@ class UAVCAN_EXPORT Node : public INode typedef PoolAllocator Allocator; Allocator pool_allocator_; - MarshalBufferProvider marsh_buf_; + MarshalBufferProvider marsh_buf_; OutgoingTransferRegistry outgoing_trans_reg_; Scheduler scheduler_; @@ -265,9 +268,8 @@ public: // ---------------------------------------------------------------------------- -template -int Node::start( +template +int Node::start( const TransferPriority priority) { if (started_) @@ -313,9 +315,8 @@ fail: #if !UAVCAN_TINY -template -int Node:: +template +int Node:: checkNetworkCompatibility(NetworkCompatibilityCheckResult& result) { if (!started_) diff --git a/libuavcan/src/node/uc_generic_publisher.cpp b/libuavcan/src/node/uc_generic_publisher.cpp index 3ebc7bd699..09f361f5b0 100644 --- a/libuavcan/src/node/uc_generic_publisher.cpp +++ b/libuavcan/src/node/uc_generic_publisher.cpp @@ -47,12 +47,12 @@ int GenericPublisherBase::genericPublish(const IMarshalBuffer& buffer, TransferT { if (tid) { - return sender_->send(buffer.getDataPtr(), buffer.getDataLength(), getTxDeadline(), + return sender_->send(buffer.getDataPtr(), buffer.getMaxWritePos(), getTxDeadline(), blocking_deadline, transfer_type, dst_node_id, *tid); } else { - return sender_->send(buffer.getDataPtr(), buffer.getDataLength(), getTxDeadline(), + return sender_->send(buffer.getDataPtr(), buffer.getMaxWritePos(), getTxDeadline(), blocking_deadline, transfer_type, dst_node_id); } } diff --git a/libuavcan/test/node/test_node.hpp b/libuavcan/test/node/test_node.hpp index 543f99a50d..5a943ae6da 100644 --- a/libuavcan/test/node/test_node.hpp +++ b/libuavcan/test/node/test_node.hpp @@ -20,7 +20,7 @@ struct TestNode : public uavcan::INode { uavcan::PoolAllocator pool; uavcan::PoolManager<1> poolmgr; - uavcan::MarshalBufferProvider<> buffer_provider; + uavcan::MarshalBufferProvider<512> buffer_provider; uavcan::OutgoingTransferRegistry<8> otr; uavcan::Scheduler scheduler; uint64_t internal_failure_count;