SubNode<>

This commit is contained in:
Pavel Kirienko
2015-06-08 12:37:31 +03:00
parent fa2829a04a
commit e24fa5f236
4 changed files with 68 additions and 1 deletions
@@ -6,6 +6,7 @@
#define UAVCAN_NODE_ABSTRACT_NODE_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/dynamic_memory.hpp>
#include <uavcan/node/scheduler.hpp>
namespace uavcan
-1
View File
@@ -8,7 +8,6 @@
#include <cassert>
#include <uavcan/error.hpp>
#include <uavcan/build_config.hpp>
#include <uavcan/dynamic_memory.hpp>
#include <uavcan/node/abstract_node.hpp>
// High-level functionality available by default
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2015 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#ifndef UAVCAN_SUB_NODE_NODE_HPP_INCLUDED
#define UAVCAN_SUB_NODE_NODE_HPP_INCLUDED
#include <cassert>
#include <uavcan/build_config.hpp>
#include <uavcan/node/abstract_node.hpp>
#if UAVCAN_TINY
# error "This functionality is not available in tiny mode"
#endif
namespace uavcan
{
/**
* This node object can be used in multiprocess UAVCAN nodes.
* Please refer to the @ref Node<> for documentation concerning the template arguments; refer to the tutorials
* to lean how to use libuavcan in multiprocess applications.
*/
template <std::size_t MemPoolSize_,
unsigned OutgoingTransferRegistryStaticEntries = 10
>
class UAVCAN_EXPORT SubNode : public INode
{
enum
{
MemPoolSize = (MemPoolSize_ < std::size_t(MemPoolBlockSize)) ? std::size_t(MemPoolBlockSize) : MemPoolSize_
};
typedef PoolAllocator<MemPoolSize, MemPoolBlockSize> Allocator;
Allocator pool_allocator_;
OutgoingTransferRegistry<OutgoingTransferRegistryStaticEntries> outgoing_trans_reg_;
Scheduler scheduler_;
uint64_t internal_failure_cnt_;
protected:
virtual void registerInternalFailure(const char* msg)
{
internal_failure_cnt_++;
UAVCAN_TRACE("Node", "Internal failure: %s", msg);
(void)msg;
}
public:
SubNode(ICanDriver& can_driver, ISystemClock& system_clock) :
outgoing_trans_reg_(pool_allocator_),
scheduler_(can_driver, pool_allocator_, system_clock, outgoing_trans_reg_),
internal_failure_cnt_(0)
{ }
virtual Allocator& getAllocator() { return pool_allocator_; }
virtual Scheduler& getScheduler() { return scheduler_; }
virtual const Scheduler& getScheduler() const { return scheduler_; }
uint64_t getInternalFailureCount() const { return internal_failure_cnt_; }
};
}
#endif // Include guard
+1
View File
@@ -4,6 +4,7 @@
#include <gtest/gtest.h>
#include <uavcan/node/node.hpp>
#include <uavcan/node/sub_node.hpp> // Compilability test
#include <uavcan/protocol/node_status_monitor.hpp>
#include "test_node.hpp"
#include "../protocol/helpers.hpp"