139199b4dSPatrick Venture /* 239199b4dSPatrick Venture // Copyright (c) 2018 Intel Corporation 339199b4dSPatrick Venture // 439199b4dSPatrick Venture // Licensed under the Apache License, Version 2.0 (the "License"); 539199b4dSPatrick Venture // you may not use this file except in compliance with the License. 639199b4dSPatrick Venture // You may obtain a copy of the License at 739199b4dSPatrick Venture // 839199b4dSPatrick Venture // http://www.apache.org/licenses/LICENSE-2.0 939199b4dSPatrick Venture // 1039199b4dSPatrick Venture // Unless required by applicable law or agreed to in writing, software 1139199b4dSPatrick Venture // distributed under the License is distributed on an "AS IS" BASIS, 1239199b4dSPatrick Venture // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1339199b4dSPatrick Venture // See the License for the specific language governing permissions and 1439199b4dSPatrick Venture // limitations under the License. 1539199b4dSPatrick Venture */ 1639199b4dSPatrick Venture #include "util.hpp" 1739199b4dSPatrick Venture 1839199b4dSPatrick Venture #include "conf.hpp" 1939199b4dSPatrick Venture 2039199b4dSPatrick Venture #include <cstdint> 2139199b4dSPatrick Venture #include <iostream> 2239199b4dSPatrick Venture #include <map> 2339199b4dSPatrick Venture #include <string> 2439199b4dSPatrick Venture 2539199b4dSPatrick Venture namespace pid_control 2639199b4dSPatrick Venture { 2739199b4dSPatrick Venture 2839199b4dSPatrick Venture void debugPrint(const std::map<std::string, conf::SensorConfig>& sensorConfig, 2939199b4dSPatrick Venture const std::map<int64_t, conf::PIDConf>& zoneConfig, 3039199b4dSPatrick Venture const std::map<int64_t, conf::ZoneConfig>& zoneDetailsConfig) 3139199b4dSPatrick Venture { 3239199b4dSPatrick Venture if constexpr (!conf::DEBUG) 3339199b4dSPatrick Venture { 3439199b4dSPatrick Venture return; 3539199b4dSPatrick Venture } 3639199b4dSPatrick Venture // print sensor config 3739199b4dSPatrick Venture std::cout << "sensor config:\n"; 3839199b4dSPatrick Venture std::cout << "{\n"; 3939199b4dSPatrick Venture for (const auto& pair : sensorConfig) 4039199b4dSPatrick Venture { 4139199b4dSPatrick Venture std::cout << "\t{" << pair.first << ",\n\t\t{"; 4239199b4dSPatrick Venture std::cout << pair.second.type << ", "; 4339199b4dSPatrick Venture std::cout << pair.second.readPath << ", "; 4439199b4dSPatrick Venture std::cout << pair.second.writePath << ", "; 4539199b4dSPatrick Venture std::cout << pair.second.min << ", "; 4639199b4dSPatrick Venture std::cout << pair.second.max << ", "; 478f73ad76SAlex.Song std::cout << pair.second.timeout << ", "; 488f73ad76SAlex.Song std::cout << pair.second.unavailableAsFailed << "},\n\t},\n"; 4939199b4dSPatrick Venture } 5039199b4dSPatrick Venture std::cout << "}\n\n"; 5139199b4dSPatrick Venture std::cout << "ZoneDetailsConfig\n"; 5239199b4dSPatrick Venture std::cout << "{\n"; 5339199b4dSPatrick Venture for (const auto& zone : zoneDetailsConfig) 5439199b4dSPatrick Venture { 5539199b4dSPatrick Venture std::cout << "\t{" << zone.first << ",\n"; 5639199b4dSPatrick Venture std::cout << "\t\t{" << zone.second.minThermalOutput << ", "; 5739199b4dSPatrick Venture std::cout << zone.second.failsafePercent << "}\n\t},\n"; 5839199b4dSPatrick Venture } 5939199b4dSPatrick Venture std::cout << "}\n\n"; 6039199b4dSPatrick Venture std::cout << "ZoneConfig\n"; 6139199b4dSPatrick Venture std::cout << "{\n"; 6239199b4dSPatrick Venture for (const auto& zone : zoneConfig) 6339199b4dSPatrick Venture { 6439199b4dSPatrick Venture std::cout << "\t{" << zone.first << "\n"; 6539199b4dSPatrick Venture for (const auto& pidconf : zone.second) 6639199b4dSPatrick Venture { 6739199b4dSPatrick Venture std::cout << "\t\t{" << pidconf.first << ",\n"; 6839199b4dSPatrick Venture std::cout << "\t\t\t{" << pidconf.second.type << ",\n"; 6939199b4dSPatrick Venture std::cout << "\t\t\t{"; 7039199b4dSPatrick Venture for (const auto& input : pidconf.second.inputs) 7139199b4dSPatrick Venture { 72*31058fd3SJosh Lehan std::cout << "\n\t\t\t" << input.name; 73*31058fd3SJosh Lehan if (input.convertTempToMargin) 74*31058fd3SJosh Lehan { 75*31058fd3SJosh Lehan std::cout << "[" << input.convertMarginZero << "]"; 76*31058fd3SJosh Lehan } 77*31058fd3SJosh Lehan std::cout << ",\n"; 7839199b4dSPatrick Venture } 7939199b4dSPatrick Venture std::cout << "\t\t\t}\n"; 8039199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.setpoint << ",\n"; 8139199b4dSPatrick Venture std::cout << "\t\t\t{" << pidconf.second.pidInfo.ts << ",\n"; 8239199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.pidInfo.proportionalCoeff 8339199b4dSPatrick Venture << ",\n"; 8439199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.pidInfo.integralCoeff 8539199b4dSPatrick Venture << ",\n"; 8639199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.pidInfo.feedFwdOffset 8739199b4dSPatrick Venture << ",\n"; 8839199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.pidInfo.feedFwdGain 8939199b4dSPatrick Venture << ",\n"; 9039199b4dSPatrick Venture std::cout << "\t\t\t{" << pidconf.second.pidInfo.integralLimit.min 9139199b4dSPatrick Venture << "," << pidconf.second.pidInfo.integralLimit.max 9239199b4dSPatrick Venture << "},\n"; 9339199b4dSPatrick Venture std::cout << "\t\t\t{" << pidconf.second.pidInfo.outLim.min << "," 9439199b4dSPatrick Venture << pidconf.second.pidInfo.outLim.max << "},\n"; 9539199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.pidInfo.slewNeg << ",\n"; 9639199b4dSPatrick Venture std::cout << "\t\t\t" << pidconf.second.pidInfo.slewPos << ",\n"; 9739199b4dSPatrick Venture std::cout << "\t\t\t}\n\t\t}\n"; 9839199b4dSPatrick Venture } 9939199b4dSPatrick Venture std::cout << "\t},\n"; 10039199b4dSPatrick Venture } 10139199b4dSPatrick Venture std::cout << "}\n\n"; 10239199b4dSPatrick Venture } 10339199b4dSPatrick Venture 104*31058fd3SJosh Lehan std::vector<conf::SensorInput> 105*31058fd3SJosh Lehan spliceInputs(const std::vector<std::string>& inputNames, 106*31058fd3SJosh Lehan const std::vector<double>& inputTempToMargin) 107*31058fd3SJosh Lehan { 108*31058fd3SJosh Lehan std::vector<conf::SensorInput> results; 109*31058fd3SJosh Lehan 110*31058fd3SJosh Lehan // Default to the TempToMargin feature disabled 111*31058fd3SJosh Lehan for (const auto& inputName : inputNames) 112*31058fd3SJosh Lehan { 113*31058fd3SJosh Lehan conf::SensorInput newInput{ 114*31058fd3SJosh Lehan inputName, std::numeric_limits<double>::quiet_NaN(), false}; 115*31058fd3SJosh Lehan 116*31058fd3SJosh Lehan results.emplace_back(newInput); 117*31058fd3SJosh Lehan } 118*31058fd3SJosh Lehan 119*31058fd3SJosh Lehan size_t resultSize = results.size(); 120*31058fd3SJosh Lehan size_t marginSize = inputTempToMargin.size(); 121*31058fd3SJosh Lehan 122*31058fd3SJosh Lehan for (size_t index = 0; index < resultSize; ++index) 123*31058fd3SJosh Lehan { 124*31058fd3SJosh Lehan // If fewer doubles than strings, and vice versa, ignore remainder 125*31058fd3SJosh Lehan if (index >= marginSize) 126*31058fd3SJosh Lehan { 127*31058fd3SJosh Lehan break; 128*31058fd3SJosh Lehan } 129*31058fd3SJosh Lehan 130*31058fd3SJosh Lehan // Both vectors have this index, combine both into SensorInput 131*31058fd3SJosh Lehan results[index].convertMarginZero = inputTempToMargin[index]; 132*31058fd3SJosh Lehan results[index].convertTempToMargin = true; 133*31058fd3SJosh Lehan } 134*31058fd3SJosh Lehan 135*31058fd3SJosh Lehan return results; 136*31058fd3SJosh Lehan } 137*31058fd3SJosh Lehan 138*31058fd3SJosh Lehan std::vector<std::string> 139*31058fd3SJosh Lehan splitNames(const std::vector<conf::SensorInput>& sensorInputs) 140*31058fd3SJosh Lehan { 141*31058fd3SJosh Lehan std::vector<std::string> results; 142*31058fd3SJosh Lehan 143*31058fd3SJosh Lehan for (const auto& sensorInput : sensorInputs) 144*31058fd3SJosh Lehan { 145*31058fd3SJosh Lehan results.emplace_back(sensorInput.name); 146*31058fd3SJosh Lehan } 147*31058fd3SJosh Lehan 148*31058fd3SJosh Lehan return results; 149*31058fd3SJosh Lehan } 150*31058fd3SJosh Lehan 15139199b4dSPatrick Venture } // namespace pid_control 152