blob: 0fae66386a0ad8674c9a4c9fbbe9dc60355e5ab6 [file] [log] [blame]
Alpana Kumaria00936f2020-04-14 07:15:46 -05001#include "memory_vpd_parser.hpp"
2
3#include <iostream>
4#include <numeric>
5#include <string>
6
7namespace openpower
8{
9namespace vpd
10{
11namespace memory
12{
13namespace parser
14{
15using namespace inventory;
16using namespace parser;
17using namespace constants;
18using namespace std;
19
20KeywordVpdMap 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
39KeywordVpdMap 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