psu-ng: Refactor reading VPD values to helper

Create a readVPDValue() helper function. Replace the repetitive try/catch,
read size check, resize code with a call to that common helper.

Change-Id: Ia4ceec5fa4422c3c56ff4ab3ea369c193916a388
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/phosphor-power-supply/power_supply.hpp b/phosphor-power-supply/power_supply.hpp
index a4888ec..d60b3f0 100644
--- a/phosphor-power-supply/power_supply.hpp
+++ b/phosphor-power-supply/power_supply.hpp
@@ -35,6 +35,11 @@
 
 // ipzVPD Keyword sizes
 static constexpr auto FL_KW_SIZE = 20;
+static constexpr auto FN_KW_SIZE = 7;
+static constexpr auto PN_KW_SIZE = 7;
+// For IBM power supplies, the SN is 6-byte header + 6-byte serial.
+static constexpr auto SN_KW_SIZE = 12;
+static constexpr auto CC_KW_SIZE = 4;
 #endif
 
 constexpr auto LOG_LIMIT = 3;
@@ -868,6 +873,18 @@
      */
     auto getMaxPowerOut() const;
 
+    /* @brief Reads a VPD value from PMBus and corrects for size.
+     *
+     * @param[in] vpdName - The name of the sysfs "file" to read data from.
+     * @param[in] type - The HWMON file type to read from.
+     * @param[in] vpdSize - The expacted size of the data for this VPD/property
+     *
+     * @return A string containing the VPD data read, resized if necessary
+     */
+    auto readVPDValue(const std::string& vpdName,
+                      const phosphor::pmbus::Type& type,
+                      const std::size_t& vpdSize);
+
     /**
      * @brief Reads the most recent input history record from the power supply
      * and updates the average and maximum properties in D-Bus if there is a new