vpd-tool:UTF-8 encoding support on hardware read
Keyword values when in unreadable format may need to be converted
to Hex. This code converts data from HW to readable format.
Test:
root@bonn003:~# tmp/vpd-tool -r -H -O "/sys/bus/i2c/drivers/at24/8-0050/eeprom" -R VINI -K SN
{
"/sys/bus/i2c/drivers/at24/8-0050/eeprom": {
"SN": "YF30UF31C007"
}
}
root@bonn003:~# tmp/vpd-tool -r -H -O "/sys/bus/i2c/drivers/at24/8-0050/eeprom" -R VINI -K HW
{
"/sys/bus/i2c/drivers/at24/8-0050/eeprom": {
"HW": "0x8001"
}
}
Change-Id: I28d9189d95202a565bcba81299f2e548cb4cb83a
Signed-off-by: Giridhari Krishna <giridharikrishnan@gmail.com>
diff --git a/ibm_vpd_utils.hpp b/ibm_vpd_utils.hpp
index 18ee819..46a707a 100644
--- a/ibm_vpd_utils.hpp
+++ b/ibm_vpd_utils.hpp
@@ -7,6 +7,7 @@
#include <iostream>
#include <nlohmann/json.hpp>
#include <optional>
+#include <variant>
namespace openpower
{
@@ -354,21 +355,21 @@
/**
* @brief Get Printable Value
*
- * Checks if the vector value has non printable characters.
+ * Checks if the value has non printable characters.
* Returns hex value if non printable char is found else
* returns ascii value.
*
- * @param[in] vector - Reference of the Binary vector
+ * @param[in] kwVal - Reference of the input data, Keyword value
* @return printable value - either in hex or in ascii.
*/
-std::string getPrintableValue(const Binary& vec);
+std::string getPrintableValue(const std::variant<Binary, std::string>& kwVal);
/**
- * @brief Convert byte array to hex string.
- * @param[in] vec - byte array
+ * @brief Convert array to hex string.
+ * @param[in] kwVal - input data, Keyword value
* @return hexadecimal string of bytes.
*/
-std::string byteArrayToHexString(const Binary& vec);
+std::string hexString(const std::variant<Binary, std::string>& kwVal);
/**
* @brief Return presence of the FRU.