mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 04:33:33 +08:00
Refactored the dynamic node ID allocation server: added a new class AbstractServer, which is inherited by CentralizedServer and DistributedServer. This change allowed to move the data and logic that is common to both types of servers to a single location. In the next step this will be used to add more complex common logic.
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
|
||||
#include <uavcan/build_config.hpp>
|
||||
#include <uavcan/debug.hpp>
|
||||
#include <uavcan/protocol/dynamic_node_id_server/allocation_request_manager.hpp>
|
||||
#include <uavcan/protocol/dynamic_node_id_server/node_discoverer.hpp>
|
||||
#include <uavcan/protocol/dynamic_node_id_server/abstract_server.hpp>
|
||||
#include <uavcan/protocol/dynamic_node_id_server/node_id_selector.hpp>
|
||||
#include <uavcan/protocol/dynamic_node_id_server/storage_marshaller.hpp>
|
||||
#include <uavcan/protocol/dynamic_node_id_server/centralized/storage.hpp>
|
||||
@@ -26,15 +25,8 @@ namespace centralized
|
||||
*
|
||||
* This version is suitable only for simple non-critical systems.
|
||||
*/
|
||||
class Server : IAllocationRequestHandler
|
||||
, INodeDiscoveryHandler
|
||||
class Server : public AbstractServer
|
||||
{
|
||||
UniqueID own_unique_id_;
|
||||
|
||||
INode& node_;
|
||||
IEventTracer& tracer_;
|
||||
AllocationRequestManager allocation_request_manager_;
|
||||
NodeDiscoverer node_discoverer_;
|
||||
Storage storage_;
|
||||
|
||||
/*
|
||||
@@ -128,10 +120,7 @@ public:
|
||||
Server(INode& node,
|
||||
IStorageBackend& storage,
|
||||
IEventTracer& tracer)
|
||||
: node_(node)
|
||||
, tracer_(tracer)
|
||||
, allocation_request_manager_(node, tracer, *this)
|
||||
, node_discoverer_(node, tracer, *this)
|
||||
: AbstractServer(node, tracer)
|
||||
, storage_(storage)
|
||||
{ }
|
||||
|
||||
@@ -147,13 +136,20 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Common logic
|
||||
*/
|
||||
res = AbstractServer::init(own_unique_id, priority);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Making sure that the server is started with the same node ID
|
||||
*/
|
||||
own_unique_id_ = own_unique_id;
|
||||
|
||||
{
|
||||
const NodeID stored_own_node_id = storage_.getNodeIDForUniqueID(own_unique_id_);
|
||||
const NodeID stored_own_node_id = storage_.getNodeIDForUniqueID(getOwnUniqueID());
|
||||
if (stored_own_node_id.isValid())
|
||||
{
|
||||
if (stored_own_node_id != node_.getNodeID())
|
||||
@@ -163,7 +159,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
res = storage_.add(node_.getNodeID(), own_unique_id_);
|
||||
res = storage_.add(node_.getNodeID(), getOwnUniqueID());
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
@@ -171,21 +167,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Misc
|
||||
*/
|
||||
res = allocation_request_manager_.init(priority);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
res = node_discoverer_.init(priority);
|
||||
if (res < 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user