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 | { |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 11 | namespace message = openpower::pels::message; |
| 12 | |
| 13 | PEL::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 Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 24 | |
| 25 | PEL::PEL(const std::vector<uint8_t>& data) : PEL(data, 0) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | PEL::PEL(const std::vector<uint8_t>& data, uint32_t obmcLogID) : _rawPEL(data) |
| 30 | { |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 31 | _fromStream = true; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 32 | populateFromRawData(obmcLogID); |
| 33 | } |
| 34 | |
| 35 | void 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 | |
| 47 | bool 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 | |
| 59 | void PEL::setCommitTime() |
| 60 | { |
| 61 | auto now = std::chrono::system_clock::now(); |
| 62 | _ph->commitTimestamp() = getBCDTime(now); |
| 63 | } |
| 64 | |
| 65 | void PEL::assignID() |
| 66 | { |
| 67 | _ph->id() = generatePELID(); |
| 68 | } |
| 69 | |
| 70 | void PEL::flatten(std::vector<uint8_t>& pelBuffer) |
| 71 | { |
| 72 | Stream pelData{pelBuffer}; |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 73 | |
| 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 Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 80 | { |
| 81 | return; |
| 82 | } |
| 83 | |
Matt Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 84 | _uh->flatten(pelData); |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | std::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 Spinler | b832363 | 2019-09-20 15:11:04 -0500 | [diff] [blame] | 91 | // reason. If creating a PEL from scratch, _rawPEL will get filled in with |
| 92 | // what we do have. |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 93 | |
| 94 | flatten(_rawPEL); |
| 95 | return _rawPEL; |
| 96 | } |
| 97 | |
| 98 | } // namespace pels |
| 99 | } // namespace openpower |