diff options
author | Patrick Venture <venture@google.com> | 2019-03-26 07:10:59 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-03-26 07:13:12 -0700 |
commit | e3eeef45a722b57d4c3bb379df165e0bd14993bd (patch) | |
tree | 5fa2191d8d7ecb7d26aaca3f524be41ffa667b0c | |
parent | 90e9dbcae6c1df3127dd3de41f9d1e1b5a438828 (diff) | |
download | phosphor-pid-control-e3eeef45a722b57d4c3bb379df165e0bd14993bd.tar.gz phosphor-pid-control-e3eeef45a722b57d4c3bb379df165e0bd14993bd.zip |
bugfix: grab hystersis parameter from pid json
The code incorrectly attempts to read the hystersis parameters from the
wrong scope of the json object. This fixes it to read from the pid
configuration's scope.
Tested: Added a new unit-test to hit this case.
Change-Id: I808bc907ec33a0b12d68a88fd316c3c9fae41516
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | pid/buildjson.cpp | 4 | ||||
-rw-r--r-- | test/pid_json_unittest.cpp | 49 |
2 files changed, 51 insertions, 2 deletions
diff --git a/pid/buildjson.cpp b/pid/buildjson.cpp index d31b6bc..ad51d9b 100644 --- a/pid/buildjson.cpp +++ b/pid/buildjson.cpp @@ -56,7 +56,7 @@ void from_json(const json& j, conf::ControllerInfo& c) } else { - j.at("positiveHysteresis").get_to(c.pidInfo.positiveHysteresis); + p.at("positiveHysteresis").get_to(c.pidInfo.positiveHysteresis); } auto negativeHysteresis = p.find("negativeHysteresis"); @@ -66,7 +66,7 @@ void from_json(const json& j, conf::ControllerInfo& c) } else { - j.at("negativeHysteresis").get_to(c.pidInfo.negativeHysteresis); + p.at("negativeHysteresis").get_to(c.pidInfo.negativeHysteresis); } } } // namespace conf diff --git a/test/pid_json_unittest.cpp b/test/pid_json_unittest.cpp index c8a1f61..9d33789 100644 --- a/test/pid_json_unittest.cpp +++ b/test/pid_json_unittest.cpp @@ -66,3 +66,52 @@ TEST(ZoneFromJson, oneZoneOnePid) EXPECT_EQ(pidConfig[1]["fan1-5"].type, "fan"); EXPECT_DOUBLE_EQ(zoneConfig[1].minThermalOutput, 3000.0); } + +TEST(ZoneFromJson, oneZoneOnePidWithHysteresis) +{ + // Parse a valid configuration with one zone and one PID and the PID uses + // Hysteresis parameters. + + std::map<int64_t, conf::PIDConf> pidConfig; + std::map<int64_t, struct conf::ZoneConfig> zoneConfig; + + auto j2 = R"( + { + "zones" : [{ + "id": 1, + "minThermalOutput": 3000.0, + "failsafePercent": 75.0, + "pids": [{ + "name": "fan1-5", + "type": "fan", + "inputs": ["fan1", "fan5"], + "setpoint": 90.0, + "pid": { + "samplePeriod": 0.1, + "proportionalCoeff": 0.0, + "integralCoeff": 0.0, + "feedFwdOffsetCoeff": 0.0, + "feedFwdGainCoeff": 0.010, + "integralLimit_min": 0.0, + "integralLimit_max": 0.0, + "outLim_min": 30.0, + "outLim_max": 100.0, + "slewNeg": 0.0, + "slewPos": 0.0, + "positiveHysteresis": 1000.0, + "negativeHysteresis": 9000.0 + } + }] + }] + } + )"_json; + + std::tie(pidConfig, zoneConfig) = buildPIDsFromJson(j2); + EXPECT_EQ(pidConfig.size(), 1); + EXPECT_EQ(zoneConfig.size(), 1); + + EXPECT_EQ(pidConfig[1]["fan1-5"].type, "fan"); + EXPECT_DOUBLE_EQ(pidConfig[1]["fan1-5"].pidInfo.positiveHysteresis, 1000.0); + + EXPECT_DOUBLE_EQ(zoneConfig[1].minThermalOutput, 3000.0); +} |