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/pid/buildjson.cpp b/pid/buildjson.cpp
index 57ea943..8396338 100644
--- a/pid/buildjson.cpp
+++ b/pid/buildjson.cpp
@@ -17,10 +17,12 @@
 #include "pid/buildjson.hpp"
 
 #include "conf.hpp"
+#include "util.hpp"
 
 #include <nlohmann/json.hpp>
 
 #include <iostream>
+#include <limits>
 #include <map>
 #include <tuple>
 
@@ -31,12 +33,25 @@
 
 namespace conf
 {
+
 void from_json(const json& j, conf::ControllerInfo& c)
 {
+    std::vector<std::string> inputNames;
+
     j.at("type").get_to(c.type);
-    j.at("inputs").get_to(c.inputs);
+    j.at("inputs").get_to(inputNames);
     j.at("setpoint").get_to(c.setpoint);
 
+    std::vector<double> inputTempToMargin;
+
+    auto findTempToMargin = j.find("tempToMargin");
+    if (findTempToMargin != j.end())
+    {
+        findTempToMargin->get_to(inputTempToMargin);
+    }
+
+    c.inputs = spliceInputs(inputNames, inputTempToMargin);
+
     /* TODO: We need to handle parsing other PID controller configurations.
      * We can do that by checking for different keys and making the decision
      * accordingly.
@@ -135,6 +150,7 @@
         c.stepwiseInfo.negativeHysteresis = negativeHysteresisValue;
     }
 }
+
 } // namespace conf
 
 inline void getCycleTimeSetting(const auto& zone, const int id,