blob: d3fb6c1be18831521dacadd41c93a7870118ceec [file] [log] [blame]
James Feistbc896df2018-11-26 16:28:17 -08001/*
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*/
16
17#include "ExitAirTempSensor.hpp"
18
19#include "Utils.hpp"
20#include "VariantVisitors.hpp"
21
22#include <math.h>
23
24#include <boost/algorithm/string/predicate.hpp>
25#include <boost/algorithm/string/replace.hpp>
26#include <chrono>
27#include <iostream>
28#include <limits>
29#include <numeric>
30#include <sdbusplus/asio/connection.hpp>
31#include <sdbusplus/asio/object_server.hpp>
32#include <vector>
33
34constexpr const float altitudeFactor = 1.14;
35constexpr const char* exitAirIface =
36 "xyz.openbmc_project.Configuration.ExitAirTempSensor";
37constexpr const char* cfmIface = "xyz.openbmc_project.Configuration.CFMSensor";
38
39// todo: this *might* need to be configurable
40constexpr const char* inletTemperatureSensor = "temperature/Front_Panel_Temp";
James Feistbc896df2018-11-26 16:28:17 -080041
42static constexpr bool DEBUG = false;
43
James Feistb2eb3f52018-12-04 16:17:50 -080044static constexpr double cfmMaxReading = 255;
45static constexpr double cfmMinReading = 0;
46
47static void setupSensorMatch(
48 std::vector<sdbusplus::bus::match::match>& matches,
49 sdbusplus::bus::bus& connection, const std::string& type,
50 std::function<void(const double&, sdbusplus::message::message&)>&& callback)
51{
52
53 std::function<void(sdbusplus::message::message & message)> eventHandler =
54 [callback{std::move(callback)}](sdbusplus::message::message& message) {
55 std::string objectName;
James Feist3eb82622019-02-08 13:10:22 -080056 boost::container::flat_map<std::string,
57 std::variant<double, int64_t>>
James Feistb2eb3f52018-12-04 16:17:50 -080058 values;
59 message.read(objectName, values);
60 auto findValue = values.find("Value");
61 if (findValue == values.end())
62 {
63 return;
64 }
James Feist3eb82622019-02-08 13:10:22 -080065 double value =
66 std::visit(VariantToDoubleVisitor(), findValue->second);
James Feist9566bfa2019-01-29 15:31:23 -080067 if (std::isnan(value))
68 {
69 return;
70 }
71
James Feistb2eb3f52018-12-04 16:17:50 -080072 callback(value, message);
73 };
74 matches.emplace_back(connection,
75 "type='signal',"
76 "member='PropertiesChanged',interface='org."
77 "freedesktop.DBus.Properties',path_"
78 "namespace='/xyz/openbmc_project/sensors/" +
79 std::string(type) +
80 "',arg0='xyz.openbmc_project.Sensor.Value'",
81 std::move(eventHandler));
82}
83
James Feistb2eb3f52018-12-04 16:17:50 -080084CFMSensor::CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
85 const std::string& sensorName,
86 const std::string& sensorConfiguration,
87 sdbusplus::asio::object_server& objectServer,
88 std::vector<thresholds::Threshold>&& thresholds,
89 std::shared_ptr<ExitAirTempSensor>& parent) :
90 Sensor(boost::replace_all_copy(sensorName, " ", "_"),
91 "" /* todo: remove arg from base*/, std::move(thresholds),
92 sensorConfiguration, "xyz.openbmc_project.Configuration.ExitAirTemp",
93 cfmMaxReading, cfmMinReading),
James Feist9566bfa2019-01-29 15:31:23 -080094 dbusConnection(conn), parent(parent), objServer(objectServer)
James Feistb2eb3f52018-12-04 16:17:50 -080095{
96 sensorInterface =
97 objectServer.add_interface("/xyz/openbmc_project/sensors/cfm/" + name,
98 "xyz.openbmc_project.Sensor.Value");
99
100 if (thresholds::hasWarningInterface(thresholds))
101 {
102 thresholdInterfaceWarning = objectServer.add_interface(
103 "/xyz/openbmc_project/sensors/cfm/" + name,
104 "xyz.openbmc_project.Sensor.Threshold.Warning");
105 }
106 if (thresholds::hasCriticalInterface(thresholds))
107 {
108 thresholdInterfaceCritical = objectServer.add_interface(
109 "/xyz/openbmc_project/sensors/cfm/" + name,
110 "xyz.openbmc_project.Sensor.Threshold.Critical");
111 }
112 setInitialProperties(conn);
113 setupSensorMatch(
114 matches, *dbusConnection, "fan_tach",
115 std::move(
116 [this](const double& value, sdbusplus::message::message& message) {
117 tachReadings[message.get_path()] = value;
118 if (tachRanges.find(message.get_path()) == tachRanges.end())
119 {
120 // calls update reading after updating ranges
121 addTachRanges(message.get_sender(), message.get_path());
122 }
123 else
124 {
125 updateReading();
126 }
127 }));
128}
129
James Feist9566bfa2019-01-29 15:31:23 -0800130CFMSensor::~CFMSensor()
131{
132 objServer.remove_interface(thresholdInterfaceWarning);
133 objServer.remove_interface(thresholdInterfaceCritical);
134 objServer.remove_interface(sensorInterface);
135}
136
James Feistb2eb3f52018-12-04 16:17:50 -0800137void CFMSensor::addTachRanges(const std::string& serviceName,
138 const std::string& path)
139{
140 dbusConnection->async_method_call(
141 [this, path](const boost::system::error_code ec,
142 const boost::container::flat_map<std::string,
143 BasicVariantType>& data) {
144 if (ec)
145 {
146 std::cerr << "Error getting properties from " << path << "\n";
James Feist1ccdb5e2019-01-24 09:44:01 -0800147 return;
James Feistb2eb3f52018-12-04 16:17:50 -0800148 }
149
150 double max = loadVariant<double>(data, "MaxValue");
151 double min = loadVariant<double>(data, "MinValue");
152 tachRanges[path] = std::make_pair(min, max);
153 updateReading();
154 },
155 serviceName, path, "org.freedesktop.DBus.Properties", "GetAll",
156 "xyz.openbmc_project.Sensor.Value");
157}
158
159void CFMSensor::checkThresholds(void)
160{
161 thresholds::checkThresholds(this);
162}
163
164void CFMSensor::updateReading(void)
165{
166 double val = 0.0;
167 if (calculate(val))
168 {
169 if (value != val && parent)
170 {
171 parent->updateReading();
172 }
173 updateValue(val);
174 }
175 else
176 {
177 updateValue(std::numeric_limits<double>::quiet_NaN());
178 }
179}
180
181bool CFMSensor::calculate(double& value)
182{
183 double totalCFM = 0;
184 for (const std::string& tachName : tachs)
185 {
James Feist9566bfa2019-01-29 15:31:23 -0800186
James Feistb2eb3f52018-12-04 16:17:50 -0800187 auto findReading = std::find_if(
188 tachReadings.begin(), tachReadings.end(), [&](const auto& item) {
189 return boost::ends_with(item.first, tachName);
190 });
191 auto findRange = std::find_if(
192 tachRanges.begin(), tachRanges.end(), [&](const auto& item) {
193 return boost::ends_with(item.first, tachName);
194 });
195 if (findReading == tachReadings.end())
196 {
James Feista96329f2019-01-24 10:08:27 -0800197 if (DEBUG)
198 {
199 std::cerr << "Can't find " << tachName << "in readings\n";
200 }
James Feist9566bfa2019-01-29 15:31:23 -0800201 continue; // haven't gotten a reading
James Feistb2eb3f52018-12-04 16:17:50 -0800202 }
203
204 if (findRange == tachRanges.end())
205 {
James Feist523828e2019-03-04 14:38:37 -0800206 std::cerr << "Can't find " << tachName << " in ranges\n";
James Feistb2eb3f52018-12-04 16:17:50 -0800207 return false; // haven't gotten a max / min
208 }
209
210 // avoid divide by 0
211 if (findRange->second.second == 0)
212 {
213 std::cerr << "Tach Max Set to 0 " << tachName << "\n";
214 return false;
215 }
216
217 double rpm = findReading->second;
218
219 // for now assume the min for a fan is always 0, divide by max to get
220 // percent and mult by 100
221 rpm /= findRange->second.second;
222 rpm *= 100;
223
224 if constexpr (DEBUG)
225 {
226 std::cout << "Tach " << tachName << "at " << rpm << "\n";
227 }
228
229 // Do a linear interpolation to get Ci
230 // Ci = C1 + (C2 - C1)/(RPM2 - RPM1) * (TACHi - TACH1)
231
232 double ci = 0;
233 if (rpm == 0)
234 {
235 ci = 0;
236 }
237 else if (rpm < tachMinPercent)
238 {
239 ci = c1;
240 }
241 else if (rpm > tachMaxPercent)
242 {
243 ci = c2;
244 }
245 else
246 {
247 ci = c1 + (((c2 - c1) * (rpm - tachMinPercent)) /
248 (tachMaxPercent - tachMinPercent));
249 }
250
251 // Now calculate the CFM for this tach
252 // CFMi = Ci * Qmaxi * TACHi
253 totalCFM += ci * maxCFM * rpm;
254 }
255
256 // divide by 100 since rpm is in percent
257 value = totalCFM / 100;
James Feist9566bfa2019-01-29 15:31:23 -0800258 return true;
James Feistb2eb3f52018-12-04 16:17:50 -0800259}
260
261static constexpr double exitAirMaxReading = 127;
262static constexpr double exitAirMinReading = -128;
James Feistbc896df2018-11-26 16:28:17 -0800263ExitAirTempSensor::ExitAirTempSensor(
264 std::shared_ptr<sdbusplus::asio::connection>& conn,
James Feistb2eb3f52018-12-04 16:17:50 -0800265 const std::string& sensorName, const std::string& sensorConfiguration,
James Feistbc896df2018-11-26 16:28:17 -0800266 sdbusplus::asio::object_server& objectServer,
267 std::vector<thresholds::Threshold>&& thresholds) :
James Feistb2eb3f52018-12-04 16:17:50 -0800268 Sensor(boost::replace_all_copy(sensorName, " ", "_"),
269 "" /* todo: remove arg from base*/, std::move(thresholds),
270 sensorConfiguration, "xyz.openbmc_project.Configuration.ExitAirTemp",
271 exitAirMaxReading, exitAirMinReading),
James Feist523828e2019-03-04 14:38:37 -0800272 dbusConnection(conn), objServer(objectServer)
James Feistbc896df2018-11-26 16:28:17 -0800273{
274 sensorInterface = objectServer.add_interface(
275 "/xyz/openbmc_project/sensors/temperature/" + name,
276 "xyz.openbmc_project.Sensor.Value");
277
278 if (thresholds::hasWarningInterface(thresholds))
279 {
280 thresholdInterfaceWarning = objectServer.add_interface(
281 "/xyz/openbmc_project/sensors/temperature/" + name,
282 "xyz.openbmc_project.Sensor.Threshold.Warning");
283 }
284 if (thresholds::hasCriticalInterface(thresholds))
285 {
286 thresholdInterfaceCritical = objectServer.add_interface(
287 "/xyz/openbmc_project/sensors/temperature/" + name,
288 "xyz.openbmc_project.Sensor.Threshold.Critical");
289 }
290 setInitialProperties(conn);
291 setupMatches();
James Feist71d31b22019-01-02 16:57:54 -0800292 setupPowerMatch(conn);
James Feistbc896df2018-11-26 16:28:17 -0800293}
294
295ExitAirTempSensor::~ExitAirTempSensor()
296{
James Feist523828e2019-03-04 14:38:37 -0800297 objServer.remove_interface(thresholdInterfaceWarning);
298 objServer.remove_interface(thresholdInterfaceCritical);
299 objServer.remove_interface(sensorInterface);
James Feistbc896df2018-11-26 16:28:17 -0800300}
301
302void ExitAirTempSensor::setupMatches(void)
303{
304
James Feistb2eb3f52018-12-04 16:17:50 -0800305 constexpr const std::array<const char*, 2> matchTypes = {
306 "power", inletTemperatureSensor};
James Feistbc896df2018-11-26 16:28:17 -0800307
James Feistb2eb3f52018-12-04 16:17:50 -0800308 for (const std::string& type : matchTypes)
James Feistbc896df2018-11-26 16:28:17 -0800309 {
James Feistb2eb3f52018-12-04 16:17:50 -0800310 setupSensorMatch(matches, *dbusConnection, type,
311 [this, type](const double& value,
312 sdbusplus::message::message& message) {
313 if (type == "power")
314 {
315 powerReadings[message.get_path()] = value;
316 }
317 else if (type == inletTemperatureSensor)
318 {
319 inletTemp = value;
320 }
321 updateReading();
322 });
James Feistbc896df2018-11-26 16:28:17 -0800323 }
James Feist9566bfa2019-01-29 15:31:23 -0800324 dbusConnection->async_method_call(
325 [this](boost::system::error_code ec,
326 const std::variant<double>& value) {
327 if (ec)
328 {
329 // sensor not ready yet
330 return;
331 }
332
James Feist3eb82622019-02-08 13:10:22 -0800333 inletTemp = std::visit(VariantToDoubleVisitor(), value);
James Feist9566bfa2019-01-29 15:31:23 -0800334 },
335 "xyz.openbmc_project.HwmonTempSensor",
336 std::string("/xyz/openbmc_project/sensors/") + inletTemperatureSensor,
337 "org.freedesktop.DBus.Properties", "Get",
338 "xyz.openbmc_project.Sensor.Value", "Value");
James Feistbc896df2018-11-26 16:28:17 -0800339}
340
341void ExitAirTempSensor::updateReading(void)
342{
343
344 double val = 0.0;
345 if (calculate(val))
346 {
347 updateValue(val);
348 }
349 else
350 {
351 updateValue(std::numeric_limits<double>::quiet_NaN());
352 }
353}
354
James Feistb2eb3f52018-12-04 16:17:50 -0800355double ExitAirTempSensor::getTotalCFM(void)
James Feistbc896df2018-11-26 16:28:17 -0800356{
James Feistb2eb3f52018-12-04 16:17:50 -0800357 double sum = 0;
358 for (auto& sensor : cfmSensors)
James Feistbc896df2018-11-26 16:28:17 -0800359 {
James Feistb2eb3f52018-12-04 16:17:50 -0800360 double reading = 0;
361 if (!sensor->calculate(reading))
James Feistbc896df2018-11-26 16:28:17 -0800362 {
James Feistbc896df2018-11-26 16:28:17 -0800363 return -1;
364 }
James Feistb2eb3f52018-12-04 16:17:50 -0800365 sum += reading;
James Feistbc896df2018-11-26 16:28:17 -0800366 }
James Feistb2eb3f52018-12-04 16:17:50 -0800367
368 return sum;
James Feistbc896df2018-11-26 16:28:17 -0800369}
370
371bool ExitAirTempSensor::calculate(double& val)
372{
373 static bool firstRead = false;
374 double cfm = getTotalCFM();
375 if (cfm <= 0)
376 {
377 std::cerr << "Error getting cfm\n";
378 return false;
379 }
380
381 // if there is an error getting inlet temp, return error
382 if (std::isnan(inletTemp))
383 {
384 std::cerr << "Cannot get inlet temp\n";
385 val = 0;
386 return false;
387 }
388
389 // if fans are off, just make the exit temp equal to inlet
James Feist71d31b22019-01-02 16:57:54 -0800390 if (!isPowerOn())
James Feistbc896df2018-11-26 16:28:17 -0800391 {
392 val = inletTemp;
393 return true;
394 }
395
396 double totalPower = 0;
397 for (const auto& reading : powerReadings)
398 {
399 if (std::isnan(reading.second))
400 {
401 continue;
402 }
403 totalPower += reading.second;
404 }
405
406 // Calculate power correction factor
407 // Ci = CL + (CH - CL)/(QMax - QMin) * (CFM - QMin)
408 float powerFactor = 0.0;
409 if (cfm <= qMin)
410 {
411 powerFactor = powerFactorMin;
412 }
413 else if (cfm >= qMax)
414 {
415 powerFactor = powerFactorMax;
416 }
417 else
418 {
419 powerFactor = powerFactorMin + ((powerFactorMax - powerFactorMin) /
420 (qMax - qMin) * (cfm - qMin));
421 }
422
423 totalPower *= powerFactor;
424 totalPower += pOffset;
425
426 if (totalPower == 0)
427 {
428 std::cerr << "total power 0\n";
429 val = 0;
430 return false;
431 }
432
433 if constexpr (DEBUG)
434 {
435 std::cout << "Power Factor " << powerFactor << "\n";
436 std::cout << "Inlet Temp " << inletTemp << "\n";
437 std::cout << "Total Power" << totalPower << "\n";
438 }
439
440 // Calculate the exit air temp
441 // Texit = Tfp + (1.76 * TotalPower / CFM * Faltitude)
442 double reading = 1.76 * totalPower * altitudeFactor;
443 reading /= cfm;
444 reading += inletTemp;
445
446 if constexpr (DEBUG)
447 {
448 std::cout << "Reading 1: " << reading << "\n";
449 }
450
451 // Now perform the exponential average
452 // Calculate alpha based on SDR values and CFM
453 // Ai = As + (Af - As)/(QMax - QMin) * (CFM - QMin)
454
455 double alpha = 0.0;
456 if (cfm < qMin)
457 {
458 alpha = alphaS;
459 }
460 else if (cfm >= qMax)
461 {
462 alpha = alphaF;
463 }
464 else
465 {
466 alpha = alphaS + ((alphaF - alphaS) * (cfm - qMin) / (qMax - qMin));
467 }
468
469 auto time = std::chrono::system_clock::now();
470 if (!firstRead)
471 {
472 firstRead = true;
473 lastTime = time;
474 lastReading = reading;
475 }
476 double alphaDT =
477 std::chrono::duration_cast<std::chrono::seconds>(time - lastTime)
478 .count() *
479 alpha;
480
481 // cap at 1.0 or the below fails
482 if (alphaDT > 1.0)
483 {
484 alphaDT = 1.0;
485 }
486
487 if constexpr (DEBUG)
488 {
489 std::cout << "AlphaDT: " << alphaDT << "\n";
490 }
491
492 reading = ((reading * alphaDT) + (lastReading * (1.0 - alphaDT)));
493
494 if constexpr (DEBUG)
495 {
496 std::cout << "Reading 2: " << reading << "\n";
497 }
498
499 val = reading;
500 lastReading = reading;
501 lastTime = time;
502 return true;
503}
504
505void ExitAirTempSensor::checkThresholds(void)
506{
507 thresholds::checkThresholds(this);
508}
509
James Feistbc896df2018-11-26 16:28:17 -0800510static void loadVariantPathArray(
511 const boost::container::flat_map<std::string, BasicVariantType>& data,
512 const std::string& key, std::vector<std::string>& resp)
513{
514 auto it = data.find(key);
515 if (it == data.end())
516 {
517 std::cerr << "Configuration missing " << key << "\n";
518 throw std::invalid_argument("Key Missing");
519 }
520 BasicVariantType copy = it->second;
James Feist3eb82622019-02-08 13:10:22 -0800521 std::vector<std::string> config = std::get<std::vector<std::string>>(copy);
James Feistbc896df2018-11-26 16:28:17 -0800522 for (auto& str : config)
523 {
524 boost::replace_all(str, " ", "_");
525 }
526 resp = std::move(config);
527}
528
529void createSensor(sdbusplus::asio::object_server& objectServer,
James Feistb2eb3f52018-12-04 16:17:50 -0800530 std::shared_ptr<ExitAirTempSensor>& exitAirSensor,
James Feistbc896df2018-11-26 16:28:17 -0800531 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
532{
533 if (!dbusConnection)
534 {
535 std::cerr << "Connection not created\n";
536 return;
537 }
538 dbusConnection->async_method_call(
539 [&](boost::system::error_code ec, const ManagedObjectType& resp) {
540 if (ec)
541 {
542 std::cerr << "Error contacting entity manager\n";
543 return;
544 }
James Feistb2eb3f52018-12-04 16:17:50 -0800545 std::vector<std::unique_ptr<CFMSensor>> cfmSensors;
James Feistbc896df2018-11-26 16:28:17 -0800546 for (const auto& pathPair : resp)
547 {
548 for (const auto& entry : pathPair.second)
549 {
550 if (entry.first == exitAirIface)
551 {
James Feistbc896df2018-11-26 16:28:17 -0800552 // thresholds should be under the same path
553 std::vector<thresholds::Threshold> sensorThresholds;
554 parseThresholdsFromConfig(pathPair.second,
555 sensorThresholds);
James Feistbc896df2018-11-26 16:28:17 -0800556
James Feist523828e2019-03-04 14:38:37 -0800557 std::string name =
558 loadVariant<std::string>(entry.second, "Name");
559 exitAirSensor = std::make_shared<ExitAirTempSensor>(
560 dbusConnection, name, pathPair.first.str,
561 objectServer, std::move(sensorThresholds));
James Feistb2eb3f52018-12-04 16:17:50 -0800562 exitAirSensor->powerFactorMin =
563 loadVariant<double>(entry.second, "PowerFactorMin");
564 exitAirSensor->powerFactorMax =
565 loadVariant<double>(entry.second, "PowerFactorMax");
566 exitAirSensor->qMin =
567 loadVariant<double>(entry.second, "QMin");
568 exitAirSensor->qMax =
569 loadVariant<double>(entry.second, "QMax");
570 exitAirSensor->alphaS =
571 loadVariant<double>(entry.second, "AlphaS");
572 exitAirSensor->alphaF =
573 loadVariant<double>(entry.second, "AlphaF");
James Feistbc896df2018-11-26 16:28:17 -0800574 }
575 else if (entry.first == cfmIface)
576
577 {
James Feistb2eb3f52018-12-04 16:17:50 -0800578 // thresholds should be under the same path
579 std::vector<thresholds::Threshold> sensorThresholds;
580 parseThresholdsFromConfig(pathPair.second,
581 sensorThresholds);
582 std::string name =
583 loadVariant<std::string>(entry.second, "Name");
584 auto sensor = std::make_unique<CFMSensor>(
585 dbusConnection, name, pathPair.first.str,
586 objectServer, std::move(sensorThresholds),
587 exitAirSensor);
588 loadVariantPathArray(entry.second, "Tachs",
589 sensor->tachs);
590 sensor->maxCFM =
591 loadVariant<double>(entry.second, "MaxCFM");
James Feistbc896df2018-11-26 16:28:17 -0800592
593 // change these into percent upon getting the data
James Feistb2eb3f52018-12-04 16:17:50 -0800594 sensor->c1 =
595 loadVariant<double>(entry.second, "C1") / 100;
596 sensor->c2 =
597 loadVariant<double>(entry.second, "C2") / 100;
598 sensor->tachMinPercent =
599 loadVariant<double>(entry.second,
600 "TachMinPercent") /
James Feistbc896df2018-11-26 16:28:17 -0800601 100;
James Feistb2eb3f52018-12-04 16:17:50 -0800602 sensor->tachMaxPercent =
603 loadVariant<double>(entry.second,
604 "TachMaxPercent") /
James Feistbc896df2018-11-26 16:28:17 -0800605 100;
606
James Feistb2eb3f52018-12-04 16:17:50 -0800607 cfmSensors.emplace_back(std::move(sensor));
James Feistbc896df2018-11-26 16:28:17 -0800608 }
609 }
610 }
James Feistb2eb3f52018-12-04 16:17:50 -0800611 if (exitAirSensor)
James Feistbc896df2018-11-26 16:28:17 -0800612 {
James Feistb2eb3f52018-12-04 16:17:50 -0800613 exitAirSensor->cfmSensors = std::move(cfmSensors);
James Feistbc896df2018-11-26 16:28:17 -0800614
James Feistb2eb3f52018-12-04 16:17:50 -0800615 // todo: when power sensors are done delete this fake
616 // reading
617 exitAirSensor->powerReadings["foo"] = 144.0;
James Feistbc896df2018-11-26 16:28:17 -0800618
James Feistb2eb3f52018-12-04 16:17:50 -0800619 exitAirSensor->updateReading();
James Feistbc896df2018-11-26 16:28:17 -0800620 }
621 },
622 entityManagerName, "/", "org.freedesktop.DBus.ObjectManager",
623 "GetManagedObjects");
624}
625
626int main(int argc, char** argv)
627{
628
629 boost::asio::io_service io;
630 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
631 systemBus->request_name("xyz.openbmc_project.ExitAirTempSensor");
632 sdbusplus::asio::object_server objectServer(systemBus);
633 std::shared_ptr<ExitAirTempSensor> sensor =
634 nullptr; // wait until we find the config
635 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
636
637 io.post([&]() { createSensor(objectServer, sensor, systemBus); });
638
639 boost::asio::deadline_timer configTimer(io);
640
641 std::function<void(sdbusplus::message::message&)> eventHandler =
642 [&](sdbusplus::message::message& message) {
643 configTimer.expires_from_now(boost::posix_time::seconds(1));
644 // create a timer because normally multiple properties change
645 configTimer.async_wait([&](const boost::system::error_code& ec) {
646 if (ec == boost::asio::error::operation_aborted)
647 {
648 return; // we're being canceled
649 }
650 createSensor(objectServer, sensor, systemBus);
651 if (!sensor)
652 {
653 std::cout << "Configuration not detected\n";
654 }
655 });
656 };
657 constexpr const std::array<const char*, 2> monitorIfaces = {exitAirIface,
658 cfmIface};
659 for (const char* type : monitorIfaces)
660 {
661 auto match = std::make_unique<sdbusplus::bus::match::match>(
662 static_cast<sdbusplus::bus::bus&>(*systemBus),
663 "type='signal',member='PropertiesChanged',path_namespace='" +
664 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
665 eventHandler);
666 matches.emplace_back(std::move(match));
667 }
668
669 io.run();
670}