regulators: Add i2c_capture_bytes to parser
Enhance the JSON configuration file parser to support the new
i2c_capture_bytes action.
Add gtest test cases to exercise new code.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I92f50fe3df9b3469e16e03b04ae5d0df464eb3e2
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 0b4673d..be28fdc 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -80,6 +80,11 @@
action = parseCompareVPD(element["compare_vpd"]);
++propertyCount;
}
+ else if (element.contains("i2c_capture_bytes"))
+ {
+ action = parseI2CCaptureBytes(element["i2c_capture_bytes"]);
+ ++propertyCount;
+ }
else if (element.contains("i2c_compare_bit"))
{
action = parseI2CCompareBit(element["i2c_compare_bit"]);
@@ -429,6 +434,31 @@
return values;
}
+std::unique_ptr<I2CCaptureBytesAction> parseI2CCaptureBytes(const json& element)
+{
+ verifyIsObject(element);
+ unsigned int propertyCount{0};
+
+ // Required register property
+ const json& regElement = getRequiredProperty(element, "register");
+ uint8_t reg = parseHexByte(regElement);
+ ++propertyCount;
+
+ // Required count property
+ const json& countElement = getRequiredProperty(element, "count");
+ uint8_t count = parseUint8(countElement);
+ if (count < 1)
+ {
+ throw std::invalid_argument{"Invalid byte count: Must be > 0"};
+ }
+ ++propertyCount;
+
+ // Verify no invalid properties exist
+ verifyPropertyCount(element, propertyCount);
+
+ return std::make_unique<I2CCaptureBytesAction>(reg, count);
+}
+
std::unique_ptr<I2CCompareBitAction> parseI2CCompareBit(const json& element)
{
verifyIsObject(element);