1711d51d8SMatt Spinler /**
2711d51d8SMatt Spinler * Copyright © 2019 IBM Corporation
3711d51d8SMatt Spinler *
4711d51d8SMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License");
5711d51d8SMatt Spinler * you may not use this file except in compliance with the License.
6711d51d8SMatt Spinler * You may obtain a copy of the License at
7711d51d8SMatt Spinler *
8711d51d8SMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0
9711d51d8SMatt Spinler *
10711d51d8SMatt Spinler * Unless required by applicable law or agreed to in writing, software
11711d51d8SMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS,
12711d51d8SMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13711d51d8SMatt Spinler * See the License for the specific language governing permissions and
14711d51d8SMatt Spinler * limitations under the License.
15711d51d8SMatt Spinler */
16b6664339SMatt Spinler #include "mtms.hpp"
17b6664339SMatt Spinler
18b6664339SMatt Spinler namespace openpower
19b6664339SMatt Spinler {
20b6664339SMatt Spinler namespace pels
21b6664339SMatt Spinler {
22b6664339SMatt Spinler
MTMS()23b6664339SMatt Spinler MTMS::MTMS()
24b6664339SMatt Spinler {
25b6664339SMatt Spinler memset(_machineTypeAndModel.data(), 0, mtmSize);
26b6664339SMatt Spinler memset(_serialNumber.data(), 0, snSize);
27b6664339SMatt Spinler }
28b6664339SMatt Spinler
MTMS(const std::string & typeModel,const std::string & serialNumber)29b6664339SMatt Spinler MTMS::MTMS(const std::string& typeModel, const std::string& serialNumber)
30b6664339SMatt Spinler {
31b6664339SMatt Spinler memset(_machineTypeAndModel.data(), 0, mtmSize);
32b6664339SMatt Spinler memset(_serialNumber.data(), 0, snSize);
33b6664339SMatt Spinler
34b6664339SMatt Spinler // Copy in as much as the fields as possible
35b6664339SMatt Spinler for (size_t i = 0; i < mtmSize; i++)
36b6664339SMatt Spinler {
37b6664339SMatt Spinler if (typeModel.size() > i)
38b6664339SMatt Spinler {
39b6664339SMatt Spinler _machineTypeAndModel[i] = typeModel[i];
40b6664339SMatt Spinler }
41b6664339SMatt Spinler }
42b6664339SMatt Spinler
43b6664339SMatt Spinler for (size_t i = 0; i < snSize; i++)
44b6664339SMatt Spinler {
45b6664339SMatt Spinler if (serialNumber.size() > i)
46b6664339SMatt Spinler {
47b6664339SMatt Spinler _serialNumber[i] = serialNumber[i];
48b6664339SMatt Spinler }
49b6664339SMatt Spinler }
50b6664339SMatt Spinler }
51b6664339SMatt Spinler
MTMS(Stream & stream)52b6664339SMatt Spinler MTMS::MTMS(Stream& stream)
53b6664339SMatt Spinler {
54b6664339SMatt Spinler for (size_t i = 0; i < mtmSize; i++)
55b6664339SMatt Spinler {
56b6664339SMatt Spinler stream >> _machineTypeAndModel[i];
57b6664339SMatt Spinler }
58b6664339SMatt Spinler
59b6664339SMatt Spinler for (size_t i = 0; i < snSize; i++)
60b6664339SMatt Spinler {
61b6664339SMatt Spinler stream >> _serialNumber[i];
62b6664339SMatt Spinler }
63b6664339SMatt Spinler }
64b6664339SMatt Spinler
operator <<(Stream & s,const MTMS & mtms)65*654708fdSMatt Spinler Stream& operator<<(Stream& s, const MTMS& mtms)
66b6664339SMatt Spinler {
67b6664339SMatt Spinler for (size_t i = 0; i < MTMS::mtmSize; i++)
68b6664339SMatt Spinler {
694b59f7adSMatt Spinler s << mtms.machineTypeAndModelRaw()[i];
70b6664339SMatt Spinler }
71b6664339SMatt Spinler
72b6664339SMatt Spinler for (size_t i = 0; i < MTMS::snSize; i++)
73b6664339SMatt Spinler {
744b59f7adSMatt Spinler s << mtms.machineSerialNumberRaw()[i];
75b6664339SMatt Spinler }
76b6664339SMatt Spinler
77b6664339SMatt Spinler return s;
78b6664339SMatt Spinler }
79b6664339SMatt Spinler
operator >>(Stream & s,MTMS & mtms)80b6664339SMatt Spinler Stream& operator>>(Stream& s, MTMS& mtms)
81b6664339SMatt Spinler {
82*654708fdSMatt Spinler std::array<uint8_t, MTMS::mtmSize> mtm;
83*654708fdSMatt Spinler
84b6664339SMatt Spinler for (size_t i = 0; i < MTMS::mtmSize; i++)
85b6664339SMatt Spinler {
86*654708fdSMatt Spinler s >> mtm[i];
87b6664339SMatt Spinler }
88b6664339SMatt Spinler
89*654708fdSMatt Spinler mtms.setMachineTypeAndModel(mtm);
90*654708fdSMatt Spinler
91*654708fdSMatt Spinler std::array<uint8_t, MTMS::snSize> sn;
92b6664339SMatt Spinler for (size_t i = 0; i < MTMS::snSize; i++)
93b6664339SMatt Spinler {
94*654708fdSMatt Spinler s >> sn[i];
95b6664339SMatt Spinler }
96b6664339SMatt Spinler
97*654708fdSMatt Spinler mtms.setMachineSerialNumber(sn);
98*654708fdSMatt Spinler
99b6664339SMatt Spinler return s;
100b6664339SMatt Spinler }
101b6664339SMatt Spinler } // namespace pels
102b6664339SMatt Spinler } // namespace openpower
103