blob: 928fb74f2aa40bb1d40f062bea84ab7506df151c [file] [log] [blame]
Matt Spinlerb6664332019-09-10 15:24:10 -05001#pragma once
2
3#include "stream.hpp"
4
5#include <string>
6
7namespace openpower
8{
9namespace 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 */
24class 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 Spinler4b59f7a2019-10-08 13:55:17 -050062 * @brief Returns the raw machine type/model value
Matt Spinlerb6664332019-09-10 15:24:10 -050063 *
64 * @return std::array<uint8_t, mtmSize>& - The TM value
65 */
Matt Spinler654708f2019-11-06 09:59:07 -060066 const std::array<uint8_t, mtmSize>& machineTypeAndModelRaw() const
Matt Spinlerb6664332019-09-10 15:24:10 -050067 {
68 return _machineTypeAndModel;
69 }
70
71 /**
Matt Spinler654708f2019-11-06 09:59:07 -060072 * @brief Sets the machine type and model field
73 *
74 * @param[in] mtm - The new value
75 */
76 void setMachineTypeAndModel(const std::array<uint8_t, mtmSize>& mtm)
77 {
78 _machineTypeAndModel = mtm;
79 }
80
81 /**
Matt Spinler4b59f7a2019-10-08 13:55:17 -050082 * @brief Returns the machine type/model value
83 *
84 * @return std::string - The TM value
85 */
86 std::string machineTypeAndModel() const
87 {
88 std::string mtm;
89
90 // Get everything up to the 0s.
91 for (size_t i = 0; (i < mtmSize) && (_machineTypeAndModel[i] != 0); i++)
92 {
93 mtm.push_back(_machineTypeAndModel[i]);
94 }
95
96 return mtm;
97 }
98
99 /**
100 * @brief Returns the raw machine serial number value
Matt Spinlerb6664332019-09-10 15:24:10 -0500101 *
102 * @return std::array<uint8_t, snSize>& - The SN value
103 */
Matt Spinler654708f2019-11-06 09:59:07 -0600104 const std::array<uint8_t, snSize>& machineSerialNumberRaw() const
Matt Spinlerb6664332019-09-10 15:24:10 -0500105 {
106 return _serialNumber;
107 }
108
109 /**
Matt Spinler654708f2019-11-06 09:59:07 -0600110 * @brief Sets the machine serial number field
111 *
112 * @param[in] sn - The new value
113 */
114 void setMachineSerialNumber(const std::array<uint8_t, snSize>& sn)
115 {
116 _serialNumber = sn;
117 }
118
119 /**
Matt Spinler4b59f7a2019-10-08 13:55:17 -0500120 * @brief Returns the machine serial number value
121 *
122 * @return std::string - The SN value
123 */
124 std::string machineSerialNumber() const
125 {
126 std::string sn;
127
128 // Get everything up to the 0s.
129 for (size_t i = 0; (i < snSize) && (_serialNumber[i] != 0); i++)
130 {
131 sn.push_back(_serialNumber[i]);
132 }
133 return sn;
134 }
135
136 /**
Matt Spinlerb6664332019-09-10 15:24:10 -0500137 * @brief Returns the size of the data when flattened
138 *
139 * @return size_t - The size of the data
140 */
141 static constexpr size_t flattenedSize()
142 {
143 return mtmSize + snSize;
144 }
145
146 private:
147 /**
148 * @brief The type+model value
149 *
150 * Of the form TTTT-MMM where:
151 * TTTT = machine type
152 * MMM = machine model
153 */
154 std::array<uint8_t, mtmSize> _machineTypeAndModel;
155
156 /**
157 * @brief Machine Serial Number
158 */
159 std::array<uint8_t, snSize> _serialNumber;
160};
161
162/**
163 * @brief Stream extraction operator for MTMS
164 *
165 * @param[in] s - the stream
166 * @param[out] mtms - the MTMS object
167 *
168 * @return Stream&
169 */
170Stream& operator>>(Stream& s, MTMS& mtms);
171
172/**
173 * @brief Stream insertion operator for MTMS
174 *
175 * @param[out] s - the stream
176 * @param[in] mtms - the MTMS object
177 *
178 * @return Stream&
179 */
Matt Spinler654708f2019-11-06 09:59:07 -0600180Stream& operator<<(Stream& s, const MTMS& mtms);
Matt Spinlerb6664332019-09-10 15:24:10 -0500181
182} // namespace pels
183} // namespace openpower