blob: 90c247212af8574284cca13b9ef6360a5821fb77 [file] [log] [blame]
James Feist7136a5a2018-07-19 09:52:05 -07001/*
2// Copyright (c) 2018 Intel 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*/
Patrick Venture7e952d92020-10-05 15:58:52 -070016#include "dbusconfiguration.hpp"
James Feist7136a5a2018-07-19 09:52:05 -070017
Patrick Venture07716592018-10-14 11:46:40 -070018#include "conf.hpp"
Patrick Ventureef1f8862020-08-17 09:34:35 -070019#include "dbushelper.hpp"
20#include "dbusutil.hpp"
James Feist0c8223b2019-05-08 15:33:33 -070021#include "util.hpp"
Patrick Venture07716592018-10-14 11:46:40 -070022
James Feist1fe08952019-05-07 09:17:16 -070023#include <boost/asio/steady_timer.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -070024#include <sdbusplus/bus.hpp>
25#include <sdbusplus/bus/match.hpp>
26#include <sdbusplus/exception.hpp>
27
28#include <algorithm>
James Feist64f072a2018-08-10 16:39:24 -070029#include <chrono>
James Feist64f072a2018-08-10 16:39:24 -070030#include <functional>
James Feist7136a5a2018-07-19 09:52:05 -070031#include <iostream>
James Feist1fe08952019-05-07 09:17:16 -070032#include <list>
James Feist7136a5a2018-07-19 09:52:05 -070033#include <set>
34#include <unordered_map>
James Feist1f802f52019-02-08 13:51:43 -080035#include <variant>
James Feist7136a5a2018-07-19 09:52:05 -070036
Patrick Venturea0764872020-08-08 07:48:43 -070037namespace pid_control
38{
39
James Feist7136a5a2018-07-19 09:52:05 -070040static constexpr bool DEBUG = false; // enable to print found configuration
41
James Feistf81f2882019-02-26 11:26:36 -080042extern std::map<std::string, struct conf::SensorConfig> sensorConfig;
43extern std::map<int64_t, conf::PIDConf> zoneConfig;
44extern std::map<int64_t, struct conf::ZoneConfig> zoneDetailsConfig;
James Feist7136a5a2018-07-19 09:52:05 -070045
Patrick Venturee2ec0f62018-09-04 12:30:27 -070046constexpr const char* pidConfigurationInterface =
James Feist7136a5a2018-07-19 09:52:05 -070047 "xyz.openbmc_project.Configuration.Pid";
Patrick Venturee2ec0f62018-09-04 12:30:27 -070048constexpr const char* objectManagerInterface =
James Feist7136a5a2018-07-19 09:52:05 -070049 "org.freedesktop.DBus.ObjectManager";
Patrick Venturee2ec0f62018-09-04 12:30:27 -070050constexpr const char* pidZoneConfigurationInterface =
James Feist7136a5a2018-07-19 09:52:05 -070051 "xyz.openbmc_project.Configuration.Pid.Zone";
James Feist22c257a2018-08-31 14:07:12 -070052constexpr const char* stepwiseConfigurationInterface =
53 "xyz.openbmc_project.Configuration.Stepwise";
James Feistf0096a02019-02-21 11:25:22 -080054constexpr const char* thermalControlIface =
55 "xyz.openbmc_project.Control.ThermalMode";
Patrick Venturee2ec0f62018-09-04 12:30:27 -070056constexpr const char* sensorInterface = "xyz.openbmc_project.Sensor.Value";
Patrick Venture0911bfe2020-08-10 12:51:40 -070057constexpr const char* defaultPwmInterface =
58 "xyz.openbmc_project.Control.FanPwm";
James Feist7136a5a2018-07-19 09:52:05 -070059
James Feist991ebd82020-07-21 11:14:52 -070060using Association = std::tuple<std::string, std::string, std::string>;
61using Associations = std::vector<Association>;
62
James Feist5ec20272019-07-10 11:59:57 -070063namespace thresholds
64{
65constexpr const char* warningInterface =
66 "xyz.openbmc_project.Sensor.Threshold.Warning";
67constexpr const char* criticalInterface =
68 "xyz.openbmc_project.Sensor.Threshold.Critical";
69const std::array<const char*, 4> types = {"CriticalLow", "CriticalHigh",
70 "WarningLow", "WarningHigh"};
71
72} // namespace thresholds
73
James Feist7136a5a2018-07-19 09:52:05 -070074namespace dbus_configuration
75{
Jason Lingf3b04fd2020-07-24 09:33:04 -070076using SensorInterfaceType = std::pair<std::string, std::string>;
77
78inline std::string getSensorNameFromPath(const std::string& dbusPath)
79{
80 return dbusPath.substr(dbusPath.find_last_of("/") + 1);
81}
82
83inline std::string sensorNameToDbusName(const std::string& sensorName)
84{
85 std::string retString = sensorName;
86 std::replace(retString.begin(), retString.end(), ' ', '_');
87 return retString;
88}
James Feist5ec20272019-07-10 11:59:57 -070089
James Feist7136a5a2018-07-19 09:52:05 -070090// this function prints the configuration into a form similar to the cpp
91// generated code to help in verification, should be turned off during normal
92// use
93void debugPrint(void)
94{
95 // print sensor config
96 std::cout << "sensor config:\n";
97 std::cout << "{\n";
Patrick Venturec54fbd82018-10-30 19:40:05 -070098 for (const auto& pair : sensorConfig)
James Feist7136a5a2018-07-19 09:52:05 -070099 {
100
101 std::cout << "\t{" << pair.first << ",\n\t\t{";
102 std::cout << pair.second.type << ", ";
Patrick Venture69c51062019-02-11 09:46:03 -0800103 std::cout << pair.second.readPath << ", ";
104 std::cout << pair.second.writePath << ", ";
James Feist7136a5a2018-07-19 09:52:05 -0700105 std::cout << pair.second.min << ", ";
106 std::cout << pair.second.max << ", ";
107 std::cout << pair.second.timeout << "},\n\t},\n";
108 }
109 std::cout << "}\n\n";
110 std::cout << "ZoneDetailsConfig\n";
111 std::cout << "{\n";
Patrick Venturec54fbd82018-10-30 19:40:05 -0700112 for (const auto& zone : zoneDetailsConfig)
James Feist7136a5a2018-07-19 09:52:05 -0700113 {
114 std::cout << "\t{" << zone.first << ",\n";
James Feist3484bed2019-02-25 13:28:18 -0800115 std::cout << "\t\t{" << zone.second.minThermalOutput << ", ";
Patrick Venture8e2fdb32019-02-11 09:39:59 -0800116 std::cout << zone.second.failsafePercent << "}\n\t},\n";
James Feist7136a5a2018-07-19 09:52:05 -0700117 }
118 std::cout << "}\n\n";
119 std::cout << "ZoneConfig\n";
120 std::cout << "{\n";
Patrick Venturec54fbd82018-10-30 19:40:05 -0700121 for (const auto& zone : zoneConfig)
James Feist7136a5a2018-07-19 09:52:05 -0700122 {
123 std::cout << "\t{" << zone.first << "\n";
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700124 for (const auto& pidconf : zone.second)
James Feist7136a5a2018-07-19 09:52:05 -0700125 {
126 std::cout << "\t\t{" << pidconf.first << ",\n";
127 std::cout << "\t\t\t{" << pidconf.second.type << ",\n";
128 std::cout << "\t\t\t{";
Patrick Venture4a2dc4d2018-10-23 09:02:55 -0700129 for (const auto& input : pidconf.second.inputs)
James Feist7136a5a2018-07-19 09:52:05 -0700130 {
131 std::cout << "\n\t\t\t" << input << ",\n";
132 }
133 std::cout << "\t\t\t}\n";
134 std::cout << "\t\t\t" << pidconf.second.setpoint << ",\n";
James Feist22c257a2018-08-31 14:07:12 -0700135 std::cout << "\t\t\t{" << pidconf.second.pidInfo.ts << ",\n";
Patrick Venture7442c372019-02-11 10:21:05 -0800136 std::cout << "\t\t\t" << pidconf.second.pidInfo.proportionalCoeff
137 << ",\n";
138 std::cout << "\t\t\t" << pidconf.second.pidInfo.integralCoeff
139 << ",\n";
140 std::cout << "\t\t\t" << pidconf.second.pidInfo.feedFwdOffset
141 << ",\n";
142 std::cout << "\t\t\t" << pidconf.second.pidInfo.feedFwdGain
143 << ",\n";
144 std::cout << "\t\t\t{" << pidconf.second.pidInfo.integralLimit.min
145 << "," << pidconf.second.pidInfo.integralLimit.max
146 << "},\n";
147 std::cout << "\t\t\t{" << pidconf.second.pidInfo.outLim.min << ","
148 << pidconf.second.pidInfo.outLim.max << "},\n";
149 std::cout << "\t\t\t" << pidconf.second.pidInfo.slewNeg << ",\n";
150 std::cout << "\t\t\t" << pidconf.second.pidInfo.slewPos << ",\n";
James Feist7136a5a2018-07-19 09:52:05 -0700151 std::cout << "\t\t\t}\n\t\t}\n";
152 }
153 std::cout << "\t},\n";
154 }
155 std::cout << "}\n\n";
156}
157
Josh Lehan998fbe62020-09-20 21:21:05 -0700158int64_t setZoneIndex(const std::string& name,
159 std::map<std::string, int64_t>& zones, int64_t index)
James Feistffd418b2018-11-15 14:46:36 -0800160{
Josh Lehan998fbe62020-09-20 21:21:05 -0700161 auto it = zones.find(name);
162 if (it != zones.end())
James Feistffd418b2018-11-15 14:46:36 -0800163 {
Josh Lehan998fbe62020-09-20 21:21:05 -0700164 // Name already allocated, make no change, return existing
165 return it->second;
James Feistffd418b2018-11-15 14:46:36 -0800166 }
167
Josh Lehan998fbe62020-09-20 21:21:05 -0700168 // The zone name is known not to exist yet
169 for (;;)
170 {
171 bool usedIndex = false;
172
173 // See if desired index number is free
174 for (const auto& zi : zones)
175 {
176 if (index == zi.second)
177 {
178 usedIndex = true;
179 break;
180 }
181 }
182
183 // Increment until a free index number is found
184 if (usedIndex)
185 {
186 ++index;
187 continue;
188 }
189
190 break;
191 }
192
193 // Allocate and return new zone index number for this name
194 zones[name] = index;
195 return index;
196}
197
198int64_t getZoneIndex(const std::string& name,
199 std::map<std::string, int64_t>& zones)
200{
201 auto it = zones.find(name);
202 if (it != zones.end())
203 {
204 return it->second;
205 }
206
207 // Auto-assign next unused zone number, using 0-based numbering
208 return setZoneIndex(name, zones, 0);
James Feistffd418b2018-11-15 14:46:36 -0800209}
210
James Feistf0096a02019-02-21 11:25:22 -0800211std::vector<std::string> getSelectedProfiles(sdbusplus::bus::bus& bus)
212{
213 std::vector<std::string> ret;
214 auto mapper =
215 bus.new_method_call("xyz.openbmc_project.ObjectMapper",
216 "/xyz/openbmc_project/object_mapper",
217 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
218 mapper.append("/", 0, std::array<const char*, 1>{thermalControlIface});
219 std::unordered_map<
220 std::string, std::unordered_map<std::string, std::vector<std::string>>>
221 respData;
222
223 try
224 {
225 auto resp = bus.call(mapper);
226 resp.read(respData);
227 }
228 catch (sdbusplus::exception_t&)
229 {
230 // can't do anything without mapper call data
231 throw std::runtime_error("ObjectMapper Call Failure");
232 }
233 if (respData.empty())
234 {
235 // if the user has profiles but doesn't expose the interface to select
236 // one, just go ahead without using profiles
237 return ret;
238 }
239
240 // assumption is that we should only have a small handful of selected
241 // profiles at a time (probably only 1), so calling each individually should
242 // not incur a large cost
243 for (const auto& objectPair : respData)
244 {
245 const std::string& path = objectPair.first;
246 for (const auto& ownerPair : objectPair.second)
247 {
248 const std::string& busName = ownerPair.first;
249 auto getProfile =
250 bus.new_method_call(busName.c_str(), path.c_str(),
251 "org.freedesktop.DBus.Properties", "Get");
252 getProfile.append(thermalControlIface, "Current");
253 std::variant<std::string> variantResp;
254 try
255 {
256 auto resp = bus.call(getProfile);
257 resp.read(variantResp);
258 }
259 catch (sdbusplus::exception_t&)
260 {
261 throw std::runtime_error("Failure getting profile");
262 }
263 std::string mode = std::get<std::string>(variantResp);
264 ret.emplace_back(std::move(mode));
265 }
266 }
267 if constexpr (DEBUG)
268 {
269 std::cout << "Profiles selected: ";
270 for (const auto& profile : ret)
271 {
272 std::cout << profile << " ";
273 }
274 std::cout << "\n";
275 }
276 return ret;
277}
278
James Feist991ebd82020-07-21 11:14:52 -0700279int eventHandler(sd_bus_message* m, void* context, sd_bus_error*)
James Feist7136a5a2018-07-19 09:52:05 -0700280{
James Feist1fe08952019-05-07 09:17:16 -0700281
James Feist991ebd82020-07-21 11:14:52 -0700282 if (context == nullptr || m == nullptr)
James Feist1fe08952019-05-07 09:17:16 -0700283 {
284 throw std::runtime_error("Invalid match");
285 }
James Feist991ebd82020-07-21 11:14:52 -0700286
287 // we skip associations because the mapper populates these, not the sensors
288 const std::array<const char*, 1> skipList = {
289 "xyz.openbmc_project.Association"};
290
291 sdbusplus::message::message message(m);
292 if (std::string(message.get_member()) == "InterfacesAdded")
293 {
294 sdbusplus::message::object_path path;
295 std::unordered_map<
296 std::string,
297 std::unordered_map<std::string, std::variant<Associations, bool>>>
298 data;
299
300 message.read(path, data);
301
302 for (const char* skip : skipList)
303 {
304 auto find = data.find(skip);
305 if (find != data.end())
306 {
307 data.erase(find);
308 if (data.empty())
309 {
310 return 1;
311 }
312 }
313 }
314 }
315
James Feist1fe08952019-05-07 09:17:16 -0700316 boost::asio::steady_timer* timer =
317 static_cast<boost::asio::steady_timer*>(context);
318
319 // do a brief sleep as we tend to get a bunch of these events at
320 // once
321 timer->expires_after(std::chrono::seconds(2));
322 timer->async_wait([](const boost::system::error_code ec) {
323 if (ec == boost::asio::error::operation_aborted)
324 {
325 /* another timer started*/
326 return;
327 }
328
329 std::cout << "New configuration detected, reloading\n.";
Yong Li298a95c2020-04-07 15:11:02 +0800330 tryRestartControlLoops();
James Feist1fe08952019-05-07 09:17:16 -0700331 });
332
333 return 1;
334}
335
336void createMatches(sdbusplus::bus::bus& bus, boost::asio::steady_timer& timer)
337{
338 // this is a list because the matches can't be moved
339 static std::list<sdbusplus::bus::match::match> matches;
340
James Feist3987c8b2019-05-13 10:43:17 -0700341 const std::array<std::string, 4> interfaces = {
342 thermalControlIface, pidConfigurationInterface,
343 pidZoneConfigurationInterface, stepwiseConfigurationInterface};
James Feist1fe08952019-05-07 09:17:16 -0700344
345 // this list only needs to be created once
346 if (!matches.empty())
347 {
348 return;
349 }
350
351 // we restart when the configuration changes or there are new sensors
352 for (const auto& interface : interfaces)
353 {
354 matches.emplace_back(
355 bus,
356 "type='signal',member='PropertiesChanged',arg0namespace='" +
357 interface + "'",
358 eventHandler, &timer);
359 }
360 matches.emplace_back(
361 bus,
362 "type='signal',member='InterfacesAdded',arg0path='/xyz/openbmc_project/"
363 "sensors/'",
364 eventHandler, &timer);
365}
366
Jason Ling6fc301f2020-07-23 12:39:57 -0700367/**
368 * retrieve an attribute from the pid configuration map
369 * @param[in] base - the PID configuration map, keys are the attributes and
370 * value is the variant associated with that attribute.
371 * @param attributeName - the name of the attribute
372 * @return a variant holding the value associated with a key
373 * @throw runtime_error : attributeName is not in base
374 */
375inline DbusVariantType getPIDAttribute(
376 const std::unordered_map<std::string, DbusVariantType>& base,
377 const std::string& attributeName)
378{
379 auto search = base.find(attributeName);
380 if (search == base.end())
381 {
382 throw std::runtime_error("missing attribute " + attributeName);
383 }
384 return search->second;
385}
386
James Feist5ec20272019-07-10 11:59:57 -0700387void populatePidInfo(
388 sdbusplus::bus::bus& bus,
389 const std::unordered_map<std::string, DbusVariantType>& base,
390 struct conf::ControllerInfo& info, const std::string* thresholdProperty)
391{
Jason Ling6fc301f2020-07-23 12:39:57 -0700392 info.type = std::get<std::string>(getPIDAttribute(base, "Class"));
James Feist5ec20272019-07-10 11:59:57 -0700393 if (info.type == "fan")
394 {
395 info.setpoint = 0;
396 }
397 else
398 {
Jason Ling6fc301f2020-07-23 12:39:57 -0700399 info.setpoint = std::visit(VariantToDoubleVisitor(),
400 getPIDAttribute(base, "SetPoint"));
James Feist5ec20272019-07-10 11:59:57 -0700401 }
402
403 if (thresholdProperty != nullptr)
404 {
405 std::string interface;
406 if (*thresholdProperty == "WarningHigh" ||
407 *thresholdProperty == "WarningLow")
408 {
409 interface = thresholds::warningInterface;
410 }
411 else
412 {
413 interface = thresholds::criticalInterface;
414 }
415 const std::string& path = sensorConfig[info.inputs.front()].readPath;
416
Patrick Venture8729eb92020-08-10 10:38:44 -0700417 DbusHelper helper(sdbusplus::bus::new_system());
Patrick Venture9b936922020-08-10 11:28:39 -0700418 std::string service = helper.getService(interface, path);
James Feist5ec20272019-07-10 11:59:57 -0700419 double reading = 0;
420 try
421 {
Patrick Venture9b936922020-08-10 11:28:39 -0700422 helper.getProperty(service, path, interface, *thresholdProperty,
423 reading);
James Feist5ec20272019-07-10 11:59:57 -0700424 }
425 catch (const sdbusplus::exception::SdBusError& ex)
426 {
427 // unsupported threshold, leaving reading at 0
428 }
429
430 info.setpoint += reading;
431 }
432
433 info.pidInfo.ts = 1.0; // currently unused
Jason Ling6fc301f2020-07-23 12:39:57 -0700434 info.pidInfo.proportionalCoeff = std::visit(
435 VariantToDoubleVisitor(), getPIDAttribute(base, "PCoefficient"));
436 info.pidInfo.integralCoeff = std::visit(
437 VariantToDoubleVisitor(), getPIDAttribute(base, "ICoefficient"));
438 info.pidInfo.feedFwdOffset = std::visit(
439 VariantToDoubleVisitor(), getPIDAttribute(base, "FFOffCoefficient"));
440 info.pidInfo.feedFwdGain = std::visit(
441 VariantToDoubleVisitor(), getPIDAttribute(base, "FFGainCoefficient"));
442 info.pidInfo.integralLimit.max = std::visit(
443 VariantToDoubleVisitor(), getPIDAttribute(base, "ILimitMax"));
444 info.pidInfo.integralLimit.min = std::visit(
445 VariantToDoubleVisitor(), getPIDAttribute(base, "ILimitMin"));
446 info.pidInfo.outLim.max = std::visit(VariantToDoubleVisitor(),
447 getPIDAttribute(base, "OutLimitMax"));
448 info.pidInfo.outLim.min = std::visit(VariantToDoubleVisitor(),
449 getPIDAttribute(base, "OutLimitMin"));
James Feist5ec20272019-07-10 11:59:57 -0700450 info.pidInfo.slewNeg =
Jason Ling6fc301f2020-07-23 12:39:57 -0700451 std::visit(VariantToDoubleVisitor(), getPIDAttribute(base, "SlewNeg"));
James Feist5ec20272019-07-10 11:59:57 -0700452 info.pidInfo.slewPos =
Jason Ling6fc301f2020-07-23 12:39:57 -0700453 std::visit(VariantToDoubleVisitor(), getPIDAttribute(base, "SlewPos"));
James Feist5ec20272019-07-10 11:59:57 -0700454 double negativeHysteresis = 0;
455 double positiveHysteresis = 0;
456
457 auto findNeg = base.find("NegativeHysteresis");
458 auto findPos = base.find("PositiveHysteresis");
459
460 if (findNeg != base.end())
461 {
462 negativeHysteresis =
463 std::visit(VariantToDoubleVisitor(), findNeg->second);
464 }
465
466 if (findPos != base.end())
467 {
468 positiveHysteresis =
469 std::visit(VariantToDoubleVisitor(), findPos->second);
470 }
James Feist5ec20272019-07-10 11:59:57 -0700471 info.pidInfo.negativeHysteresis = negativeHysteresis;
472 info.pidInfo.positiveHysteresis = positiveHysteresis;
473}
474
James Feist1fe08952019-05-07 09:17:16 -0700475bool init(sdbusplus::bus::bus& bus, boost::asio::steady_timer& timer)
476{
477
478 sensorConfig.clear();
479 zoneConfig.clear();
480 zoneDetailsConfig.clear();
481
482 createMatches(bus, timer);
483
James Feist7136a5a2018-07-19 09:52:05 -0700484 auto mapper =
485 bus.new_method_call("xyz.openbmc_project.ObjectMapper",
486 "/xyz/openbmc_project/object_mapper",
487 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feist26e8c6a2018-10-25 10:38:26 -0700488 mapper.append("/", 0,
Patrick Venture0911bfe2020-08-10 12:51:40 -0700489 std::array<const char*, 6>{
490 objectManagerInterface, pidConfigurationInterface,
491 pidZoneConfigurationInterface,
492 stepwiseConfigurationInterface, sensorInterface,
493 defaultPwmInterface});
James Feist7136a5a2018-07-19 09:52:05 -0700494 std::unordered_map<
495 std::string, std::unordered_map<std::string, std::vector<std::string>>>
496 respData;
James Feist22c257a2018-08-31 14:07:12 -0700497 try
498 {
499 auto resp = bus.call(mapper);
James Feist22c257a2018-08-31 14:07:12 -0700500 resp.read(respData);
501 }
502 catch (sdbusplus::exception_t&)
503 {
504 // can't do anything without mapper call data
505 throw std::runtime_error("ObjectMapper Call Failure");
506 }
James Feist7136a5a2018-07-19 09:52:05 -0700507
James Feist7136a5a2018-07-19 09:52:05 -0700508 if (respData.empty())
509 {
James Feist22c257a2018-08-31 14:07:12 -0700510 // can't do anything without mapper call data
James Feist7136a5a2018-07-19 09:52:05 -0700511 throw std::runtime_error("No configuration data available from Mapper");
512 }
513 // create a map of pair of <has pid configuration, ObjectManager path>
514 std::unordered_map<std::string, std::pair<bool, std::string>> owners;
515 // and a map of <path, interface> for sensors
516 std::unordered_map<std::string, std::string> sensors;
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700517 for (const auto& objectPair : respData)
James Feist7136a5a2018-07-19 09:52:05 -0700518 {
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700519 for (const auto& ownerPair : objectPair.second)
James Feist7136a5a2018-07-19 09:52:05 -0700520 {
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700521 auto& owner = owners[ownerPair.first];
522 for (const std::string& interface : ownerPair.second)
James Feist7136a5a2018-07-19 09:52:05 -0700523 {
524
525 if (interface == objectManagerInterface)
526 {
527 owner.second = objectPair.first;
528 }
529 if (interface == pidConfigurationInterface ||
James Feist22c257a2018-08-31 14:07:12 -0700530 interface == pidZoneConfigurationInterface ||
531 interface == stepwiseConfigurationInterface)
James Feist7136a5a2018-07-19 09:52:05 -0700532 {
533 owner.first = true;
534 }
Patrick Venture0911bfe2020-08-10 12:51:40 -0700535 if (interface == sensorInterface ||
536 interface == defaultPwmInterface)
James Feist7136a5a2018-07-19 09:52:05 -0700537 {
538 // we're not interested in pwm sensors, just pwm control
539 if (interface == sensorInterface &&
540 objectPair.first.find("pwm") != std::string::npos)
541 {
542 continue;
543 }
544 sensors[objectPair.first] = interface;
545 }
546 }
547 }
548 }
549 ManagedObjectType configurations;
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700550 for (const auto& owner : owners)
James Feist7136a5a2018-07-19 09:52:05 -0700551 {
552 // skip if no pid configuration (means probably a sensor)
553 if (!owner.second.first)
554 {
555 continue;
556 }
557 auto endpoint = bus.new_method_call(
558 owner.first.c_str(), owner.second.second.c_str(),
559 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
James Feist22c257a2018-08-31 14:07:12 -0700560 ManagedObjectType configuration;
561 try
James Feist7136a5a2018-07-19 09:52:05 -0700562 {
James Feist22c257a2018-08-31 14:07:12 -0700563 auto responce = bus.call(endpoint);
James Feist22c257a2018-08-31 14:07:12 -0700564 responce.read(configuration);
565 }
566 catch (sdbusplus::exception_t&)
567 {
568 // this shouldn't happen, probably means daemon crashed
James Feist7136a5a2018-07-19 09:52:05 -0700569 throw std::runtime_error("Error getting managed objects from " +
570 owner.first);
571 }
James Feist22c257a2018-08-31 14:07:12 -0700572
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700573 for (auto& pathPair : configuration)
James Feist7136a5a2018-07-19 09:52:05 -0700574 {
575 if (pathPair.second.find(pidConfigurationInterface) !=
576 pathPair.second.end() ||
577 pathPair.second.find(pidZoneConfigurationInterface) !=
James Feist22c257a2018-08-31 14:07:12 -0700578 pathPair.second.end() ||
579 pathPair.second.find(stepwiseConfigurationInterface) !=
James Feist7136a5a2018-07-19 09:52:05 -0700580 pathPair.second.end())
581 {
582 configurations.emplace(pathPair);
583 }
James Feistf0096a02019-02-21 11:25:22 -0800584 }
585 }
586
587 // remove controllers from config that aren't in the current profile(s)
James Feist3987c8b2019-05-13 10:43:17 -0700588 std::vector<std::string> selectedProfiles = getSelectedProfiles(bus);
589 if (selectedProfiles.size())
James Feistf0096a02019-02-21 11:25:22 -0800590 {
James Feist3987c8b2019-05-13 10:43:17 -0700591 for (auto pathIt = configurations.begin();
592 pathIt != configurations.end();)
James Feistf0096a02019-02-21 11:25:22 -0800593 {
James Feist3987c8b2019-05-13 10:43:17 -0700594 for (auto confIt = pathIt->second.begin();
595 confIt != pathIt->second.end();)
James Feistf0096a02019-02-21 11:25:22 -0800596 {
James Feist3987c8b2019-05-13 10:43:17 -0700597 auto profilesFind = confIt->second.find("Profiles");
598 if (profilesFind == confIt->second.end())
James Feistf0096a02019-02-21 11:25:22 -0800599 {
James Feist3987c8b2019-05-13 10:43:17 -0700600 confIt++;
601 continue; // if no profiles selected, apply always
602 }
603 auto profiles =
604 std::get<std::vector<std::string>>(profilesFind->second);
605 if (profiles.empty())
606 {
607 confIt++;
608 continue;
609 }
610
611 bool found = false;
612 for (const std::string& profile : profiles)
613 {
614 if (std::find(selectedProfiles.begin(),
615 selectedProfiles.end(),
616 profile) != selectedProfiles.end())
617 {
618 found = true;
619 break;
620 }
621 }
622 if (found)
623 {
624 confIt++;
James Feistf0096a02019-02-21 11:25:22 -0800625 }
626 else
627 {
James Feist3987c8b2019-05-13 10:43:17 -0700628 confIt = pathIt->second.erase(confIt);
James Feistf0096a02019-02-21 11:25:22 -0800629 }
630 }
James Feist3987c8b2019-05-13 10:43:17 -0700631 if (pathIt->second.empty())
James Feistf0096a02019-02-21 11:25:22 -0800632 {
James Feist3987c8b2019-05-13 10:43:17 -0700633 pathIt = configurations.erase(pathIt);
James Feistf0096a02019-02-21 11:25:22 -0800634 }
James Feist3987c8b2019-05-13 10:43:17 -0700635 else
James Feistf0096a02019-02-21 11:25:22 -0800636 {
James Feist3987c8b2019-05-13 10:43:17 -0700637 pathIt++;
James Feistf0096a02019-02-21 11:25:22 -0800638 }
James Feist7136a5a2018-07-19 09:52:05 -0700639 }
640 }
James Feist8c3c51e2018-08-08 16:31:43 -0700641
Josh Lehan998fbe62020-09-20 21:21:05 -0700642 // On D-Bus, although not necessary,
643 // having the "zoneID" field can still be useful,
644 // as it is used for diagnostic messages,
645 // logging file names, and so on.
646 // Accept optional "ZoneIndex" parameter to explicitly specify.
647 // If not present, or not unique, auto-assign index,
648 // using 0-based numbering, ensuring uniqueness.
649 std::map<std::string, int64_t> foundZones;
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700650 for (const auto& configuration : configurations)
James Feist7136a5a2018-07-19 09:52:05 -0700651 {
652 auto findZone =
653 configuration.second.find(pidZoneConfigurationInterface);
654 if (findZone != configuration.second.end())
655 {
Patrick Venturee2ec0f62018-09-04 12:30:27 -0700656 const auto& zone = findZone->second;
James Feistffd418b2018-11-15 14:46:36 -0800657
James Feist1f802f52019-02-08 13:51:43 -0800658 const std::string& name = std::get<std::string>(zone.at("Name"));
Josh Lehan998fbe62020-09-20 21:21:05 -0700659
660 auto findZoneIndex = zone.find("ZoneIndex");
661 if (findZoneIndex == zone.end())
662 {
663 continue;
664 }
665
666 auto ptrZoneIndex = std::get_if<double>(&(findZoneIndex->second));
667 if (!ptrZoneIndex)
668 {
669 continue;
670 }
671
672 auto desiredIndex = static_cast<int64_t>(*ptrZoneIndex);
673 auto grantedIndex = setZoneIndex(name, foundZones, desiredIndex);
674 std::cout << "Zone " << name << " is at ZoneIndex " << grantedIndex
675 << "\n";
676 }
677 }
678
679 for (const auto& configuration : configurations)
680 {
681 auto findZone =
682 configuration.second.find(pidZoneConfigurationInterface);
683 if (findZone != configuration.second.end())
684 {
685 const auto& zone = findZone->second;
686
687 const std::string& name = std::get<std::string>(zone.at("Name"));
688
689 auto index = getZoneIndex(name, foundZones);
James Feist8c3c51e2018-08-08 16:31:43 -0700690
Patrick Venturec54fbd82018-10-30 19:40:05 -0700691 auto& details = zoneDetailsConfig[index];
Josh Lehan998fbe62020-09-20 21:21:05 -0700692
James Feist3484bed2019-02-25 13:28:18 -0800693 details.minThermalOutput = std::visit(VariantToDoubleVisitor(),
694 zone.at("MinThermalOutput"));
Patrick Venture8e2fdb32019-02-11 09:39:59 -0800695 details.failsafePercent = std::visit(VariantToDoubleVisitor(),
James Feist1f802f52019-02-08 13:51:43 -0800696 zone.at("FailSafePercent"));
James Feist7136a5a2018-07-19 09:52:05 -0700697 }
698 auto findBase = configuration.second.find(pidConfigurationInterface);
Jason Lingf3b04fd2020-07-24 09:33:04 -0700699 // loop through all the PID configurations and fill out a sensor config
James Feist22c257a2018-08-31 14:07:12 -0700700 if (findBase != configuration.second.end())
James Feist7136a5a2018-07-19 09:52:05 -0700701 {
James Feist22c257a2018-08-31 14:07:12 -0700702 const auto& base =
703 configuration.second.at(pidConfigurationInterface);
Jason Lingf3b04fd2020-07-24 09:33:04 -0700704 const std::string pidName = std::get<std::string>(base.at("Name"));
705 const std::string pidClass =
706 std::get<std::string>(base.at("Class"));
James Feist22c257a2018-08-31 14:07:12 -0700707 const std::vector<std::string>& zones =
James Feist1f802f52019-02-08 13:51:43 -0800708 std::get<std::vector<std::string>>(base.at("Zones"));
James Feist22c257a2018-08-31 14:07:12 -0700709 for (const std::string& zone : zones)
James Feist7136a5a2018-07-19 09:52:05 -0700710 {
Josh Lehan998fbe62020-09-20 21:21:05 -0700711 auto index = getZoneIndex(zone, foundZones);
712
James Feistf81f2882019-02-26 11:26:36 -0800713 conf::PIDConf& conf = zoneConfig[index];
Jason Lingf3b04fd2020-07-24 09:33:04 -0700714 std::vector<std::string> inputSensorNames(
715 std::get<std::vector<std::string>>(base.at("Inputs")));
716 std::vector<std::string> outputSensorNames;
James Feist50fdfe32018-09-24 15:51:09 -0700717
Jason Lingf3b04fd2020-07-24 09:33:04 -0700718 // assumption: all fan pids must have at least one output
719 if (pidClass == "fan")
James Feist50fdfe32018-09-24 15:51:09 -0700720 {
Jason Lingf3b04fd2020-07-24 09:33:04 -0700721 outputSensorNames = std::get<std::vector<std::string>>(
722 getPIDAttribute(base, "Outputs"));
James Feist50fdfe32018-09-24 15:51:09 -0700723 }
James Feist1738e2a2019-02-04 15:57:03 -0800724
Jason Lingf3b04fd2020-07-24 09:33:04 -0700725 std::vector<SensorInterfaceType> inputSensorInterfaces;
726 std::vector<SensorInterfaceType> outputSensorInterfaces;
727 /* populate an interface list for different sensor direction
728 * types (input,output)
729 */
730 /* take the Inputs from the configuration and generate
731 * a list of dbus descriptors (path, interface).
732 * Mapping can be many-to-one since an element of Inputs can be
733 * a regex
734 */
735 for (const std::string& sensorName : inputSensorNames)
James Feist50fdfe32018-09-24 15:51:09 -0700736 {
Jason Lingf3b04fd2020-07-24 09:33:04 -0700737 findSensors(sensors, sensorNameToDbusName(sensorName),
738 inputSensorInterfaces);
739 }
740 for (const std::string& sensorName : outputSensorNames)
741 {
742 findSensors(sensors, sensorNameToDbusName(sensorName),
743 outputSensorInterfaces);
James Feist1738e2a2019-02-04 15:57:03 -0800744 }
James Feist50fdfe32018-09-24 15:51:09 -0700745
Jason Lingf3b04fd2020-07-24 09:33:04 -0700746 inputSensorNames.clear();
747 for (const SensorInterfaceType& inputSensorInterface :
748 inputSensorInterfaces)
James Feist1738e2a2019-02-04 15:57:03 -0800749 {
Jason Lingf3b04fd2020-07-24 09:33:04 -0700750 const std::string& dbusInterface =
751 inputSensorInterface.second;
752 const std::string& inputSensorPath =
753 inputSensorInterface.first;
754 std::string inputSensorName =
755 getSensorNameFromPath(inputSensorPath);
756 auto& config = sensorConfig[inputSensorName];
757 inputSensorNames.push_back(inputSensorName);
758 config.type = pidClass;
759 config.readPath = inputSensorInterface.first;
760 // todo: maybe un-hardcode this if we run into slower
761 // timeouts with sensors
762 if (config.type == "temp")
James Feist50fdfe32018-09-24 15:51:09 -0700763 {
Jason Lingf3b04fd2020-07-24 09:33:04 -0700764 config.timeout = 0;
765 config.ignoreDbusMinMax = true;
James Feist50fdfe32018-09-24 15:51:09 -0700766 }
Jason Lingf3b04fd2020-07-24 09:33:04 -0700767 if (dbusInterface != sensorInterface)
James Feist50fdfe32018-09-24 15:51:09 -0700768 {
Jason Lingf3b04fd2020-07-24 09:33:04 -0700769 /* all expected inputs in the configuration are expected
770 * to be sensor interfaces
771 */
772 throw std::runtime_error(
773 "sensor at dbus path [" + inputSensorPath +
774 "] has an interface [" + dbusInterface +
775 "] that does not match the expected interface of " +
776 sensorInterface);
James Feist50fdfe32018-09-24 15:51:09 -0700777 }
778 }
James Feist1738e2a2019-02-04 15:57:03 -0800779
Jason Lingf3b04fd2020-07-24 09:33:04 -0700780 /* fan pids need to pair up tach sensors with their pwm
781 * counterparts
782 */
783 if (pidClass == "fan")
784 {
785 /* If a PID is a fan there should be either
786 * (1) one output(pwm) per input(tach)
787 * OR
788 * (2) one putput(pwm) for all inputs(tach)
789 * everything else indicates a bad configuration.
790 */
791 bool singlePwm = false;
792 if (outputSensorInterfaces.size() == 1)
793 {
794 /* one pwm, set write paths for all fan sensors to it */
795 singlePwm = true;
796 }
797 else if (inputSensorInterfaces.size() ==
798 outputSensorInterfaces.size())
799 {
800 /* one to one mapping, each fan sensor gets its own pwm
801 * control */
802 singlePwm = false;
803 }
804 else
805 {
806 throw std::runtime_error(
807 "fan PID has invalid number of Outputs");
808 }
809 std::string fanSensorName;
810 std::string pwmPath;
811 std::string pwmInterface;
812 if (singlePwm)
813 {
814 /* if just a single output(pwm) is provided then use
815 * that pwm control path for all the fan sensor write
816 * path configs
817 */
818 pwmPath = outputSensorInterfaces.at(0).first;
819 pwmInterface = outputSensorInterfaces.at(0).second;
820 }
821 for (uint32_t idx = 0; idx < inputSensorInterfaces.size();
822 idx++)
823 {
824 if (!singlePwm)
825 {
826 pwmPath = outputSensorInterfaces.at(idx).first;
827 pwmInterface =
828 outputSensorInterfaces.at(idx).second;
829 }
Patrick Venture0911bfe2020-08-10 12:51:40 -0700830 if (defaultPwmInterface != pwmInterface)
Jason Lingf3b04fd2020-07-24 09:33:04 -0700831 {
832 throw std::runtime_error(
833 "fan pwm control at dbus path [" + pwmPath +
834 "] has an interface [" + pwmInterface +
835 "] that does not match the expected interface "
836 "of " +
Patrick Venture0911bfe2020-08-10 12:51:40 -0700837 defaultPwmInterface);
Jason Lingf3b04fd2020-07-24 09:33:04 -0700838 }
839 const std::string& fanPath =
840 inputSensorInterfaces.at(idx).first;
841 fanSensorName = getSensorNameFromPath(fanPath);
842 auto& fanConfig = sensorConfig[fanSensorName];
843 fanConfig.writePath = pwmPath;
844 // todo: un-hardcode this if there are fans with
845 // different ranges
846 fanConfig.max = 255;
847 fanConfig.min = 0;
848 }
849 }
James Feist11d243d2019-06-24 16:18:40 -0700850 // if the sensors aren't available in the current state, don't
851 // add them to the configuration.
Jason Lingf3b04fd2020-07-24 09:33:04 -0700852 if (inputSensorNames.empty())
James Feist11d243d2019-06-24 16:18:40 -0700853 {
854 continue;
855 }
856
James Feist5ec20272019-07-10 11:59:57 -0700857 std::string offsetType;
James Feist50fdfe32018-09-24 15:51:09 -0700858
James Feist5ec20272019-07-10 11:59:57 -0700859 // SetPointOffset is a threshold value to pull from the sensor
860 // to apply an offset. For upper thresholds this means the
861 // setpoint is usually negative.
862 auto findSetpointOffset = base.find("SetPointOffset");
863 if (findSetpointOffset != base.end())
James Feist22c257a2018-08-31 14:07:12 -0700864 {
James Feist5ec20272019-07-10 11:59:57 -0700865 offsetType =
866 std::get<std::string>(findSetpointOffset->second);
867 if (std::find(thresholds::types.begin(),
868 thresholds::types.end(),
869 offsetType) == thresholds::types.end())
870 {
871 throw std::runtime_error("Unsupported type: " +
872 offsetType);
873 }
874 }
875
876 if (offsetType.empty())
877 {
878 struct conf::ControllerInfo& info =
879 conf[std::get<std::string>(base.at("Name"))];
Jason Lingf3b04fd2020-07-24 09:33:04 -0700880 info.inputs = std::move(inputSensorNames);
James Feist5ec20272019-07-10 11:59:57 -0700881 populatePidInfo(bus, base, info, nullptr);
James Feist22c257a2018-08-31 14:07:12 -0700882 }
883 else
884 {
James Feist5ec20272019-07-10 11:59:57 -0700885 // we have to split up the inputs, as in practice t-control
886 // values will differ, making setpoints differ
Jason Lingf3b04fd2020-07-24 09:33:04 -0700887 for (const std::string& input : inputSensorNames)
James Feist5ec20272019-07-10 11:59:57 -0700888 {
889 struct conf::ControllerInfo& info = conf[input];
890 info.inputs.emplace_back(input);
891 populatePidInfo(bus, base, info, &offsetType);
892 }
James Feist22c257a2018-08-31 14:07:12 -0700893 }
James Feist22c257a2018-08-31 14:07:12 -0700894 }
895 }
896 auto findStepwise =
897 configuration.second.find(stepwiseConfigurationInterface);
898 if (findStepwise != configuration.second.end())
899 {
900 const auto& base = findStepwise->second;
901 const std::vector<std::string>& zones =
James Feist1f802f52019-02-08 13:51:43 -0800902 std::get<std::vector<std::string>>(base.at("Zones"));
James Feist22c257a2018-08-31 14:07:12 -0700903 for (const std::string& zone : zones)
904 {
Josh Lehan998fbe62020-09-20 21:21:05 -0700905 auto index = getZoneIndex(zone, foundZones);
906
James Feistf81f2882019-02-26 11:26:36 -0800907 conf::PIDConf& conf = zoneConfig[index];
James Feist50fdfe32018-09-24 15:51:09 -0700908
909 std::vector<std::string> inputs;
910 std::vector<std::string> sensorNames =
James Feist1f802f52019-02-08 13:51:43 -0800911 std::get<std::vector<std::string>>(base.at("Inputs"));
James Feist50fdfe32018-09-24 15:51:09 -0700912
James Feist1738e2a2019-02-04 15:57:03 -0800913 bool sensorFound = false;
James Feist50fdfe32018-09-24 15:51:09 -0700914 for (const std::string& sensorName : sensorNames)
915 {
James Feist1738e2a2019-02-04 15:57:03 -0800916 std::vector<std::pair<std::string, std::string>>
917 sensorPathIfacePairs;
Jason Lingf3b04fd2020-07-24 09:33:04 -0700918 if (!findSensors(sensors, sensorNameToDbusName(sensorName),
919 sensorPathIfacePairs))
James Feist50fdfe32018-09-24 15:51:09 -0700920 {
James Feist50fdfe32018-09-24 15:51:09 -0700921 break;
922 }
923
James Feist1738e2a2019-02-04 15:57:03 -0800924 for (const auto& sensorPathIfacePair : sensorPathIfacePairs)
925 {
926 size_t idx =
927 sensorPathIfacePair.first.find_last_of("/") + 1;
928 std::string shortName =
929 sensorPathIfacePair.first.substr(idx);
James Feist50fdfe32018-09-24 15:51:09 -0700930
James Feist1738e2a2019-02-04 15:57:03 -0800931 inputs.push_back(shortName);
932 auto& config = sensorConfig[shortName];
Patrick Venture69c51062019-02-11 09:46:03 -0800933 config.readPath = sensorPathIfacePair.first;
James Feist1738e2a2019-02-04 15:57:03 -0800934 config.type = "temp";
James Feist3660b382019-11-11 16:29:19 -0800935 config.ignoreDbusMinMax = true;
James Feist1738e2a2019-02-04 15:57:03 -0800936 // todo: maybe un-hardcode this if we run into slower
937 // timeouts with sensors
938
James Feist2642cb52019-02-25 13:00:16 -0800939 config.timeout = 0;
James Feist1738e2a2019-02-04 15:57:03 -0800940 sensorFound = true;
941 }
James Feist50fdfe32018-09-24 15:51:09 -0700942 }
943 if (!sensorFound)
944 {
945 continue;
946 }
James Feistf81f2882019-02-26 11:26:36 -0800947 struct conf::ControllerInfo& info =
James Feist1f802f52019-02-08 13:51:43 -0800948 conf[std::get<std::string>(base.at("Name"))];
James Feist50fdfe32018-09-24 15:51:09 -0700949 info.inputs = std::move(inputs);
950
James Feist22c257a2018-08-31 14:07:12 -0700951 info.type = "stepwise";
952 info.stepwiseInfo.ts = 1.0; // currently unused
James Feist3dfaafd2018-09-20 15:46:58 -0700953 info.stepwiseInfo.positiveHysteresis = 0.0;
954 info.stepwiseInfo.negativeHysteresis = 0.0;
James Feist608304d2019-02-25 10:01:42 -0800955 std::string subtype = std::get<std::string>(base.at("Class"));
956
957 info.stepwiseInfo.isCeiling = (subtype == "Ceiling");
James Feist3dfaafd2018-09-20 15:46:58 -0700958 auto findPosHyst = base.find("PositiveHysteresis");
959 auto findNegHyst = base.find("NegativeHysteresis");
960 if (findPosHyst != base.end())
961 {
James Feist1f802f52019-02-08 13:51:43 -0800962 info.stepwiseInfo.positiveHysteresis = std::visit(
James Feist208abce2018-12-06 09:59:10 -0800963 VariantToDoubleVisitor(), findPosHyst->second);
James Feist3dfaafd2018-09-20 15:46:58 -0700964 }
965 if (findNegHyst != base.end())
966 {
James Feist5782ab82019-04-02 08:38:48 -0700967 info.stepwiseInfo.negativeHysteresis = std::visit(
James Feist208abce2018-12-06 09:59:10 -0800968 VariantToDoubleVisitor(), findNegHyst->second);
James Feist3dfaafd2018-09-20 15:46:58 -0700969 }
James Feist22c257a2018-08-31 14:07:12 -0700970 std::vector<double> readings =
James Feist1f802f52019-02-08 13:51:43 -0800971 std::get<std::vector<double>>(base.at("Reading"));
James Feist22c257a2018-08-31 14:07:12 -0700972 if (readings.size() > ec::maxStepwisePoints)
973 {
974 throw std::invalid_argument("Too many stepwise points.");
975 }
976 if (readings.empty())
977 {
978 throw std::invalid_argument(
979 "Must have one stepwise point.");
980 }
981 std::copy(readings.begin(), readings.end(),
982 info.stepwiseInfo.reading);
983 if (readings.size() < ec::maxStepwisePoints)
984 {
985 info.stepwiseInfo.reading[readings.size()] =
Patrick Venture5f59c0f2018-11-11 12:55:14 -0800986 std::numeric_limits<double>::quiet_NaN();
James Feist22c257a2018-08-31 14:07:12 -0700987 }
988 std::vector<double> outputs =
James Feist1f802f52019-02-08 13:51:43 -0800989 std::get<std::vector<double>>(base.at("Output"));
James Feist22c257a2018-08-31 14:07:12 -0700990 if (readings.size() != outputs.size())
991 {
992 throw std::invalid_argument(
993 "Outputs size must match readings");
994 }
995 std::copy(outputs.begin(), outputs.end(),
996 info.stepwiseInfo.output);
997 if (outputs.size() < ec::maxStepwisePoints)
998 {
999 info.stepwiseInfo.output[outputs.size()] =
Patrick Venture5f59c0f2018-11-11 12:55:14 -08001000 std::numeric_limits<double>::quiet_NaN();
James Feist22c257a2018-08-31 14:07:12 -07001001 }
James Feist7136a5a2018-07-19 09:52:05 -07001002 }
1003 }
1004 }
James Feistf0096a02019-02-21 11:25:22 -08001005 if constexpr (DEBUG)
James Feist7136a5a2018-07-19 09:52:05 -07001006 {
1007 debugPrint();
1008 }
James Feistc959c422018-11-01 12:33:40 -07001009 if (zoneConfig.empty() || zoneDetailsConfig.empty())
James Feist50fdfe32018-09-24 15:51:09 -07001010 {
James Feist1fe08952019-05-07 09:17:16 -07001011 std::cerr
1012 << "No fan zones, application pausing until new configuration\n";
1013 return false;
James Feist50fdfe32018-09-24 15:51:09 -07001014 }
James Feist1fe08952019-05-07 09:17:16 -07001015 return true;
James Feist7136a5a2018-07-19 09:52:05 -07001016}
Patrick Venturea0764872020-08-08 07:48:43 -07001017
James Feist7136a5a2018-07-19 09:52:05 -07001018} // namespace dbus_configuration
Patrick Venturea0764872020-08-08 07:48:43 -07001019} // namespace pid_control