Alpana Kumari | a00936f | 2020-04-14 07:15:46 -0500 | [diff] [blame^] | 1 | #include "memory_vpd_parser.hpp" |
| 2 | |
| 3 | #include <iostream> |
| 4 | #include <numeric> |
| 5 | #include <string> |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace vpd |
| 10 | { |
| 11 | namespace memory |
| 12 | { |
| 13 | namespace parser |
| 14 | { |
| 15 | using namespace inventory; |
| 16 | using namespace parser; |
| 17 | using namespace constants; |
| 18 | using namespace std; |
| 19 | |
| 20 | KeywordVpdMap memoryVpdParser::readKeywords(Binary::const_iterator iterator) |
| 21 | { |
| 22 | KeywordVpdMap map{}; |
| 23 | |
| 24 | vector<uint8_t> partNumber(iterator, iterator + PART_NUM_LEN); |
| 25 | |
| 26 | advance(iterator, PART_NUM_LEN); |
| 27 | vector<uint8_t> serialNumber(iterator, iterator + SERIAL_NUM_LEN); |
| 28 | |
| 29 | advance(iterator, SERIAL_NUM_LEN); |
| 30 | vector<uint8_t> ccin(iterator, iterator + CCIN_LEN); |
| 31 | |
| 32 | map.emplace("PN", move(partNumber)); |
| 33 | map.emplace("SN", move(serialNumber)); |
| 34 | map.emplace("CC", move(ccin)); |
| 35 | |
| 36 | return map; |
| 37 | } |
| 38 | |
| 39 | KeywordVpdMap memoryVpdParser::parseMemVpd() |
| 40 | { |
| 41 | // check if vpd file is empty |
| 42 | if (memVpd.empty()) |
| 43 | { |
| 44 | throw runtime_error("VPD file is empty."); |
| 45 | } |
| 46 | |
| 47 | // Read the data and return the map |
| 48 | auto iterator = memVpd.cbegin(); |
| 49 | // point the iterator to DIMM data and skip "11S" |
| 50 | advance(iterator, MEMORY_VPD_DATA_START + 3); |
| 51 | |
| 52 | auto vpdDataMap = readKeywords(iterator); |
| 53 | |
| 54 | return vpdDataMap; |
| 55 | } |
| 56 | |
| 57 | } // namespace parser |
| 58 | } // namespace memory |
| 59 | } // namespace vpd |
| 60 | } // namespace openpower |