Implementing the TempToMargin feature
Wrapping the input name std::string in a new structure SensorInput, so
that the TempToMargin information can be cleanly carried along with
it, all the way down to the PID input processing layer where it is
needed. This allows the conversion to be done just-in-time before the
temperature reading is interpreted, minimizing the blast radius of
this change. Nonetheless, because of the type change, there was a
somewhat large blast radius to implement this feature.
The design, and the documentation, is already here:
https://github.com/openbmc/phosphor-pid-control/issues/23
Tested: Added unit tests for JSON parsing and for proper execution
of the TempToMargin feature. They pass. Ran it locally, on our
appropriately-configured system, and it seems to work for me.
Change-Id: I598ba485195aaa70c26e91a1da3ab88fff8c3a4c
Signed-off-by: Josh Lehan <krellan@google.com>
diff --git a/conf.hpp b/conf.hpp
index f3811e4..0e26f55 100644
--- a/conf.hpp
+++ b/conf.hpp
@@ -3,12 +3,14 @@
#include "pid/ec/pid.hpp"
#include "pid/ec/stepwise.hpp"
+#include <limits>
#include <map>
#include <string>
#include <vector>
namespace pid_control
{
+
namespace conf
{
@@ -31,12 +33,23 @@
};
/*
+ * Structure for decorating an input sensor's name with additional
+ * information, to help out with TempToMargin conversion.
+ */
+struct SensorInput
+{
+ std::string name;
+ double convertMarginZero = std::numeric_limits<double>::quiet_NaN();
+ bool convertTempToMargin = false;
+};
+
+/*
* Structure for holding the configuration of a PID.
*/
struct ControllerInfo
{
std::string type; // fan or margin or temp?
- std::vector<std::string> inputs; // one or more sensors.
+ std::vector<SensorInput> inputs; // one or more sensors.
double setpoint; // initial setpoint for thermal.
ec::pidinfo pidInfo; // pid details
ec::StepwiseInfo stepwiseInfo;
@@ -74,4 +87,5 @@
constexpr bool DEBUG = false; // enable to print found configuration
} // namespace conf
+
} // namespace pid_control