Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 1 | #include "pel.hpp" |
| 2 | |
| 3 | #include "bcd_time.hpp" |
| 4 | #include "log_id.hpp" |
| 5 | #include "stream.hpp" |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
| 11 | |
| 12 | PEL::PEL(const std::vector<uint8_t>& data) : PEL(data, 0) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | PEL::PEL(const std::vector<uint8_t>& data, uint32_t obmcLogID) : _rawPEL(data) |
| 17 | { |
| 18 | populateFromRawData(obmcLogID); |
| 19 | } |
| 20 | |
| 21 | void 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 | |
| 33 | bool 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 | |
| 45 | void PEL::setCommitTime() |
| 46 | { |
| 47 | auto now = std::chrono::system_clock::now(); |
| 48 | _ph->commitTimestamp() = getBCDTime(now); |
| 49 | } |
| 50 | |
| 51 | void PEL::assignID() |
| 52 | { |
| 53 | _ph->id() = generatePELID(); |
| 54 | } |
| 55 | |
| 56 | void PEL::flatten(std::vector<uint8_t>& pelBuffer) |
| 57 | { |
| 58 | Stream pelData{pelBuffer}; |
| 59 | if (_ph->valid()) |
| 60 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 61 | _ph->flatten(pelData); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 62 | } |
| 63 | else |
| 64 | { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | if (_uh->valid()) |
| 69 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 70 | _uh->flatten(pelData); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
| 74 | std::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 |