psu-ng: Read and validate input voltage

Read the input voltage reported by pmbus for each PSU. Determine the
actual voltage based on predefined thresholds. Then validate the actual
voltage is supported for the PSU model.

Tested:
Verified in Rainier 2U that the 2 present PSUs had a pmbus
voltage value of 208000 mV, which is then translated to a 220V PSU, and
that value is validated against the supported configuration.
Verified the additional data strings by printing them with debug
statements:
Aug 05 18:50:15 p10bmc phosphor-psu-monitor[3615]: ACTUAL_VOLTAGE: 208.000000
Aug 05 18:50:15 p10bmc phosphor-psu-monitor[3615]: CALLOUT_INVENTORY_PATH:
/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0
Aug 05 18:50:15 p10bmc phosphor-psu-monitor[3615]: EXPECTED_VOLTAGE: 220

Change-Id: Ic8c3b567c8265e90bce420f98ac6f1e131ff713b
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/phosphor-power-supply/power_supply.cpp b/phosphor-power-supply/power_supply.cpp
index 226d03b..0e2c259 100644
--- a/phosphor-power-supply/power_supply.cpp
+++ b/phosphor-power-supply/power_supply.cpp
@@ -551,4 +551,44 @@
     }
 }
 
+void PowerSupply::getInputVoltage(double& actualInputVoltage,
+                                  int& inputVoltage) const
+{
+    using namespace phosphor::pmbus;
+
+    actualInputVoltage = in_input::VIN_VOLTAGE_0;
+    inputVoltage = in_input::VIN_VOLTAGE_0;
+
+    if (present)
+    {
+        try
+        {
+            // Read input voltage in millivolts
+            auto inputVoltageStr = pmbusIntf->readString(READ_VIN, Type::Hwmon);
+
+            // Convert to volts
+            actualInputVoltage = std::stod(inputVoltageStr) / 1000;
+
+            // Calculate the voltage based on voltage thresholds
+            if (actualInputVoltage < in_input::VIN_VOLTAGE_MIN)
+            {
+                inputVoltage = in_input::VIN_VOLTAGE_0;
+            }
+            else if (actualInputVoltage < in_input::VIN_VOLTAGE_110_THRESHOLD)
+            {
+                inputVoltage = in_input::VIN_VOLTAGE_110;
+            }
+            else
+            {
+                inputVoltage = in_input::VIN_VOLTAGE_220;
+            }
+        }
+        catch (const std::exception& e)
+        {
+            log<level::ERR>(
+                fmt::format("READ_VIN read error: {}", e.what()).c_str());
+        }
+    }
+}
+
 } // namespace phosphor::power::psu