Matt Spinler | a906c94 | 2019-10-08 13:42:05 -0500 | [diff] [blame] | 1 | #include "fru_identity.hpp" |
| 2 | |
| 3 | namespace openpower |
| 4 | { |
| 5 | namespace pels |
| 6 | { |
| 7 | namespace src |
| 8 | { |
| 9 | |
| 10 | FRUIdentity::FRUIdentity(Stream& pel) |
| 11 | { |
| 12 | pel >> _type >> _size >> _flags; |
| 13 | |
| 14 | if (_flags & (pnSupplied | maintProcSupplied)) |
| 15 | { |
| 16 | pel.read(_pnOrProcedureID.data(), _pnOrProcedureID.size()); |
| 17 | } |
| 18 | |
| 19 | if (_flags & ccinSupplied) |
| 20 | { |
| 21 | pel.read(_ccin.data(), _ccin.size()); |
| 22 | } |
| 23 | |
| 24 | if (_flags & snSupplied) |
| 25 | { |
| 26 | pel.read(_sn.data(), _sn.size()); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | std::optional<std::string> FRUIdentity::getPN() const |
| 31 | { |
| 32 | if (hasPN()) |
| 33 | { |
| 34 | // NULL terminated |
| 35 | std::string pn{_pnOrProcedureID.data()}; |
| 36 | return pn; |
| 37 | } |
| 38 | |
| 39 | return std::nullopt; |
| 40 | } |
| 41 | |
| 42 | std::optional<std::string> FRUIdentity::getMaintProc() const |
| 43 | { |
| 44 | if (hasMP()) |
| 45 | { |
| 46 | // NULL terminated |
| 47 | std::string mp{_pnOrProcedureID.data()}; |
| 48 | return mp; |
| 49 | } |
| 50 | |
| 51 | return std::nullopt; |
| 52 | } |
| 53 | |
| 54 | std::optional<std::string> FRUIdentity::getCCIN() const |
| 55 | { |
| 56 | if (hasCCIN()) |
| 57 | { |
| 58 | std::string ccin{_ccin.begin(), _ccin.begin() + _ccin.size()}; |
| 59 | return ccin; |
| 60 | } |
| 61 | |
| 62 | return std::nullopt; |
| 63 | } |
| 64 | |
| 65 | std::optional<std::string> FRUIdentity::getSN() const |
| 66 | { |
| 67 | if (hasSN()) |
| 68 | { |
| 69 | std::string sn{_sn.begin(), _sn.begin() + _sn.size()}; |
| 70 | return sn; |
| 71 | } |
| 72 | |
| 73 | return std::nullopt; |
| 74 | } |
| 75 | |
| 76 | void FRUIdentity::flatten(Stream& pel) |
| 77 | { |
| 78 | pel << _type << _size << _flags; |
| 79 | |
| 80 | if (hasPN() || hasMP()) |
| 81 | { |
| 82 | pel.write(_pnOrProcedureID.data(), _pnOrProcedureID.size()); |
| 83 | } |
| 84 | |
| 85 | if (hasCCIN()) |
| 86 | { |
| 87 | pel.write(_ccin.data(), _ccin.size()); |
| 88 | } |
| 89 | |
| 90 | if (hasSN()) |
| 91 | { |
| 92 | pel.write(_sn.data(), _sn.size()); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | } // namespace src |
| 97 | } // namespace pels |
| 98 | } // namespace openpower |