summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
authorJames Feist <james.feist@linux.intel.com>2019-02-25 12:50:02 -0800
committerJames Feist <james.feist@linux.intel.com>2019-02-26 18:32:17 +0000
commit75eb769d351434547899186f73ff70ae00d7934a (patch)
tree8f5d8f7958b2f59d525a8c1cba24c4fe0fac1e80 /dbus
parent608304da320f232b9adc591301581a5fa5949fff (diff)
downloadphosphor-pid-control-75eb769d351434547899186f73ff70ae00d7934a.tar.gz
phosphor-pid-control-75eb769d351434547899186f73ff70ae00d7934a.zip
dbuspassive: allow scaling
For tachs it is beneficial to deal in percent so that multiple controllers can be used with different fan types without having to recalculate. This starts using the unused min and max fields to be able to scale readings. Since max and min are commonly on the value interface, the special value of <int64_t>::lowest() allows these to be gathered from dbus instead of having to enter them manually. Tested-by: Moved pid control to percent and printed outputs Change-Id: I9496eb92a18b68a7cd7f034d41d40ef5175c6974 Signed-off-by: James Feist <james.feist@linux.intel.com>
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbusconfiguration.cpp5
-rw-r--r--dbus/dbuspassive.cpp25
-rw-r--r--dbus/dbuspassive.hpp8
-rw-r--r--dbus/util.cpp23
-rw-r--r--dbus/util.hpp3
5 files changed, 60 insertions, 4 deletions
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index b449490..06bcdcc 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -366,6 +366,11 @@ void init(sdbusplus::bus::bus& bus)
{
config.timeout = 0;
}
+ else if (config.type == "fan")
+ {
+ config.max = conf::inheritValueFromDbus;
+ config.min = conf::inheritValueFromDbus;
+ }
}
else if (sensorPathIfacePair.second == pwmInterface)
{
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index 6d8aa03..206adbe 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -27,7 +27,7 @@
std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
sdbusplus::bus::bus& bus, const std::string& type, const std::string& id,
- DbusHelperInterface* helper)
+ DbusHelperInterface* helper, const SensorConfig* info)
{
if (helper == nullptr)
{
@@ -58,6 +58,15 @@ std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
{
return nullptr;
}
+ if (info->max != conf::inheritValueFromDbus)
+ {
+ settings.max = info->max;
+ }
+
+ if (info->max != conf::inheritValueFromDbus)
+ {
+ settings.min = info->min;
+ }
return std::make_unique<DbusPassive>(bus, type, id, helper, settings,
failed);
@@ -72,6 +81,8 @@ DbusPassive::DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
{
_scale = settings.scale;
_value = settings.value * pow(10, _scale);
+ _min = settings.min * pow(10, _scale);
+ _max = settings.max * pow(10, _scale);
_updated = std::chrono::high_resolution_clock::now();
}
@@ -112,6 +123,16 @@ std::string DbusPassive::getID(void)
return _id;
}
+double DbusPassive::getMax(void)
+{
+ return _max;
+}
+
+double DbusPassive::getMin(void)
+{
+ return _min;
+}
+
int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner)
{
std::string msgSensor;
@@ -129,6 +150,8 @@ int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner)
value *= std::pow(10, owner->getScale());
+ scaleSensorReading(owner->getMin(), owner->getMax(), value);
+
owner->setValue(value);
}
}
diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp
index 5dbd3c3..fa9dab7 100644
--- a/dbus/dbuspassive.hpp
+++ b/dbus/dbuspassive.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "conf.hpp"
#include "dbus/util.hpp"
#include "interfaces.hpp"
@@ -35,7 +36,8 @@ class DbusPassive : public ReadInterface
public:
static std::unique_ptr<ReadInterface>
createDbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
- const std::string& id, DbusHelperInterface* helper);
+ const std::string& id, DbusHelperInterface* helper,
+ const SensorConfig* info);
DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
const std::string& id, DbusHelperInterface* helper,
@@ -48,6 +50,8 @@ class DbusPassive : public ReadInterface
void setFailed(bool value);
int64_t getScale(void);
std::string getID(void);
+ double getMax(void);
+ double getMin(void);
private:
sdbusplus::bus::bus& _bus;
@@ -58,6 +62,8 @@ class DbusPassive : public ReadInterface
std::mutex _lock;
double _value = 0;
+ double _max = 0;
+ double _min = 0;
bool _failed = false;
/* The last time the value was refreshed, not necessarily changed. */
std::chrono::high_resolution_clock::time_point _updated;
diff --git a/dbus/util.cpp b/dbus/util.cpp
index 5a572d0..b5b22f4 100644
--- a/dbus/util.cpp
+++ b/dbus/util.cpp
@@ -88,13 +88,23 @@ void DbusHelper::getProperties(sdbusplus::bus::bus& bus,
prop->unit = std::get<std::string>(findUnit->second);
}
auto findScale = propMap.find("Scale");
+ auto findMax = propMap.find("MaxValue");
+ auto findMin = propMap.find("MinValue");
+
+ prop->min = 0;
+ prop->max = 0;
+ prop->scale = 0;
if (findScale != propMap.end())
{
prop->scale = std::get<int64_t>(findScale->second);
}
- else
+ if (findMax != propMap.end())
+ {
+ prop->max = std::visit(VariantToDoubleVisitor(), findMax->second);
+ }
+ if (findMin != propMap.end())
{
- prop->scale = 0;
+ prop->min = std::visit(VariantToDoubleVisitor(), findMin->second);
}
prop->value = std::visit(VariantToDoubleVisitor(), propMap["Value"]);
@@ -174,3 +184,12 @@ bool validType(const std::string& type)
static std::set<std::string> valid = {"fan", "temp"};
return (valid.find(type) != valid.end());
}
+
+void scaleSensorReading(const double min, const double max, double& value)
+{
+ if (max <= 0)
+ {
+ return;
+ }
+ value /= (max - min);
+} \ No newline at end of file
diff --git a/dbus/util.hpp b/dbus/util.hpp
index 719bb1d..69a8112 100644
--- a/dbus/util.hpp
+++ b/dbus/util.hpp
@@ -7,6 +7,8 @@ struct SensorProperties
{
int64_t scale;
double value;
+ double min;
+ double max;
std::string unit;
};
@@ -83,6 +85,7 @@ class DbusHelper : public DbusHelperInterface
std::string getSensorPath(const std::string& type, const std::string& id);
std::string getMatch(const std::string& type, const std::string& id);
+void scaleSensorReading(const double min, const double max, double& value);
bool validType(const std::string& type);
struct VariantToDoubleVisitor
OpenPOWER on IntegriCloud