1 /** 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 */ 16 #include "mtms.hpp" 17 18 namespace openpower 19 { 20 namespace pels 21 { 22 23 MTMS::MTMS() 24 { 25 memset(_machineTypeAndModel.data(), 0, mtmSize); 26 memset(_serialNumber.data(), 0, snSize); 27 } 28 29 MTMS::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 52 MTMS::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 65 Stream& operator<<(Stream& s, const MTMS& mtms) 66 { 67 for (size_t i = 0; i < MTMS::mtmSize; i++) 68 { 69 s << mtms.machineTypeAndModelRaw()[i]; 70 } 71 72 for (size_t i = 0; i < MTMS::snSize; i++) 73 { 74 s << mtms.machineSerialNumberRaw()[i]; 75 } 76 77 return s; 78 } 79 80 Stream& operator>>(Stream& s, MTMS& mtms) 81 { 82 std::array<uint8_t, MTMS::mtmSize> mtm; 83 84 for (size_t i = 0; i < MTMS::mtmSize; i++) 85 { 86 s >> mtm[i]; 87 } 88 89 mtms.setMachineTypeAndModel(mtm); 90 91 std::array<uint8_t, MTMS::snSize> sn; 92 for (size_t i = 0; i < MTMS::snSize; i++) 93 { 94 s >> sn[i]; 95 } 96 97 mtms.setMachineSerialNumber(sn); 98 99 return s; 100 } 101 } // namespace pels 102 } // namespace openpower 103