From 0ada59f968b6f51ccb561dd60da36c6bfbf2ae5d Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Thu, 28 Sep 2017 10:38:11 -0500 Subject: monitor: Add NonzeroSpeed trust group class This class provides the ability to only trust the sensors in the group if at least one of them has a nonzero speed. It is being used for a system where the tach values for a set of rotors are reported as zero by the fan controller hardware when the other rotor on the fan is moving to a new target speed. As all the fans are set to the same speed at the same time, the rotors in question all report as zeros at exactly the same time, and this is then used to know when the values cannot be trusted. Change-Id: I29a014014bc8455287f90e5b573a856814331a53 Signed-off-by: Matt Spinler --- monitor/nonzero_speed_trust.hpp | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 monitor/nonzero_speed_trust.hpp (limited to 'monitor/nonzero_speed_trust.hpp') diff --git a/monitor/nonzero_speed_trust.hpp b/monitor/nonzero_speed_trust.hpp new file mode 100644 index 0000000..3d14adf --- /dev/null +++ b/monitor/nonzero_speed_trust.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include "trust_group.hpp" + +namespace phosphor +{ +namespace fan +{ +namespace trust +{ + +/** + * @class NonzeroSpeed + * + * A trust group where the sensors in the group are trusted as long + * as at least one of them has a nonzero speed. If all sensors + * have a speed of zero, then no sensor in the group is trusted. + */ +class NonzeroSpeed : public Group +{ + public: + + NonzeroSpeed() = delete; + ~NonzeroSpeed() = default; + NonzeroSpeed(const NonzeroSpeed&) = delete; + NonzeroSpeed& operator=(const NonzeroSpeed&) = delete; + NonzeroSpeed(NonzeroSpeed&&) = default; + NonzeroSpeed& operator=(NonzeroSpeed&&) = default; + + /** + * Constructor + * + * @param[in] names - the names of the sensors in the group + */ + explicit NonzeroSpeed(const std::vector& names) : + Group(names) + { + } + + private: + + /** + * Determines if the group is trusted by checking + * if any sensor has a nonzero speed. If all speeds + * are zero, then no sensors in the group are trusted. + * + * @return bool - if group is trusted or not + */ + bool checkGroupTrust() override + { + return std::any_of( + _sensors.begin(), + _sensors.end(), + [](const auto& s) + { + return s.get()->getInput() != 0; + }); + } +}; + +} +} +} -- cgit v1.2.1