Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 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 | */ |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 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 | |
Matt Spinler | 654708f | 2019-11-06 09:59:07 -0600 | [diff] [blame] | 65 | Stream& operator<<(Stream& s, const MTMS& mtms) |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 66 | { |
| 67 | for (size_t i = 0; i < MTMS::mtmSize; i++) |
| 68 | { |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 69 | s << mtms.machineTypeAndModelRaw()[i]; |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | for (size_t i = 0; i < MTMS::snSize; i++) |
| 73 | { |
Matt Spinler | 4b59f7a | 2019-10-08 13:55:17 -0500 | [diff] [blame] | 74 | s << mtms.machineSerialNumberRaw()[i]; |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | return s; |
| 78 | } |
| 79 | |
| 80 | Stream& operator>>(Stream& s, MTMS& mtms) |
| 81 | { |
Matt Spinler | 654708f | 2019-11-06 09:59:07 -0600 | [diff] [blame] | 82 | std::array<uint8_t, MTMS::mtmSize> mtm; |
| 83 | |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 84 | for (size_t i = 0; i < MTMS::mtmSize; i++) |
| 85 | { |
Matt Spinler | 654708f | 2019-11-06 09:59:07 -0600 | [diff] [blame] | 86 | s >> mtm[i]; |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Matt Spinler | 654708f | 2019-11-06 09:59:07 -0600 | [diff] [blame] | 89 | mtms.setMachineTypeAndModel(mtm); |
| 90 | |
| 91 | std::array<uint8_t, MTMS::snSize> sn; |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 92 | for (size_t i = 0; i < MTMS::snSize; i++) |
| 93 | { |
Matt Spinler | 654708f | 2019-11-06 09:59:07 -0600 | [diff] [blame] | 94 | s >> sn[i]; |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Matt Spinler | 654708f | 2019-11-06 09:59:07 -0600 | [diff] [blame] | 97 | mtms.setMachineSerialNumber(sn); |
| 98 | |
Matt Spinler | b666433 | 2019-09-10 15:24:10 -0500 | [diff] [blame] | 99 | return s; |
| 100 | } |
| 101 | } // namespace pels |
| 102 | } // namespace openpower |