blob: 6a56e158a506c170da2192b0c6bb3834ea6ae292 [file] [log] [blame]
Matt Spinlercb6b0592019-07-16 15:58:51 -05001#include "pel.hpp"
2
3#include "bcd_time.hpp"
4#include "log_id.hpp"
5#include "stream.hpp"
6
7namespace openpower
8{
9namespace pels
10{
Matt Spinlerb8323632019-09-20 15:11:04 -050011namespace message = openpower::pels::message;
12
13PEL::PEL(const message::Entry& entry, uint32_t obmcLogID, uint64_t timestamp,
14 phosphor::logging::Entry::Level severity)
15{
16 _ph = std::make_unique<PrivateHeader>(entry.componentID, obmcLogID,
17 timestamp);
18 _uh = std::make_unique<UserHeader>(entry, severity);
19
20 // Add future sections here and update the count
21
22 _ph->sectionCount() = 2;
23}
Matt Spinlercb6b0592019-07-16 15:58:51 -050024
25PEL::PEL(const std::vector<uint8_t>& data) : PEL(data, 0)
26{
27}
28
29PEL::PEL(const std::vector<uint8_t>& data, uint32_t obmcLogID) : _rawPEL(data)
30{
Matt Spinlerb8323632019-09-20 15:11:04 -050031 _fromStream = true;
Matt Spinlercb6b0592019-07-16 15:58:51 -050032 populateFromRawData(obmcLogID);
33}
34
35void PEL::populateFromRawData(uint32_t obmcLogID)
36{
37 Stream pelData{_rawPEL};
38 _ph = std::make_unique<PrivateHeader>(pelData);
39 if (obmcLogID != 0)
40 {
41 _ph->obmcLogID() = obmcLogID;
42 }
43
44 _uh = std::make_unique<UserHeader>(pelData);
45}
46
47bool PEL::valid() const
48{
49 bool valid = _ph->valid();
50
51 if (valid)
52 {
53 valid = _uh->valid();
54 }
55
56 return valid;
57}
58
59void PEL::setCommitTime()
60{
61 auto now = std::chrono::system_clock::now();
62 _ph->commitTimestamp() = getBCDTime(now);
63}
64
65void PEL::assignID()
66{
67 _ph->id() = generatePELID();
68}
69
70void PEL::flatten(std::vector<uint8_t>& pelBuffer)
71{
72 Stream pelData{pelBuffer};
Matt Spinlerb8323632019-09-20 15:11:04 -050073
74 _ph->flatten(pelData);
75
76 // If constructed from a PEL stream originally, don't flatten the
77 // rest of the objects until we support every PEL section type.
78 // Still need the PrivateHeader, as we updated fields in it.
79 if (_fromStream)
Matt Spinlercb6b0592019-07-16 15:58:51 -050080 {
81 return;
82 }
83
Matt Spinlerb8323632019-09-20 15:11:04 -050084 _uh->flatten(pelData);
Matt Spinlercb6b0592019-07-16 15:58:51 -050085}
86
87std::vector<uint8_t> PEL::data()
88{
89 // Until we can recreate a complete PEL from objects, need to just flatten
90 // on top of the original PEL data which we need to keep around for this
Matt Spinlerb8323632019-09-20 15:11:04 -050091 // reason. If creating a PEL from scratch, _rawPEL will get filled in with
92 // what we do have.
Matt Spinlercb6b0592019-07-16 15:58:51 -050093
94 flatten(_rawPEL);
95 return _rawPEL;
96}
97
98} // namespace pels
99} // namespace openpower