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     /**
62      * @brief Returns the machine type/model value
63      *
64      * @return std::array<uint8_t, mtmSize>&  - The TM value
65      */
66     std::array<uint8_t, mtmSize>& machineTypeAndModel()
67     {
68         return _machineTypeAndModel;
69     }
70 
71     /**
72      * @brief Returns the machine serial number value
73      *
74      * @return std::array<uint8_t, snSize>& - The SN value
75      */
76     std::array<uint8_t, snSize>& machineSerialNumber()
77     {
78         return _serialNumber;
79     }
80 
81     /**
82      * @brief Returns the size of the data when flattened
83      *
84      * @return size_t - The size of the data
85      */
86     static constexpr size_t flattenedSize()
87     {
88         return mtmSize + snSize;
89     }
90 
91   private:
92     /**
93      * @brief The type+model value
94      *
95      *     Of the form TTTT-MMM where:
96      *        TTTT = machine type
97      *        MMM = machine model
98      */
99     std::array<uint8_t, mtmSize> _machineTypeAndModel;
100 
101     /**
102      * @brief Machine Serial Number
103      */
104     std::array<uint8_t, snSize> _serialNumber;
105 };
106 
107 /**
108  * @brief Stream extraction operator for MTMS
109  *
110  * @param[in] s - the stream
111  * @param[out] mtms - the MTMS object
112  *
113  * @return Stream&
114  */
115 Stream& operator>>(Stream& s, MTMS& mtms);
116 
117 /**
118  * @brief Stream insertion operator for MTMS
119  *
120  * @param[out] s - the stream
121  * @param[in] mtms - the MTMS object
122  *
123  * @return Stream&
124  */
125 Stream& operator<<(Stream& s, MTMS& mtms);
126 
127 } // namespace pels
128 } // namespace openpower
129