diff --git a/libuavcan/include/uavcan/helpers/component_status_manager.hpp b/libuavcan/include/uavcan/helpers/component_status_manager.hpp deleted file mode 100644 index f33da0a583..0000000000 --- a/libuavcan/include/uavcan/helpers/component_status_manager.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#ifndef UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED -#define UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED - -#include -#include -#include - -namespace uavcan -{ -/** - * This helper class stores status codes of multiple components, and provides a method to quickly retrieve the - * worst status code. - * It allows to easily assign the node status code with the worst component status code. - * Refer to the standard message type uavcan.protocol.NodeStatus for available status codes. - */ -template -class UAVCAN_EXPORT ComponentStatusManager -{ -public: - typedef typename StorageType::Type StatusCode; - static const unsigned NumComponents = NumComponents_; - -private: - StatusCode status_array[NumComponents]; - -public: - ComponentStatusManager(StatusCode default_status = protocol::NodeStatus::STATUS_OK) - { - for (unsigned i = 0; i < NumComponents; i++) - { - status_array[i] = default_status; - } - } - - /** - * Assign the component status by index. Normally, an index would be defined by some enum constant. - * @param component_index Normally an enum constant - * @param status_code Status code from uavcan.protocol.NodeStatus - */ - template - void setComponentStatus(ComponentIndexType component_index, StatusCode status_code) - { - const unsigned compidx = static_cast(component_index); // This cast allows to use typesafe enums - if (compidx < NumComponents) - { - status_array[compidx] = status_code; - } - } - - /** - * Returns worst status code, i.e. highest value. - */ - StatusCode getWorstStatusCode() const - { - StatusCode result = 0; - for (unsigned i = 0; i < NumComponents; i++) - { - result = max(result, status_array[i]); - } - return result; - } -}; - -template -const unsigned ComponentStatusManager::NumComponents; - -} - -#endif // UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED diff --git a/libuavcan/test/helpers/component_status_manager.cpp b/libuavcan/test/helpers/component_status_manager.cpp deleted file mode 100644 index 4965ff2334..0000000000 --- a/libuavcan/test/helpers/component_status_manager.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include - - -TEST(ComponentStatusManager, Basic) -{ - uavcan::ComponentStatusManager<4> csm; - - ASSERT_EQ(4, uavcan::ComponentStatusManager<4>::NumComponents); - ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_OK, csm.getWorstStatusCode()); - - csm.setComponentStatus(3, uavcan::protocol::NodeStatus::STATUS_WARNING); - ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_WARNING, csm.getWorstStatusCode()); - - csm.setComponentStatus(2, uavcan::protocol::NodeStatus::STATUS_CRITICAL); - ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_CRITICAL, csm.getWorstStatusCode()); - - csm.setComponentStatus(3, uavcan::protocol::NodeStatus::STATUS_INITIALIZING); - ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_CRITICAL, csm.getWorstStatusCode()); - - csm.setComponentStatus(2, uavcan::protocol::NodeStatus::STATUS_INITIALIZING); - ASSERT_EQ(uavcan::protocol::NodeStatus::STATUS_INITIALIZING, csm.getWorstStatusCode()); -}