Component status manager removed

This commit is contained in:
Pavel Kirienko
2015-07-08 23:38:56 +03:00
parent 88cf10d5a1
commit 82cd3f6196
2 changed files with 0 additions and 100 deletions
@@ -1,73 +0,0 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#ifndef UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED
#define UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED
#include <uavcan/build_config.hpp>
#include <uavcan/std.hpp>
#include <uavcan/protocol/NodeStatus.hpp>
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 <unsigned NumComponents_>
class UAVCAN_EXPORT ComponentStatusManager
{
public:
typedef typename StorageType<protocol::NodeStatus::FieldTypes::status_code>::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 <typename ComponentIndexType>
void setComponentStatus(ComponentIndexType component_index, StatusCode status_code)
{
const unsigned compidx = static_cast<unsigned>(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 <unsigned NumComponents_>
const unsigned ComponentStatusManager<NumComponents_>::NumComponents;
}
#endif // UAVCAN_HELPERS_COMPONENT_STATUS_MANAGER_HPP_INCLUDED
@@ -1,27 +0,0 @@
/*
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
*/
#include <gtest/gtest.h>
#include <uavcan/helpers/component_status_manager.hpp>
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());
}