From 8ea708b77ee7d5f4be3854c78182c06aebfe733e Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 9 May 2015 11:55:36 +0300 Subject: [PATCH] Renamed DynamicNodeIDClient --- ..._client.hpp => dynamic_node_id_client.hpp} | 14 ++++---- ...ient.cpp => uc_dynamic_node_id_client.cpp} | 32 +++++++++---------- .../dynamic_node_id_allocation_server.cpp | 6 ++-- ..._client.cpp => dynamic_node_id_client.cpp} | 10 +++--- 4 files changed, 30 insertions(+), 32 deletions(-) rename libuavcan/include/uavcan/protocol/{dynamic_node_id_allocation_client.hpp => dynamic_node_id_client.hpp} (89%) rename libuavcan/src/protocol/{uc_dynamic_node_id_allocation_client.cpp => uc_dynamic_node_id_client.cpp} (79%) rename libuavcan/test/protocol/{dynamic_node_id_allocation_client.cpp => dynamic_node_id_client.cpp} (95%) diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_client.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp similarity index 89% rename from libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_client.hpp rename to libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp index 0833ffe24e..00d654d558 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_client.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_client.hpp @@ -2,8 +2,8 @@ * Copyright (C) 2015 Pavel Kirienko */ -#ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_CLIENT_HPP_INCLUDED -#define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_CLIENT_HPP_INCLUDED +#ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_CLIENT_HPP_INCLUDED +#define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_CLIENT_HPP_INCLUDED #include #include @@ -26,10 +26,10 @@ namespace uavcan * * Once dynamic allocation is complete (or not needed anymore), the object can be deleted. */ -class DynamicNodeIDAllocationClient : private TimerBase +class DynamicNodeIDClient : private TimerBase { - typedef MethodBinder&)> AllocationCallback; @@ -48,7 +48,7 @@ class DynamicNodeIDAllocationClient : private TimerBase void handleAllocation(const ReceivedDataStructure& msg); public: - DynamicNodeIDAllocationClient(INode& node) + DynamicNodeIDClient(INode& node) : TimerBase(node) , dnida_pub_(node) , dnida_sub_(node) @@ -91,4 +91,4 @@ public: } -#endif // UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_ALLOCATION_CLIENT_HPP_INCLUDED +#endif // UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_CLIENT_HPP_INCLUDED diff --git a/libuavcan/src/protocol/uc_dynamic_node_id_allocation_client.cpp b/libuavcan/src/protocol/uc_dynamic_node_id_client.cpp similarity index 79% rename from libuavcan/src/protocol/uc_dynamic_node_id_allocation_client.cpp rename to libuavcan/src/protocol/uc_dynamic_node_id_client.cpp index 915c4b3b56..f6150ed3ac 100644 --- a/libuavcan/src/protocol/uc_dynamic_node_id_allocation_client.cpp +++ b/libuavcan/src/protocol/uc_dynamic_node_id_client.cpp @@ -2,19 +2,19 @@ * Copyright (C) 2015 Pavel Kirienko */ -#include +#include namespace uavcan { -void DynamicNodeIDAllocationClient::terminate() +void DynamicNodeIDClient::terminate() { - UAVCAN_TRACE("DynamicNodeIDAllocationClient", "Client terminated"); + UAVCAN_TRACE("DynamicNodeIDClient", "Client terminated"); stop(); dnida_sub_.stop(); } -void DynamicNodeIDAllocationClient::handleTimerEvent(const TimerEvent&) +void DynamicNodeIDClient::handleTimerEvent(const TimerEvent&) { // This method implements Rule B UAVCAN_ASSERT(preferred_node_id_.isValid()); @@ -35,17 +35,16 @@ void DynamicNodeIDAllocationClient::handleTimerEvent(const TimerEvent&) UAVCAN_ASSERT(equal(msg.unique_id.begin(), msg.unique_id.end(), unique_id_)); // Broadcasting - UAVCAN_TRACE("DynamicNodeIDAllocationClient", "Broadcasting 1st stage: preferred ID: %d", + UAVCAN_TRACE("DynamicNodeIDClient", "Broadcasting 1st stage: preferred ID: %d", static_cast(preferred_node_id_.get())); const int res = dnida_pub_.broadcast(msg); if (res < 0) { - dnida_pub_.getNode().registerInternalFailure("DynamicNodeIDAllocationClient request failed"); + dnida_pub_.getNode().registerInternalFailure("DynamicNodeIDClient request failed"); } } -void DynamicNodeIDAllocationClient::handleAllocation( - const ReceivedDataStructure& msg) +void DynamicNodeIDClient::handleAllocation(const ReceivedDataStructure& msg) { /* * TODO This method can blow the stack easily @@ -59,7 +58,7 @@ void DynamicNodeIDAllocationClient::handleAllocation( } startPeriodic(getPeriod()); // Restarting the timer - Rule C - UAVCAN_TRACE("DynamicNodeIDAllocationClient", "Request timer reset because of Allocation message from %d", + UAVCAN_TRACE("DynamicNodeIDClient", "Request timer reset because of Allocation message from %d", static_cast(msg.getSrcNodeID().get())); // Rule D @@ -88,13 +87,12 @@ void DynamicNodeIDAllocationClient::handleAllocation( unique_id_ + msg.unique_id.size())); // Broadcasting the response - UAVCAN_TRACE("DynamicNodeIDAllocationClient", - "Broadcasting 2nd stage: preferred ID: %d, size of unique ID: %d", + UAVCAN_TRACE("DynamicNodeIDClient", "Broadcasting 2nd stage: preferred ID: %d, size of unique ID: %d", static_cast(preferred_node_id_.get()), static_cast(second_stage.unique_id.size())); const int res = dnida_pub_.broadcast(second_stage); if (res < 0) { - dnida_pub_.getNode().registerInternalFailure("DynamicNodeIDAllocationClient request failed"); + dnida_pub_.getNode().registerInternalFailure("DynamicNodeIDClient request failed"); } } @@ -106,16 +104,16 @@ void DynamicNodeIDAllocationClient::handleAllocation( { allocated_node_id_ = msg.node_id; allocator_node_id_ = msg.getSrcNodeID(); - UAVCAN_TRACE("DynamicNodeIDAllocationClient", "Allocation complete, node ID %d provided by %d", + UAVCAN_TRACE("DynamicNodeIDClient", "Allocation complete, node ID %d provided by %d", static_cast(allocated_node_id_.get()), static_cast(allocator_node_id_.get())); terminate(); UAVCAN_ASSERT(isAllocationComplete()); } } -int DynamicNodeIDAllocationClient::start(const protocol::HardwareVersion& hardware_version, - const NodeID preferred_node_id, - const TransferPriority transfer_priority) +int DynamicNodeIDClient::start(const protocol::HardwareVersion& hardware_version, + const NodeID preferred_node_id, + const TransferPriority transfer_priority) { terminate(); @@ -168,7 +166,7 @@ int DynamicNodeIDAllocationClient::start(const protocol::HardwareVersion& hardwa return res; } - res = dnida_sub_.start(AllocationCallback(this, &DynamicNodeIDAllocationClient::handleAllocation)); + res = dnida_sub_.start(AllocationCallback(this, &DynamicNodeIDClient::handleAllocation)); if (res < 0) { return res; diff --git a/libuavcan/test/protocol/dynamic_node_id_allocation_server.cpp b/libuavcan/test/protocol/dynamic_node_id_allocation_server.cpp index 47da8124f3..64254fc143 100644 --- a/libuavcan/test/protocol/dynamic_node_id_allocation_server.cpp +++ b/libuavcan/test/protocol/dynamic_node_id_allocation_server.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "helpers.hpp" class StorageBackend : public uavcan::IDynamicNodeIDStorageBackend @@ -999,7 +999,7 @@ TEST(DynamicNodeIDAllocationServer, AllocationRequestManager) // Node A is Allocator, Node B is Allocatee InterlinkedTestNodesWithSysClock nodes(uavcan::NodeID(10), uavcan::NodeID::Broadcast); - uavcan::DynamicNodeIDAllocationClient client(nodes.b); + uavcan::DynamicNodeIDClient client(nodes.b); /* * Client initialization @@ -1073,7 +1073,7 @@ TEST(DynamicNodeIDAllocationServer, Main) /* * Client */ - uavcan::DynamicNodeIDAllocationClient client(nodes.b); + uavcan::DynamicNodeIDClient client(nodes.b); uavcan::protocol::HardwareVersion hwver; for (uavcan::uint8_t i = 0; i < hwver.unique_id.size(); i++) { diff --git a/libuavcan/test/protocol/dynamic_node_id_allocation_client.cpp b/libuavcan/test/protocol/dynamic_node_id_client.cpp similarity index 95% rename from libuavcan/test/protocol/dynamic_node_id_allocation_client.cpp rename to libuavcan/test/protocol/dynamic_node_id_client.cpp index ecf84ec493..c9c327ece7 100644 --- a/libuavcan/test/protocol/dynamic_node_id_allocation_client.cpp +++ b/libuavcan/test/protocol/dynamic_node_id_client.cpp @@ -3,16 +3,16 @@ */ #include -#include +#include #include "helpers.hpp" -TEST(DynamicNodeIDAllocationClient, Basic) +TEST(DynamicNodeIDClient, Basic) { // Node A is Allocator, Node B is Allocatee InterlinkedTestNodesWithSysClock nodes(uavcan::NodeID(10), uavcan::NodeID::Broadcast); - uavcan::DynamicNodeIDAllocationClient dnidac(nodes.b); + uavcan::DynamicNodeIDClient dnidac(nodes.b); uavcan::GlobalDataTypeRegistry::instance().reset(); uavcan::DefaultDataTypeRegistrator _reg1; @@ -162,11 +162,11 @@ TEST(DynamicNodeIDAllocationClient, Basic) } -TEST(DynamicNodeIDAllocationClient, NonPassiveMode) +TEST(DynamicNodeIDClient, NonPassiveMode) { InterlinkedTestNodesWithSysClock nodes; - uavcan::DynamicNodeIDAllocationClient dnidac(nodes.b); + uavcan::DynamicNodeIDClient dnidac(nodes.b); uavcan::GlobalDataTypeRegistry::instance().reset(); uavcan::DefaultDataTypeRegistrator _reg1;