Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "stream.hpp" |
| 4 | |
| 5 | #include <string> |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
| 11 | |
| 12 | /** @class MTMS |
| 13 | * |
| 14 | * (M)achine (T)ype-(M)odel (S)erialNumber |
| 15 | * |
| 16 | * Represents the PEL's Machine Type / Model / Serial Number |
| 17 | * structure, which shows up in multiple places in a PEL. |
| 18 | * |
| 19 | * It holds 8 bytes for the Type+Model, and 12 for the SN. |
| 20 | * Unused bytes are set to 0s. |
| 21 | * |
| 22 | * The type and model are combined into a single field. |
| 23 | */ |
| 24 | class MTMS |
| 25 | { |
| 26 | public: |
| 27 | MTMS(const MTMS&) = default; |
| 28 | MTMS& operator=(const MTMS&) = default; |
| 29 | MTMS(MTMS&&) = default; |
| 30 | MTMS& operator=(MTMS&&) = default; |
| 31 | ~MTMS() = default; |
| 32 | |
| 33 | enum |
| 34 | { |
| 35 | mtmSize = 8, |
| 36 | snSize = 12 |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * @brief Constructor |
| 41 | */ |
| 42 | MTMS(); |
| 43 | |
| 44 | /** |
| 45 | * @brief Constructor |
| 46 | * |
| 47 | * @param[in] typeModel - The machine type+model |
| 48 | * @param[in] serialNumber - The machine serial number |
| 49 | */ |
| 50 | MTMS(const std::string& typeModel, const std::string& serialNumber); |
| 51 | |
| 52 | /** |
| 53 | * @brief Constructor |
| 54 | * |
| 55 | * Fills in this class's data fields from the stream. |
| 56 | * |
| 57 | * @param[in] pel - the PEL data stream |
| 58 | */ |
| 59 | explicit MTMS(Stream& stream); |
| 60 | |
| 61 | /** |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 62 | * @brief Returns the raw machine type/model value |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 63 | * |
| 64 | * @return std::array<uint8_t, mtmSize>& - The TM value |
| 65 | */ |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 66 | std::array<uint8_t, mtmSize>& machineTypeAndModelRaw() |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 67 | { |
| 68 | return _machineTypeAndModel; |
| 69 | } |
| 70 | |
| 71 | /** |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 72 | * @brief Returns the machine type/model value |
| 73 | * |
| 74 | * @return std::string - The TM value |
| 75 | */ |
| 76 | std::string machineTypeAndModel() const |
| 77 | { |
| 78 | std::string mtm; |
| 79 | |
| 80 | // Get everything up to the 0s. |
| 81 | for (size_t i = 0; (i < mtmSize) && (_machineTypeAndModel[i] != 0); i++) |
| 82 | { |
| 83 | mtm.push_back(_machineTypeAndModel[i]); |
| 84 | } |
| 85 | |
| 86 | return mtm; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @brief Returns the raw machine serial number value |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 91 | * |
| 92 | * @return std::array<uint8_t, snSize>& - The SN value |
| 93 | */ |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 94 | std::array<uint8_t, snSize>& machineSerialNumberRaw() |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 95 | { |
| 96 | return _serialNumber; |
| 97 | } |
| 98 | |
| 99 | /** |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 100 | * @brief Returns the machine serial number value |
| 101 | * |
| 102 | * @return std::string - The SN value |
| 103 | */ |
| 104 | std::string machineSerialNumber() const |
| 105 | { |
| 106 | std::string sn; |
| 107 | |
| 108 | // Get everything up to the 0s. |
| 109 | for (size_t i = 0; (i < snSize) && (_serialNumber[i] != 0); i++) |
| 110 | { |
| 111 | sn.push_back(_serialNumber[i]); |
| 112 | } |
| 113 | return sn; |
| 114 | } |
| 115 | |
| 116 | /** |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 117 | * @brief Returns the size of the data when flattened |
| 118 | * |
| 119 | * @return size_t - The size of the data |
| 120 | */ |
| 121 | static constexpr size_t flattenedSize() |
| 122 | { |
| 123 | return mtmSize + snSize; |
| 124 | } |
| 125 | |
| 126 | private: |
| 127 | /** |
| 128 | * @brief The type+model value |
| 129 | * |
| 130 | * Of the form TTTT-MMM where: |
| 131 | * TTTT = machine type |
| 132 | * MMM = machine model |
| 133 | */ |
| 134 | std::array<uint8_t, mtmSize> _machineTypeAndModel; |
| 135 | |
| 136 | /** |
| 137 | * @brief Machine Serial Number |
| 138 | */ |
| 139 | std::array<uint8_t, snSize> _serialNumber; |
| 140 | }; |
| 141 | |
| 142 | /** |
| 143 | * @brief Stream extraction operator for MTMS |
| 144 | * |
| 145 | * @param[in] s - the stream |
| 146 | * @param[out] mtms - the MTMS object |
| 147 | * |
| 148 | * @return Stream& |
| 149 | */ |
| 150 | Stream& operator>>(Stream& s, MTMS& mtms); |
| 151 | |
| 152 | /** |
| 153 | * @brief Stream insertion operator for MTMS |
| 154 | * |
| 155 | * @param[out] s - the stream |
| 156 | * @param[in] mtms - the MTMS object |
| 157 | * |
| 158 | * @return Stream& |
| 159 | */ |
| 160 | Stream& operator<<(Stream& s, MTMS& mtms); |
| 161 | |
| 162 | } // namespace pels |
| 163 | } // namespace openpower |