blob: 6a4c60814eb66e2cca4cd67ade07985213b0cb6b [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;
Alpana Kumaria00936f2020-04-14 07:15:46 -050016using namespace constants;
17using namespace std;
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050018using namespace openpower::vpd::parser;
Alpana Kumaria00936f2020-04-14 07:15:46 -050019
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050020kwdVpdMap memoryVpdParser::readKeywords(Binary::const_iterator iterator)
Alpana Kumaria00936f2020-04-14 07:15:46 -050021{
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
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050039variant<kwdVpdMap, Store> memoryVpdParser::parse()
Alpana Kumaria00936f2020-04-14 07:15:46 -050040{
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
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050057std::string memoryVpdParser::getInterfaceName() const
58{
59 return memVpdInf;
60}
61
Alpana Kumaria00936f2020-04-14 07:15:46 -050062} // namespace parser
63} // namespace memory
64} // namespace vpd
65} // namespace openpower