blob: 1eac869bf0978586647df23318429b944463be16 [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{
11
12PEL::PEL(const std::vector<uint8_t>& data) : PEL(data, 0)
13{
14}
15
16PEL::PEL(const std::vector<uint8_t>& data, uint32_t obmcLogID) : _rawPEL(data)
17{
18 populateFromRawData(obmcLogID);
19}
20
21void PEL::populateFromRawData(uint32_t obmcLogID)
22{
23 Stream pelData{_rawPEL};
24 _ph = std::make_unique<PrivateHeader>(pelData);
25 if (obmcLogID != 0)
26 {
27 _ph->obmcLogID() = obmcLogID;
28 }
29
30 _uh = std::make_unique<UserHeader>(pelData);
31}
32
33bool PEL::valid() const
34{
35 bool valid = _ph->valid();
36
37 if (valid)
38 {
39 valid = _uh->valid();
40 }
41
42 return valid;
43}
44
45void PEL::setCommitTime()
46{
47 auto now = std::chrono::system_clock::now();
48 _ph->commitTimestamp() = getBCDTime(now);
49}
50
51void PEL::assignID()
52{
53 _ph->id() = generatePELID();
54}
55
56void PEL::flatten(std::vector<uint8_t>& pelBuffer)
57{
58 Stream pelData{pelBuffer};
59 if (_ph->valid())
60 {
Matt Spinlercf5a8d02019-09-05 12:58:53 -050061 _ph->flatten(pelData);
Matt Spinlercb6b0592019-07-16 15:58:51 -050062 }
63 else
64 {
65 return;
66 }
67
68 if (_uh->valid())
69 {
Matt Spinlercf5a8d02019-09-05 12:58:53 -050070 _uh->flatten(pelData);
Matt Spinlercb6b0592019-07-16 15:58:51 -050071 }
72}
73
74std::vector<uint8_t> PEL::data()
75{
76 // Until we can recreate a complete PEL from objects, need to just flatten
77 // on top of the original PEL data which we need to keep around for this
78 // reason.
79
80 flatten(_rawPEL);
81 return _rawPEL;
82}
83
84} // namespace pels
85} // namespace openpower