mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-30 18:24:06 +08:00
65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
/*
|
|
* 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_>
|
|
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 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
|