Allow derivativeCoeff and DCoefficient optional

To avoid breaking existing configurations in the field, treat the
new "derivativeCoeff" parameter as optional, not mandatory.

This affects both the old JSON parser, and the new D-Bus
entity-manager parser (it's called "DCoefficient" there).

Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: Ifcaf47d66e009b48e41b510a2ef1686b8860ad35
diff --git a/pid/buildjson.cpp b/pid/buildjson.cpp
index cf7df67..8dcbfbc 100644
--- a/pid/buildjson.cpp
+++ b/pid/buildjson.cpp
@@ -45,15 +45,21 @@
 
     auto positiveHysteresis = p.find("positiveHysteresis");
     auto negativeHysteresis = p.find("negativeHysteresis");
+    auto derivativeCoeff = p.find("derivativeCoeff");
     auto positiveHysteresisValue = 0.0;
     auto negativeHysteresisValue = 0.0;
+    auto derivativeCoeffValue = 0.0;
     if (positiveHysteresis != p.end())
     {
-        p.at("positiveHysteresis").get_to(positiveHysteresisValue);
+        positiveHysteresis->get_to(positiveHysteresisValue);
     }
     if (negativeHysteresis != p.end())
     {
-        p.at("negativeHysteresis").get_to(negativeHysteresisValue);
+        negativeHysteresis->get_to(negativeHysteresisValue);
+    }
+    if (derivativeCoeff != p.end())
+    {
+        derivativeCoeff->get_to(derivativeCoeffValue);
     }
 
     if (c.type != "stepwise")
@@ -61,7 +67,6 @@
         p.at("samplePeriod").get_to(c.pidInfo.ts);
         p.at("proportionalCoeff").get_to(c.pidInfo.proportionalCoeff);
         p.at("integralCoeff").get_to(c.pidInfo.integralCoeff);
-        p.at("derivativeCoeff").get_to(c.pidInfo.derivativeCoeff);
         p.at("feedFwdOffsetCoeff").get_to(c.pidInfo.feedFwdOffset);
         p.at("feedFwdGainCoeff").get_to(c.pidInfo.feedFwdGain);
         p.at("integralLimit_min").get_to(c.pidInfo.integralLimit.min);
@@ -71,8 +76,12 @@
         p.at("slewNeg").get_to(c.pidInfo.slewNeg);
         p.at("slewPos").get_to(c.pidInfo.slewPos);
 
+        // Unlike other coefficients, treat derivativeCoeff as an optional
+        // parameter, as support for it is fairly new, to avoid breaking
+        // existing configurations in the field that predate it.
         c.pidInfo.positiveHysteresis = positiveHysteresisValue;
         c.pidInfo.negativeHysteresis = negativeHysteresisValue;
+        c.pidInfo.derivativeCoeff = derivativeCoeffValue;
     }
     else
     {