summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/mtms.hpp
blob: 928fb74f2aa40bb1d40f062bea84ab7506df151c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once

#include "stream.hpp"

#include <string>

namespace openpower
{
namespace pels
{

/** @class MTMS
 *
 * (M)achine (T)ype-(M)odel (S)erialNumber
 *
 * Represents the PEL's Machine Type / Model / Serial Number
 * structure, which shows up in multiple places in a PEL.
 *
 * It holds 8 bytes for the Type+Model, and 12 for the SN.
 * Unused bytes are set to 0s.
 *
 * The type and model are combined into a single field.
 */
class MTMS
{
  public:
    MTMS(const MTMS&) = default;
    MTMS& operator=(const MTMS&) = default;
    MTMS(MTMS&&) = default;
    MTMS& operator=(MTMS&&) = default;
    ~MTMS() = default;

    enum
    {
        mtmSize = 8,
        snSize = 12
    };

    /**
     * @brief Constructor
     */
    MTMS();

    /**
     * @brief Constructor
     *
     * @param[in] typeModel - The machine type+model
     * @param[in] serialNumber - The machine serial number
     */
    MTMS(const std::string& typeModel, const std::string& serialNumber);

    /**
     * @brief Constructor
     *
     * Fills in this class's data fields from the stream.
     *
     * @param[in] pel - the PEL data stream
     */
    explicit MTMS(Stream& stream);

    /**
     * @brief Returns the raw machine type/model value
     *
     * @return std::array<uint8_t, mtmSize>&  - The TM value
     */
    const std::array<uint8_t, mtmSize>& machineTypeAndModelRaw() const
    {
        return _machineTypeAndModel;
    }

    /**
     * @brief Sets the machine type and model field
     *
     * @param[in] mtm - The new value
     */
    void setMachineTypeAndModel(const std::array<uint8_t, mtmSize>& mtm)
    {
        _machineTypeAndModel = mtm;
    }

    /**
     * @brief Returns the machine type/model value
     *
     * @return std::string - The TM value
     */
    std::string machineTypeAndModel() const
    {
        std::string mtm;

        // Get everything up to the 0s.
        for (size_t i = 0; (i < mtmSize) && (_machineTypeAndModel[i] != 0); i++)
        {
            mtm.push_back(_machineTypeAndModel[i]);
        }

        return mtm;
    }

    /**
     * @brief Returns the raw machine serial number value
     *
     * @return std::array<uint8_t, snSize>& - The SN value
     */
    const std::array<uint8_t, snSize>& machineSerialNumberRaw() const
    {
        return _serialNumber;
    }

    /**
     * @brief Sets the machine serial number field
     *
     * @param[in] sn - The new value
     */
    void setMachineSerialNumber(const std::array<uint8_t, snSize>& sn)
    {
        _serialNumber = sn;
    }

    /**
     * @brief Returns the machine serial number value
     *
     * @return std::string - The SN value
     */
    std::string machineSerialNumber() const
    {
        std::string sn;

        // Get everything up to the 0s.
        for (size_t i = 0; (i < snSize) && (_serialNumber[i] != 0); i++)
        {
            sn.push_back(_serialNumber[i]);
        }
        return sn;
    }

    /**
     * @brief Returns the size of the data when flattened
     *
     * @return size_t - The size of the data
     */
    static constexpr size_t flattenedSize()
    {
        return mtmSize + snSize;
    }

  private:
    /**
     * @brief The type+model value
     *
     *     Of the form TTTT-MMM where:
     *        TTTT = machine type
     *        MMM = machine model
     */
    std::array<uint8_t, mtmSize> _machineTypeAndModel;

    /**
     * @brief Machine Serial Number
     */
    std::array<uint8_t, snSize> _serialNumber;
};

/**
 * @brief Stream extraction operator for MTMS
 *
 * @param[in] s - the stream
 * @param[out] mtms - the MTMS object
 *
 * @return Stream&
 */
Stream& operator>>(Stream& s, MTMS& mtms);

/**
 * @brief Stream insertion operator for MTMS
 *
 * @param[out] s - the stream
 * @param[in] mtms - the MTMS object
 *
 * @return Stream&
 */
Stream& operator<<(Stream& s, const MTMS& mtms);

} // namespace pels
} // namespace openpower
OpenPOWER on IntegriCloud