blob: 3ef8e879688b8584960269c3b53d8b5e7fe7bbe4 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinlerb6664332019-09-10 15:24:10 -050016#include "mtms.hpp"
17
18namespace openpower
19{
20namespace pels
21{
22
23MTMS::MTMS()
24{
25 memset(_machineTypeAndModel.data(), 0, mtmSize);
26 memset(_serialNumber.data(), 0, snSize);
27}
28
29MTMS::MTMS(const std::string& typeModel, const std::string& serialNumber)
30{
31 memset(_machineTypeAndModel.data(), 0, mtmSize);
32 memset(_serialNumber.data(), 0, snSize);
33
34 // Copy in as much as the fields as possible
35 for (size_t i = 0; i < mtmSize; i++)
36 {
37 if (typeModel.size() > i)
38 {
39 _machineTypeAndModel[i] = typeModel[i];
40 }
41 }
42
43 for (size_t i = 0; i < snSize; i++)
44 {
45 if (serialNumber.size() > i)
46 {
47 _serialNumber[i] = serialNumber[i];
48 }
49 }
50}
51
52MTMS::MTMS(Stream& stream)
53{
54 for (size_t i = 0; i < mtmSize; i++)
55 {
56 stream >> _machineTypeAndModel[i];
57 }
58
59 for (size_t i = 0; i < snSize; i++)
60 {
61 stream >> _serialNumber[i];
62 }
63}
64
Matt Spinler654708f2019-11-06 09:59:07 -060065Stream& operator<<(Stream& s, const MTMS& mtms)
Matt Spinlerb6664332019-09-10 15:24:10 -050066{
67 for (size_t i = 0; i < MTMS::mtmSize; i++)
68 {
Matt Spinler4b59f7a2019-10-08 13:55:17 -050069 s << mtms.machineTypeAndModelRaw()[i];
Matt Spinlerb6664332019-09-10 15:24:10 -050070 }
71
72 for (size_t i = 0; i < MTMS::snSize; i++)
73 {
Matt Spinler4b59f7a2019-10-08 13:55:17 -050074 s << mtms.machineSerialNumberRaw()[i];
Matt Spinlerb6664332019-09-10 15:24:10 -050075 }
76
77 return s;
78}
79
80Stream& operator>>(Stream& s, MTMS& mtms)
81{
Matt Spinler654708f2019-11-06 09:59:07 -060082 std::array<uint8_t, MTMS::mtmSize> mtm;
83
Matt Spinlerb6664332019-09-10 15:24:10 -050084 for (size_t i = 0; i < MTMS::mtmSize; i++)
85 {
Matt Spinler654708f2019-11-06 09:59:07 -060086 s >> mtm[i];
Matt Spinlerb6664332019-09-10 15:24:10 -050087 }
88
Matt Spinler654708f2019-11-06 09:59:07 -060089 mtms.setMachineTypeAndModel(mtm);
90
91 std::array<uint8_t, MTMS::snSize> sn;
Matt Spinlerb6664332019-09-10 15:24:10 -050092 for (size_t i = 0; i < MTMS::snSize; i++)
93 {
Matt Spinler654708f2019-11-06 09:59:07 -060094 s >> sn[i];
Matt Spinlerb6664332019-09-10 15:24:10 -050095 }
96
Matt Spinler654708f2019-11-06 09:59:07 -060097 mtms.setMachineSerialNumber(sn);
98
Matt Spinlerb6664332019-09-10 15:24:10 -050099 return s;
100}
101} // namespace pels
102} // namespace openpower