diff options
| author | Patrick Venture <venture@google.com> | 2019-08-29 10:06:29 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2019-08-29 10:06:29 -0700 |
| commit | 35906cc3d099d1452a49d6bf0cca677a121906a6 (patch) | |
| tree | 453acdbf8f0be407edafd1abcf8bb4a17cde838b | |
| parent | c7ab57e9bdbcc7aa51c51f89aff5aa0898882ee2 (diff) | |
| download | phosphor-pid-control-35906cc3d099d1452a49d6bf0cca677a121906a6.tar.gz phosphor-pid-control-35906cc3d099d1452a49d6bf0cca677a121906a6.zip | |
sensors: buildjson: only load min/max if type fan
The min/max value in the json configuration only provide meaning in the
context of a fan sensor. This patch only loads the configuration
options in that case, and reports a warning if otherwise detected.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I20898ab3c87f4e9c6005683420a30c6685944c96
| -rw-r--r-- | sensors/buildjson.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sensors/buildjson.cpp b/sensors/buildjson.cpp index f5449eb..2dc5a37 100644 --- a/sensors/buildjson.cpp +++ b/sensors/buildjson.cpp @@ -19,6 +19,7 @@ #include "conf.hpp" #include "sensors/sensor.hpp" +#include <cstdio> #include <nlohmann/json.hpp> using json = nlohmann::json; @@ -48,14 +49,28 @@ void from_json(const json& j, conf::SensorConfig& s) auto min = j.find("min"); if (min != j.end()) { - j.at("min").get_to(s.min); + if (s.type == "fan") + { + j.at("min").get_to(s.min); + } + else + { + std::fprintf(stderr, "Non-fan types ignore min value specified\n"); + } } /* The max field is optional in a configuration. */ auto max = j.find("max"); if (max != j.end()) { - j.at("max").get_to(s.max); + if (s.type == "fan") + { + j.at("max").get_to(s.max); + } + else + { + std::fprintf(stderr, "Non-fan types ignore max value specified\n"); + } } /* The timeout field is optional in a configuration. */ |

