From d64038262e4c8743ae774efde7a8e91544ed359b Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Fri, 17 Feb 2017 17:10:19 -0600 Subject: Add tach sensors to each fan enclosure Create a tach sensor instance for each sensor listed within a fan enclosure that uses 'tach' based presence detection. Each tach sensor has a pointer to the fan it's associated with and is added to the list of sensors for that fan enclosure. Change-Id: I9a83ec52d1a5d01e39702e185336a09edeb4d158 Signed-off-by: Matthew Barth --- fan_enclosure.cpp | 6 ++++++ fan_enclosure.hpp | 5 +++++ sensor_base.hpp | 10 ++++++++++ tach_detect.cpp | 10 +++++++++- tach_sensor.cpp | 2 +- tach_sensor.hpp | 11 +++++++++++ 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/fan_enclosure.cpp b/fan_enclosure.cpp index 346911d..46efeb5 100644 --- a/fan_enclosure.cpp +++ b/fan_enclosure.cpp @@ -13,6 +13,12 @@ void FanEnclosure::addInventory() //TODO Add this fan to inventory } +void FanEnclosure::addSensor( + std::unique_ptr&& sensor) +{ + FanEnclosure::sensors.push_back(std::move(sensor)); +} + } // namespace presence } // namespace fan } // namespace phosphor diff --git a/fan_enclosure.hpp b/fan_enclosure.hpp index f214f18..0b96bfc 100644 --- a/fan_enclosure.hpp +++ b/fan_enclosure.hpp @@ -2,6 +2,7 @@ #include #include "fan_properties.hpp" +#include "sensor_base.hpp" namespace phosphor @@ -31,10 +32,14 @@ class FanEnclosure addInventory(); } + void addSensor( + std::unique_ptr&& sensor); + private: sdbusplus::bus::bus& bus; const std::string invPath; const std::string fanDesc; + std::vector> sensors; void addInventory(); diff --git a/sensor_base.hpp b/sensor_base.hpp index 92f53a7..2dc2b8d 100644 --- a/sensor_base.hpp +++ b/sensor_base.hpp @@ -19,9 +19,19 @@ class Sensor Sensor& operator=(Sensor&&) = delete; virtual ~Sensor() = default; + Sensor(const std::string& id, + FanEnclosure& fanEnc) : + id(id), + fanEnc(fanEnc) + { + //Nothing to do here + } + virtual bool isPresent() = 0; protected: + const std::string id; + FanEnclosure& fanEnc; }; diff --git a/tach_detect.cpp b/tach_detect.cpp index e3d2389..5da1b48 100644 --- a/tach_detect.cpp +++ b/tach_detect.cpp @@ -2,6 +2,7 @@ #include #include "fan_enclosure.hpp" #include "fan_detect_defs.hpp" +#include "tach_sensor.hpp" int main(void) @@ -19,7 +20,14 @@ int main(void) auto fan = std::make_unique< phosphor::fan::presence::FanEnclosure>(bus, fanProp); - // TODO Add sensors to fan object + for (auto const &fanSensor: std::get<2>(fanProp)) + { + auto sensor = std::make_unique< + phosphor::fan::presence::TachSensor>(bus, + fanSensor, + *fan); + fan->addSensor(std::move(sensor)); + } fans.push_back(std::move(fan)); } } diff --git a/tach_sensor.cpp b/tach_sensor.cpp index 1325365..987e390 100644 --- a/tach_sensor.cpp +++ b/tach_sensor.cpp @@ -10,7 +10,7 @@ namespace presence bool TachSensor::isPresent() { - return false; + return (tach != 0); } } // namespace presence diff --git a/tach_sensor.hpp b/tach_sensor.hpp index 0ef2b0a..24ee453 100644 --- a/tach_sensor.hpp +++ b/tach_sensor.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include "sensor_base.hpp" @@ -20,9 +21,19 @@ class TachSensor : public Sensor TachSensor& operator=(TachSensor&&) = delete; ~TachSensor() = default; + TachSensor(sdbusplus::bus::bus& bus, + const std::string& id, + FanEnclosure& fanEnc) : Sensor(id, fanEnc), + bus(bus) + { + // Nothing to do here + } + bool isPresent(); private: + sdbusplus::bus::bus& bus; + int64_t tach = 0; }; -- cgit v1.2.1