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/util.cpp b/util.cpp
index 411b761..87c4deb 100644
--- a/util.cpp
+++ b/util.cpp
@@ -69,7 +69,12 @@
             std::cout << "\t\t\t{";
             for (const auto& input : pidconf.second.inputs)
             {
-                std::cout << "\n\t\t\t" << input << ",\n";
+                std::cout << "\n\t\t\t" << input.name;
+                if (input.convertTempToMargin)
+                {
+                    std::cout << "[" << input.convertMarginZero << "]";
+                }
+                std::cout << ",\n";
             }
             std::cout << "\t\t\t}\n";
             std::cout << "\t\t\t" << pidconf.second.setpoint << ",\n";
@@ -96,4 +101,51 @@
     std::cout << "}\n\n";
 }
 
+std::vector<conf::SensorInput>
+    spliceInputs(const std::vector<std::string>& inputNames,
+                 const std::vector<double>& inputTempToMargin)
+{
+    std::vector<conf::SensorInput> results;
+
+    // Default to the TempToMargin feature disabled
+    for (const auto& inputName : inputNames)
+    {
+        conf::SensorInput newInput{
+            inputName, std::numeric_limits<double>::quiet_NaN(), false};
+
+        results.emplace_back(newInput);
+    }
+
+    size_t resultSize = results.size();
+    size_t marginSize = inputTempToMargin.size();
+
+    for (size_t index = 0; index < resultSize; ++index)
+    {
+        // If fewer doubles than strings, and vice versa, ignore remainder
+        if (index >= marginSize)
+        {
+            break;
+        }
+
+        // Both vectors have this index, combine both into SensorInput
+        results[index].convertMarginZero = inputTempToMargin[index];
+        results[index].convertTempToMargin = true;
+    }
+
+    return results;
+}
+
+std::vector<std::string>
+    splitNames(const std::vector<conf::SensorInput>& sensorInputs)
+{
+    std::vector<std::string> results;
+
+    for (const auto& sensorInput : sensorInputs)
+    {
+        results.emplace_back(sensorInput.name);
+    }
+
+    return results;
+}
+
 } // namespace pid_control