diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2018-05-07 14:41:46 -0500 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-06-04 15:27:55 +0000 |
commit | ac47309f62f91ccfa421e432eb7ff9f7a1da9613 (patch) | |
tree | cb15615d15bac5d61e657d6783b101611f816b60 | |
parent | e289100ec0dc9944439092d1d8f97de8123ed9c6 (diff) | |
download | phosphor-hwmon-ac47309f62f91ccfa421e432eb7ff9f7a1da9613.tar.gz phosphor-hwmon-ac47309f62f91ccfa421e432eb7ff9f7a1da9613.zip |
Move sensor adjust within sensor object
All sensor adjustments should be contained within the sensor object for
the sensor. This allows the adjustments to be retrieved for a given
sensor and applied accordingly.
Tested:
No change in adjusting a sensor value
No change in removing a sensor given a removal return code
Change-Id: I5e1e40fe41b4064422a47178aec1f297b781566d
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r-- | mainloop.cpp | 65 | ||||
-rw-r--r-- | sensor.cpp | 15 | ||||
-rw-r--r-- | sensor.hpp | 10 |
3 files changed, 47 insertions, 43 deletions
diff --git a/mainloop.cpp b/mainloop.cpp index 595432d..02c3ebb 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -67,17 +67,6 @@ decltype(Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmL decltype(Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi = &CriticalObject::criticalAlarmHigh; -// The gain and offset to adjust a value -struct valueAdjust -{ - double gain = 1.0; - int offset = 0; - std::unordered_set<int> rmRCs; -}; - -// Store the valueAdjust for sensors -std::map<SensorSet::key_type, valueAdjust> sensorAdjusts; - std::string MainLoop::getID(SensorSet::container_t::const_reference sensor) { std::string id; @@ -196,24 +185,20 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( hwmon::entry::cinput); #ifndef REMOVE_ON_FAIL // Check sensorAdjusts for sensor removal RCs - const auto& it = sensorAdjusts.find(sensor.first); - if (it != sensorAdjusts.end()) + auto& sAdjusts = sensorObj->getAdjusts(); + if (sAdjusts.rmRCs.count(e.code().value()) > 0) { - auto rmRCit = it->second.rmRCs.find(e.code().value()); - if (rmRCit != std::end(it->second.rmRCs)) + // Return code found in sensor return code removal list + if (rmSensors.find(sensor.first) == rmSensors.end()) { - // Return code found in sensor return code removal list - if (rmSensors.find(sensor.first) == rmSensors.end()) - { - // Trace for sensor not already removed from dbus - log<level::INFO>("Sensor not added to dbus for read fail", - entry("FILE=%s", file.c_str()), - entry("RC=%d", e.code().value())); - rmSensors[std::move(sensor.first)] = - std::move(sensor.second); - } - return {}; + // Trace for sensor not already removed from dbus + log<level::INFO>("Sensor not added to dbus for read fail", + entry("FILE=%s", file.c_str()), + entry("RC=%d", e.code().value())); + rmSensors[std::move(sensor.first)] = + std::move(sensor.second); } + return {}; } #endif using namespace sdbusplus::xyz::openbmc_project:: @@ -469,25 +454,21 @@ void MainLoop::read() hwmon::entry::cinput); #ifndef REMOVE_ON_FAIL // Check sensorAdjusts for sensor removal RCs - const auto& it = sensorAdjusts.find(i.first); - if (it != sensorAdjusts.end()) + auto& sAdjusts = sensorObjects[i.first]->getAdjusts(); + if (sAdjusts.rmRCs.count(e.code().value()) > 0) { - auto rmRCit = it->second.rmRCs.find(e.code().value()); - if (rmRCit != std::end(it->second.rmRCs)) + // Return code found in sensor return code removal list + if (rmSensors.find(i.first) == rmSensors.end()) { - // Return code found in sensor return code removal list - if (rmSensors.find(i.first) == rmSensors.end()) - { - // Trace for sensor not already removed from dbus - log<level::INFO>( - "Remove sensor from dbus for read fail", - entry("FILE=%s", file.c_str()), - entry("RC=%d", e.code().value())); - // Mark this sensor to be removed from dbus - rmSensors[i.first] = std::get<0>(i.second); - } - continue; + // Trace for sensor not already removed from dbus + log<level::INFO>( + "Remove sensor from dbus for read fail", + entry("FILE=%s", file.c_str()), + entry("RC=%d", e.code().value())); + // Mark this sensor to be removed from dbus + rmSensors[i.first] = std::get<0>(i.second); } + continue; } #endif using namespace sdbusplus::xyz::openbmc_project:: @@ -23,6 +23,20 @@ Sensor::Sensor(const SensorSet::key_type& sensor, ioAccess(ioAccess), devPath(devPath) { + auto gain = env::getEnv("GAIN", sensor); + if (!gain.empty()) + { + sensorAdjusts.gain = std::stod(gain); + } + + auto offset = env::getEnv("OFFSET", sensor); + if (!offset.empty()) + { + sensorAdjusts.offset = std::stoi(offset); + } + auto senRmRCs = env::getEnv("REMOVERCS", sensor); + // Add sensor removal return codes defined per sensor + addRemoveRCs(senRmRCs); } void Sensor::addRemoveRCs(const std::string& rcList) @@ -172,7 +186,6 @@ std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info) } catch (const std::system_error& e) { - using namespace phosphor::logging; using namespace sdbusplus::xyz::openbmc_project:: Sensor::Device::Error; using metadata = xyz::openbmc_project::Sensor:: @@ -52,6 +52,16 @@ class Sensor void addRemoveRCs(const std::string& rcList); /** + * @brief Get the adjustments struct for the sensor + * + * @return - Sensor adjustment struct + */ + inline const valueAdjust& getAdjusts() + { + return sensorAdjusts; + } + + /** * @brief Adjusts a sensor value * @details Adjusts the value given by any gain and/or offset defined * for this sensor object and returns that adjusted value. |