blob: 06eddc02a3b4123859999268b83c631d086cb9c5 [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 {
206 std::cerr << "Can't find " << tachName << "in ranges\n";
207 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 Feistbc896df2018-11-26 16:28:17 -0800272 dbusConnection(conn)
273{
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{
297 // this sensor currently isn't destroyed so we don't care
298}
299
300void ExitAirTempSensor::setupMatches(void)
301{
302
James Feistb2eb3f52018-12-04 16:17:50 -0800303 constexpr const std::array<const char*, 2> matchTypes = {
304 "power", inletTemperatureSensor};
James Feistbc896df2018-11-26 16:28:17 -0800305
James Feistb2eb3f52018-12-04 16:17:50 -0800306 for (const std::string& type : matchTypes)
James Feistbc896df2018-11-26 16:28:17 -0800307 {
James Feistb2eb3f52018-12-04 16:17:50 -0800308 setupSensorMatch(matches, *dbusConnection, type,
309 [this, type](const double& value,
310 sdbusplus::message::message& message) {
311 if (type == "power")
312 {
313 powerReadings[message.get_path()] = value;
314 }
315 else if (type == inletTemperatureSensor)
316 {
317 inletTemp = value;
318 }
319 updateReading();
320 });
James Feistbc896df2018-11-26 16:28:17 -0800321 }
James Feist9566bfa2019-01-29 15:31:23 -0800322 dbusConnection->async_method_call(
323 [this](boost::system::error_code ec,
324 const std::variant<double>& value) {
325 if (ec)
326 {
327 // sensor not ready yet
328 return;
329 }
330
James Feist3eb82622019-02-08 13:10:22 -0800331 inletTemp = std::visit(VariantToDoubleVisitor(), value);
James Feist9566bfa2019-01-29 15:31:23 -0800332 },
333 "xyz.openbmc_project.HwmonTempSensor",
334 std::string("/xyz/openbmc_project/sensors/") + inletTemperatureSensor,
335 "org.freedesktop.DBus.Properties", "Get",
336 "xyz.openbmc_project.Sensor.Value", "Value");
James Feistbc896df2018-11-26 16:28:17 -0800337}
338
339void ExitAirTempSensor::updateReading(void)
340{
341
342 double val = 0.0;
343 if (calculate(val))
344 {
345 updateValue(val);
346 }
347 else
348 {
349 updateValue(std::numeric_limits<double>::quiet_NaN());
350 }
351}
352
James Feistb2eb3f52018-12-04 16:17:50 -0800353double ExitAirTempSensor::getTotalCFM(void)
James Feistbc896df2018-11-26 16:28:17 -0800354{
James Feistb2eb3f52018-12-04 16:17:50 -0800355 double sum = 0;
356 for (auto& sensor : cfmSensors)
James Feistbc896df2018-11-26 16:28:17 -0800357 {
James Feistb2eb3f52018-12-04 16:17:50 -0800358 double reading = 0;
359 if (!sensor->calculate(reading))
James Feistbc896df2018-11-26 16:28:17 -0800360 {
James Feistbc896df2018-11-26 16:28:17 -0800361 return -1;
362 }
James Feistb2eb3f52018-12-04 16:17:50 -0800363 sum += reading;
James Feistbc896df2018-11-26 16:28:17 -0800364 }
James Feistb2eb3f52018-12-04 16:17:50 -0800365
366 return sum;
James Feistbc896df2018-11-26 16:28:17 -0800367}
368
369bool ExitAirTempSensor::calculate(double& val)
370{
371 static bool firstRead = false;
372 double cfm = getTotalCFM();
373 if (cfm <= 0)
374 {
375 std::cerr << "Error getting cfm\n";
376 return false;
377 }
378
379 // if there is an error getting inlet temp, return error
380 if (std::isnan(inletTemp))
381 {
382 std::cerr << "Cannot get inlet temp\n";
383 val = 0;
384 return false;
385 }
386
387 // if fans are off, just make the exit temp equal to inlet
James Feist71d31b22019-01-02 16:57:54 -0800388 if (!isPowerOn())
James Feistbc896df2018-11-26 16:28:17 -0800389 {
390 val = inletTemp;
391 return true;
392 }
393
394 double totalPower = 0;
395 for (const auto& reading : powerReadings)
396 {
397 if (std::isnan(reading.second))
398 {
399 continue;
400 }
401 totalPower += reading.second;
402 }
403
404 // Calculate power correction factor
405 // Ci = CL + (CH - CL)/(QMax - QMin) * (CFM - QMin)
406 float powerFactor = 0.0;
407 if (cfm <= qMin)
408 {
409 powerFactor = powerFactorMin;
410 }
411 else if (cfm >= qMax)
412 {
413 powerFactor = powerFactorMax;
414 }
415 else
416 {
417 powerFactor = powerFactorMin + ((powerFactorMax - powerFactorMin) /
418 (qMax - qMin) * (cfm - qMin));
419 }
420
421 totalPower *= powerFactor;
422 totalPower += pOffset;
423
424 if (totalPower == 0)
425 {
426 std::cerr << "total power 0\n";
427 val = 0;
428 return false;
429 }
430
431 if constexpr (DEBUG)
432 {
433 std::cout << "Power Factor " << powerFactor << "\n";
434 std::cout << "Inlet Temp " << inletTemp << "\n";
435 std::cout << "Total Power" << totalPower << "\n";
436 }
437
438 // Calculate the exit air temp
439 // Texit = Tfp + (1.76 * TotalPower / CFM * Faltitude)
440 double reading = 1.76 * totalPower * altitudeFactor;
441 reading /= cfm;
442 reading += inletTemp;
443
444 if constexpr (DEBUG)
445 {
446 std::cout << "Reading 1: " << reading << "\n";
447 }
448
449 // Now perform the exponential average
450 // Calculate alpha based on SDR values and CFM
451 // Ai = As + (Af - As)/(QMax - QMin) * (CFM - QMin)
452
453 double alpha = 0.0;
454 if (cfm < qMin)
455 {
456 alpha = alphaS;
457 }
458 else if (cfm >= qMax)
459 {
460 alpha = alphaF;
461 }
462 else
463 {
464 alpha = alphaS + ((alphaF - alphaS) * (cfm - qMin) / (qMax - qMin));
465 }
466
467 auto time = std::chrono::system_clock::now();
468 if (!firstRead)
469 {
470 firstRead = true;
471 lastTime = time;
472 lastReading = reading;
473 }
474 double alphaDT =
475 std::chrono::duration_cast<std::chrono::seconds>(time - lastTime)
476 .count() *
477 alpha;
478
479 // cap at 1.0 or the below fails
480 if (alphaDT > 1.0)
481 {
482 alphaDT = 1.0;
483 }
484
485 if constexpr (DEBUG)
486 {
487 std::cout << "AlphaDT: " << alphaDT << "\n";
488 }
489
490 reading = ((reading * alphaDT) + (lastReading * (1.0 - alphaDT)));
491
492 if constexpr (DEBUG)
493 {
494 std::cout << "Reading 2: " << reading << "\n";
495 }
496
497 val = reading;
498 lastReading = reading;
499 lastTime = time;
500 return true;
501}
502
503void ExitAirTempSensor::checkThresholds(void)
504{
505 thresholds::checkThresholds(this);
506}
507
James Feistbc896df2018-11-26 16:28:17 -0800508static void loadVariantPathArray(
509 const boost::container::flat_map<std::string, BasicVariantType>& data,
510 const std::string& key, std::vector<std::string>& resp)
511{
512 auto it = data.find(key);
513 if (it == data.end())
514 {
515 std::cerr << "Configuration missing " << key << "\n";
516 throw std::invalid_argument("Key Missing");
517 }
518 BasicVariantType copy = it->second;
James Feist3eb82622019-02-08 13:10:22 -0800519 std::vector<std::string> config = std::get<std::vector<std::string>>(copy);
James Feistbc896df2018-11-26 16:28:17 -0800520 for (auto& str : config)
521 {
522 boost::replace_all(str, " ", "_");
523 }
524 resp = std::move(config);
525}
526
527void createSensor(sdbusplus::asio::object_server& objectServer,
James Feistb2eb3f52018-12-04 16:17:50 -0800528 std::shared_ptr<ExitAirTempSensor>& exitAirSensor,
James Feistbc896df2018-11-26 16:28:17 -0800529 std::shared_ptr<sdbusplus::asio::connection>& dbusConnection)
530{
531 if (!dbusConnection)
532 {
533 std::cerr << "Connection not created\n";
534 return;
535 }
536 dbusConnection->async_method_call(
537 [&](boost::system::error_code ec, const ManagedObjectType& resp) {
538 if (ec)
539 {
540 std::cerr << "Error contacting entity manager\n";
541 return;
542 }
James Feistb2eb3f52018-12-04 16:17:50 -0800543 std::vector<std::unique_ptr<CFMSensor>> cfmSensors;
James Feistbc896df2018-11-26 16:28:17 -0800544 for (const auto& pathPair : resp)
545 {
546 for (const auto& entry : pathPair.second)
547 {
548 if (entry.first == exitAirIface)
549 {
James Feistbc896df2018-11-26 16:28:17 -0800550 // thresholds should be under the same path
551 std::vector<thresholds::Threshold> sensorThresholds;
552 parseThresholdsFromConfig(pathPair.second,
553 sensorThresholds);
James Feistb2eb3f52018-12-04 16:17:50 -0800554 if (!exitAirSensor)
James Feistbc896df2018-11-26 16:28:17 -0800555 {
James Feistb2eb3f52018-12-04 16:17:50 -0800556 std::string name =
557 loadVariant<std::string>(entry.second, "Name");
558 exitAirSensor = std::make_shared<ExitAirTempSensor>(
559 dbusConnection, name, pathPair.first.str,
James Feistbc896df2018-11-26 16:28:17 -0800560 objectServer, std::move(sensorThresholds));
561 }
562 else
563 {
James Feistb2eb3f52018-12-04 16:17:50 -0800564 exitAirSensor->thresholds = sensorThresholds;
James Feistbc896df2018-11-26 16:28:17 -0800565 }
566
James Feistb2eb3f52018-12-04 16:17:50 -0800567 exitAirSensor->powerFactorMin =
568 loadVariant<double>(entry.second, "PowerFactorMin");
569 exitAirSensor->powerFactorMax =
570 loadVariant<double>(entry.second, "PowerFactorMax");
571 exitAirSensor->qMin =
572 loadVariant<double>(entry.second, "QMin");
573 exitAirSensor->qMax =
574 loadVariant<double>(entry.second, "QMax");
575 exitAirSensor->alphaS =
576 loadVariant<double>(entry.second, "AlphaS");
577 exitAirSensor->alphaF =
578 loadVariant<double>(entry.second, "AlphaF");
James Feistbc896df2018-11-26 16:28:17 -0800579 }
580 else if (entry.first == cfmIface)
581
582 {
James Feistb2eb3f52018-12-04 16:17:50 -0800583 // thresholds should be under the same path
584 std::vector<thresholds::Threshold> sensorThresholds;
585 parseThresholdsFromConfig(pathPair.second,
586 sensorThresholds);
587 std::string name =
588 loadVariant<std::string>(entry.second, "Name");
589 auto sensor = std::make_unique<CFMSensor>(
590 dbusConnection, name, pathPair.first.str,
591 objectServer, std::move(sensorThresholds),
592 exitAirSensor);
593 loadVariantPathArray(entry.second, "Tachs",
594 sensor->tachs);
595 sensor->maxCFM =
596 loadVariant<double>(entry.second, "MaxCFM");
James Feistbc896df2018-11-26 16:28:17 -0800597
598 // change these into percent upon getting the data
James Feistb2eb3f52018-12-04 16:17:50 -0800599 sensor->c1 =
600 loadVariant<double>(entry.second, "C1") / 100;
601 sensor->c2 =
602 loadVariant<double>(entry.second, "C2") / 100;
603 sensor->tachMinPercent =
604 loadVariant<double>(entry.second,
605 "TachMinPercent") /
James Feistbc896df2018-11-26 16:28:17 -0800606 100;
James Feistb2eb3f52018-12-04 16:17:50 -0800607 sensor->tachMaxPercent =
608 loadVariant<double>(entry.second,
609 "TachMaxPercent") /
James Feistbc896df2018-11-26 16:28:17 -0800610 100;
611
James Feistb2eb3f52018-12-04 16:17:50 -0800612 cfmSensors.emplace_back(std::move(sensor));
James Feistbc896df2018-11-26 16:28:17 -0800613 }
614 }
615 }
James Feistb2eb3f52018-12-04 16:17:50 -0800616 if (exitAirSensor)
James Feistbc896df2018-11-26 16:28:17 -0800617 {
James Feistb2eb3f52018-12-04 16:17:50 -0800618 exitAirSensor->cfmSensors = std::move(cfmSensors);
James Feistbc896df2018-11-26 16:28:17 -0800619
James Feistb2eb3f52018-12-04 16:17:50 -0800620 // todo: when power sensors are done delete this fake
621 // reading
622 exitAirSensor->powerReadings["foo"] = 144.0;
James Feistbc896df2018-11-26 16:28:17 -0800623
James Feistb2eb3f52018-12-04 16:17:50 -0800624 exitAirSensor->updateReading();
James Feistbc896df2018-11-26 16:28:17 -0800625 }
626 },
627 entityManagerName, "/", "org.freedesktop.DBus.ObjectManager",
628 "GetManagedObjects");
629}
630
631int main(int argc, char** argv)
632{
633
634 boost::asio::io_service io;
635 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
636 systemBus->request_name("xyz.openbmc_project.ExitAirTempSensor");
637 sdbusplus::asio::object_server objectServer(systemBus);
638 std::shared_ptr<ExitAirTempSensor> sensor =
639 nullptr; // wait until we find the config
640 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
641
642 io.post([&]() { createSensor(objectServer, sensor, systemBus); });
643
644 boost::asio::deadline_timer configTimer(io);
645
646 std::function<void(sdbusplus::message::message&)> eventHandler =
647 [&](sdbusplus::message::message& message) {
648 configTimer.expires_from_now(boost::posix_time::seconds(1));
649 // create a timer because normally multiple properties change
650 configTimer.async_wait([&](const boost::system::error_code& ec) {
651 if (ec == boost::asio::error::operation_aborted)
652 {
653 return; // we're being canceled
654 }
655 createSensor(objectServer, sensor, systemBus);
656 if (!sensor)
657 {
658 std::cout << "Configuration not detected\n";
659 }
660 });
661 };
662 constexpr const std::array<const char*, 2> monitorIfaces = {exitAirIface,
663 cfmIface};
664 for (const char* type : monitorIfaces)
665 {
666 auto match = std::make_unique<sdbusplus::bus::match::match>(
667 static_cast<sdbusplus::bus::bus&>(*systemBus),
668 "type='signal',member='PropertiesChanged',path_namespace='" +
669 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
670 eventHandler);
671 matches.emplace_back(std::move(match));
672 }
673
674 io.run();
675}