blob: ce157a7033c75d2b537c4684e9b4faa3ab5e5d0f [file] [log] [blame]
Matt Spinlerb6664332019-09-10 15:24:10 -05001#pragma once
2
3#include "stream.hpp"
4
Matt Spinlerf6d4dcb2022-06-06 08:43:40 -05005#include <array>
Matt Spinlerb6664332019-09-10 15:24:10 -05006#include <string>
7
8namespace openpower
9{
10namespace 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 */
25class 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 Spinler4b59f7a2019-10-08 13:55:17 -050063 * @brief Returns the raw machine type/model value
Matt Spinlerb6664332019-09-10 15:24:10 -050064 *
65 * @return std::array<uint8_t, mtmSize>& - The TM value
66 */
Matt Spinler654708f2019-11-06 09:59:07 -060067 const std::array<uint8_t, mtmSize>& machineTypeAndModelRaw() const
Matt Spinlerb6664332019-09-10 15:24:10 -050068 {
69 return _machineTypeAndModel;
70 }
71
72 /**
Matt Spinler654708f2019-11-06 09:59:07 -060073 * @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 Spinler4b59f7a2019-10-08 13:55:17 -050083 * @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 Spinlerb6664332019-09-10 15:24:10 -0500102 *
103 * @return std::array<uint8_t, snSize>& - The SN value
104 */
Matt Spinler654708f2019-11-06 09:59:07 -0600105 const std::array<uint8_t, snSize>& machineSerialNumberRaw() const
Matt Spinlerb6664332019-09-10 15:24:10 -0500106 {
107 return _serialNumber;
108 }
109
110 /**
Matt Spinler654708f2019-11-06 09:59:07 -0600111 * @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 Spinler4b59f7a2019-10-08 13:55:17 -0500121 * @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 Spinlerb6664332019-09-10 15:24:10 -0500138 * @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 */
171Stream& 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 Spinler654708f2019-11-06 09:59:07 -0600181Stream& operator<<(Stream& s, const MTMS& mtms);
Matt Spinlerb6664332019-09-10 15:24:10 -0500182
183} // namespace pels
184} // namespace openpower