Anupama B R | 08fa59e | 2025-03-06 22:55:11 -0600 | [diff] [blame] | 1 | #include "single_fab.hpp" |
| 2 | |
| 3 | #include "constants.hpp" |
| 4 | #include "types.hpp" |
| 5 | |
| 6 | #include <utility/json_utility.hpp> |
| 7 | |
| 8 | namespace vpd |
| 9 | { |
| 10 | constexpr auto pimPersistVsbpPath = |
| 11 | "/var/lib/phosphor-inventory-manager/xyz/openbmc_project/inventory/system/chassis/motherboard/com.ibm.ipzvpd.VSBP"; |
| 12 | |
| 13 | std::string SingleFab::getImFromPersistedLocation() const noexcept |
| 14 | { |
| 15 | try |
| 16 | { |
| 17 | auto l_parsedVsbpJsonObj = |
| 18 | jsonUtility::getParsedJson(pimPersistVsbpPath); |
| 19 | if (!l_parsedVsbpJsonObj.contains("value0") || |
| 20 | !l_parsedVsbpJsonObj["value0"].contains(constants::kwdIM) || |
| 21 | !l_parsedVsbpJsonObj["value0"][constants::kwdIM].is_array()) |
| 22 | { |
| 23 | throw std::runtime_error( |
| 24 | "Json is empty or mandatory tag(s) missing from JSON"); |
| 25 | } |
| 26 | |
| 27 | const types::BinaryVector l_imValue = |
| 28 | l_parsedVsbpJsonObj["value0"][constants::kwdIM] |
| 29 | .get<types::BinaryVector>(); |
| 30 | |
| 31 | std::ostringstream l_imData; |
| 32 | for (const auto& l_byte : l_imValue) |
| 33 | { |
| 34 | l_imData << std::setw(2) << std::setfill('0') << std::hex |
| 35 | << static_cast<int>(l_byte); |
| 36 | } |
| 37 | return l_imData.str(); |
| 38 | } |
| 39 | catch (const std::exception& l_ex) |
| 40 | { |
| 41 | logging::logMessage( |
| 42 | "Error while getting IM value from PIM persisted file: " + |
| 43 | std::string(pimPersistVsbpPath) + |
| 44 | ", reason: " + std::string(l_ex.what())); |
| 45 | } |
| 46 | |
| 47 | return std::string(); |
| 48 | } |
| 49 | } // namespace vpd |