pseq: Parsing support for i2c_interface element
Add JSON parsing support for the new i2c_interface element in the
phosphor-power-sequencer configuration file.
Tested:
* Ran automated tests.
Change-Id: I2841078b0dd69635dbb6f71461d33d885b380f08
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/phosphor-power-sequencer/src/config_file_parser.cpp b/phosphor-power-sequencer/src/config_file_parser.cpp
index 07566ae..3163aff 100644
--- a/phosphor-power-sequencer/src/config_file_parser.cpp
+++ b/phosphor-power-sequencer/src/config_file_parser.cpp
@@ -118,6 +118,29 @@
return GPIO(line, activeLow);
}
+std::tuple<uint8_t, uint16_t> parseI2CInterface(
+ const nlohmann::json& element,
+ const std::map<std::string, std::string>& variables)
+{
+ verifyIsObject(element);
+ unsigned int propertyCount{0};
+
+ // Required bus property
+ const json& busElement = getRequiredProperty(element, "bus");
+ uint8_t bus = parseUint8(busElement, variables);
+ ++propertyCount;
+
+ // Required address property
+ const json& addressElement = getRequiredProperty(element, "address");
+ uint16_t address = parseHexByte(addressElement, variables);
+ ++propertyCount;
+
+ // Verify no invalid properties exist
+ verifyPropertyCount(element, propertyCount);
+
+ return {bus, address};
+}
+
std::unique_ptr<Rail> parseRail(const json& element)
{
verifyIsObject(element);
diff --git a/phosphor-power-sequencer/src/config_file_parser.hpp b/phosphor-power-sequencer/src/config_file_parser.hpp
index ee12690..a57083e 100644
--- a/phosphor-power-sequencer/src/config_file_parser.hpp
+++ b/phosphor-power-sequencer/src/config_file_parser.hpp
@@ -19,9 +19,12 @@
#include <nlohmann/json.hpp>
+#include <cstdint>
#include <filesystem>
+#include <map>
#include <memory>
#include <string>
+#include <tuple>
#include <vector>
namespace phosphor::power::sequencer::config_file_parser
@@ -88,6 +91,21 @@
GPIO parseGPIO(const nlohmann::json& element);
/**
+ * Parses a JSON element containing an i2c_interface object.
+ *
+ * Returns the corresponding I2C bus and address.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @param variables variables map used to expand variables in element value
+ * @return tuple containing bus and address
+ */
+std::tuple<uint8_t, uint16_t> parseI2CInterface(
+ const nlohmann::json& element,
+ const std::map<std::string, std::string>& variables);
+
+/**
* Parses a JSON element containing a rail.
*
* Returns the corresponding C++ Rail object.