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