blob: a8a57483fee82a9b1779d19f8262dfe810e783e4 [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;
56 boost::container::flat_map<
57 std::string, sdbusplus::message::variant<double, int64_t>>
58 values;
59 message.read(objectName, values);
60 auto findValue = values.find("Value");
61 if (findValue == values.end())
62 {
63 return;
64 }
65 double value = sdbusplus::message::variant_ns::visit(
66 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
331 inletTemp = sdbusplus::message::variant_ns::visit(
332 VariantToDoubleVisitor(), value);
333 },
334 "xyz.openbmc_project.HwmonTempSensor",
335 std::string("/xyz/openbmc_project/sensors/") + inletTemperatureSensor,
336 "org.freedesktop.DBus.Properties", "Get",
337 "xyz.openbmc_project.Sensor.Value", "Value");
James Feistbc896df2018-11-26 16:28:17 -0800338}
339
340void ExitAirTempSensor::updateReading(void)
341{
342
343 double val = 0.0;
344 if (calculate(val))
345 {
346 updateValue(val);
347 }
348 else
349 {
350 updateValue(std::numeric_limits<double>::quiet_NaN());
351 }
352}
353
James Feistb2eb3f52018-12-04 16:17:50 -0800354double ExitAirTempSensor::getTotalCFM(void)
James Feistbc896df2018-11-26 16:28:17 -0800355{
James Feistb2eb3f52018-12-04 16:17:50 -0800356 double sum = 0;
357 for (auto& sensor : cfmSensors)
James Feistbc896df2018-11-26 16:28:17 -0800358 {
James Feistb2eb3f52018-12-04 16:17:50 -0800359 double reading = 0;
360 if (!sensor->calculate(reading))
James Feistbc896df2018-11-26 16:28:17 -0800361 {
James Feistbc896df2018-11-26 16:28:17 -0800362 return -1;
363 }
James Feistb2eb3f52018-12-04 16:17:50 -0800364 sum += reading;
James Feistbc896df2018-11-26 16:28:17 -0800365 }
James Feistb2eb3f52018-12-04 16:17:50 -0800366
367 return sum;
James Feistbc896df2018-11-26 16:28:17 -0800368}
369
370bool ExitAirTempSensor::calculate(double& val)
371{
372 static bool firstRead = false;
373 double cfm = getTotalCFM();
374 if (cfm <= 0)
375 {
376 std::cerr << "Error getting cfm\n";
377 return false;
378 }
379
380 // if there is an error getting inlet temp, return error
381 if (std::isnan(inletTemp))
382 {
383 std::cerr << "Cannot get inlet temp\n";
384 val = 0;
385 return false;
386 }
387
388 // if fans are off, just make the exit temp equal to inlet
James Feist71d31b22019-01-02 16:57:54 -0800389 if (!isPowerOn())
James Feistbc896df2018-11-26 16:28:17 -0800390 {
391 val = inletTemp;
392 return true;
393 }
394
395 double totalPower = 0;
396 for (const auto& reading : powerReadings)
397 {
398 if (std::isnan(reading.second))
399 {
400 continue;
401 }
402 totalPower += reading.second;
403 }
404
405 // Calculate power correction factor
406 // Ci = CL + (CH - CL)/(QMax - QMin) * (CFM - QMin)
407 float powerFactor = 0.0;
408 if (cfm <= qMin)
409 {
410 powerFactor = powerFactorMin;
411 }
412 else if (cfm >= qMax)
413 {
414 powerFactor = powerFactorMax;
415 }
416 else
417 {
418 powerFactor = powerFactorMin + ((powerFactorMax - powerFactorMin) /
419 (qMax - qMin) * (cfm - qMin));
420 }
421
422 totalPower *= powerFactor;
423 totalPower += pOffset;
424
425 if (totalPower == 0)
426 {
427 std::cerr << "total power 0\n";
428 val = 0;
429 return false;
430 }
431
432 if constexpr (DEBUG)
433 {
434 std::cout << "Power Factor " << powerFactor << "\n";
435 std::cout << "Inlet Temp " << inletTemp << "\n";
436 std::cout << "Total Power" << totalPower << "\n";
437 }
438
439 // Calculate the exit air temp
440 // Texit = Tfp + (1.76 * TotalPower / CFM * Faltitude)
441 double reading = 1.76 * totalPower * altitudeFactor;
442 reading /= cfm;
443 reading += inletTemp;
444
445 if constexpr (DEBUG)
446 {
447 std::cout << "Reading 1: " << reading << "\n";
448 }
449
450 // Now perform the exponential average
451 // Calculate alpha based on SDR values and CFM
452 // Ai = As + (Af - As)/(QMax - QMin) * (CFM - QMin)
453
454 double alpha = 0.0;
455 if (cfm < qMin)
456 {
457 alpha = alphaS;
458 }
459 else if (cfm >= qMax)
460 {
461 alpha = alphaF;
462 }
463 else
464 {
465 alpha = alphaS + ((alphaF - alphaS) * (cfm - qMin) / (qMax - qMin));
466 }
467
468 auto time = std::chrono::system_clock::now();
469 if (!firstRead)
470 {
471 firstRead = true;
472 lastTime = time;
473 lastReading = reading;
474 }
475 double alphaDT =
476 std::chrono::duration_cast<std::chrono::seconds>(time - lastTime)
477 .count() *
478 alpha;
479
480 // cap at 1.0 or the below fails
481 if (alphaDT > 1.0)
482 {
483 alphaDT = 1.0;
484 }
485
486 if constexpr (DEBUG)
487 {
488 std::cout << "AlphaDT: " << alphaDT << "\n";
489 }
490
491 reading = ((reading * alphaDT) + (lastReading * (1.0 - alphaDT)));
492
493 if constexpr (DEBUG)
494 {
495 std::cout << "Reading 2: " << reading << "\n";
496 }
497
498 val = reading;
499 lastReading = reading;
500 lastTime = time;
501 return true;
502}
503
504void ExitAirTempSensor::checkThresholds(void)
505{
506 thresholds::checkThresholds(this);
507}
508
James Feistbc896df2018-11-26 16:28:17 -0800509static void loadVariantPathArray(
510 const boost::container::flat_map<std::string, BasicVariantType>& data,
511 const std::string& key, std::vector<std::string>& resp)
512{
513 auto it = data.find(key);
514 if (it == data.end())
515 {
516 std::cerr << "Configuration missing " << key << "\n";
517 throw std::invalid_argument("Key Missing");
518 }
519 BasicVariantType copy = it->second;
520 std::vector<std::string> config =
521 sdbusplus::message::variant_ns::get<std::vector<std::string>>(copy);
522 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 Feistb2eb3f52018-12-04 16:17:50 -0800556 if (!exitAirSensor)
James Feistbc896df2018-11-26 16:28:17 -0800557 {
James Feistb2eb3f52018-12-04 16:17:50 -0800558 std::string name =
559 loadVariant<std::string>(entry.second, "Name");
560 exitAirSensor = std::make_shared<ExitAirTempSensor>(
561 dbusConnection, name, pathPair.first.str,
James Feistbc896df2018-11-26 16:28:17 -0800562 objectServer, std::move(sensorThresholds));
563 }
564 else
565 {
James Feistb2eb3f52018-12-04 16:17:50 -0800566 exitAirSensor->thresholds = sensorThresholds;
James Feistbc896df2018-11-26 16:28:17 -0800567 }
568
James Feistb2eb3f52018-12-04 16:17:50 -0800569 exitAirSensor->powerFactorMin =
570 loadVariant<double>(entry.second, "PowerFactorMin");
571 exitAirSensor->powerFactorMax =
572 loadVariant<double>(entry.second, "PowerFactorMax");
573 exitAirSensor->qMin =
574 loadVariant<double>(entry.second, "QMin");
575 exitAirSensor->qMax =
576 loadVariant<double>(entry.second, "QMax");
577 exitAirSensor->alphaS =
578 loadVariant<double>(entry.second, "AlphaS");
579 exitAirSensor->alphaF =
580 loadVariant<double>(entry.second, "AlphaF");
James Feistbc896df2018-11-26 16:28:17 -0800581 }
582 else if (entry.first == cfmIface)
583
584 {
James Feistb2eb3f52018-12-04 16:17:50 -0800585 // thresholds should be under the same path
586 std::vector<thresholds::Threshold> sensorThresholds;
587 parseThresholdsFromConfig(pathPair.second,
588 sensorThresholds);
589 std::string name =
590 loadVariant<std::string>(entry.second, "Name");
591 auto sensor = std::make_unique<CFMSensor>(
592 dbusConnection, name, pathPair.first.str,
593 objectServer, std::move(sensorThresholds),
594 exitAirSensor);
595 loadVariantPathArray(entry.second, "Tachs",
596 sensor->tachs);
597 sensor->maxCFM =
598 loadVariant<double>(entry.second, "MaxCFM");
James Feistbc896df2018-11-26 16:28:17 -0800599
600 // change these into percent upon getting the data
James Feistb2eb3f52018-12-04 16:17:50 -0800601 sensor->c1 =
602 loadVariant<double>(entry.second, "C1") / 100;
603 sensor->c2 =
604 loadVariant<double>(entry.second, "C2") / 100;
605 sensor->tachMinPercent =
606 loadVariant<double>(entry.second,
607 "TachMinPercent") /
James Feistbc896df2018-11-26 16:28:17 -0800608 100;
James Feistb2eb3f52018-12-04 16:17:50 -0800609 sensor->tachMaxPercent =
610 loadVariant<double>(entry.second,
611 "TachMaxPercent") /
James Feistbc896df2018-11-26 16:28:17 -0800612 100;
613
James Feistb2eb3f52018-12-04 16:17:50 -0800614 cfmSensors.emplace_back(std::move(sensor));
James Feistbc896df2018-11-26 16:28:17 -0800615 }
616 }
617 }
James Feistb2eb3f52018-12-04 16:17:50 -0800618 if (exitAirSensor)
James Feistbc896df2018-11-26 16:28:17 -0800619 {
James Feistb2eb3f52018-12-04 16:17:50 -0800620 exitAirSensor->cfmSensors = std::move(cfmSensors);
James Feistbc896df2018-11-26 16:28:17 -0800621
James Feistb2eb3f52018-12-04 16:17:50 -0800622 // todo: when power sensors are done delete this fake
623 // reading
624 exitAirSensor->powerReadings["foo"] = 144.0;
James Feistbc896df2018-11-26 16:28:17 -0800625
James Feistb2eb3f52018-12-04 16:17:50 -0800626 exitAirSensor->updateReading();
James Feistbc896df2018-11-26 16:28:17 -0800627 }
628 },
629 entityManagerName, "/", "org.freedesktop.DBus.ObjectManager",
630 "GetManagedObjects");
631}
632
633int main(int argc, char** argv)
634{
635
636 boost::asio::io_service io;
637 auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
638 systemBus->request_name("xyz.openbmc_project.ExitAirTempSensor");
639 sdbusplus::asio::object_server objectServer(systemBus);
640 std::shared_ptr<ExitAirTempSensor> sensor =
641 nullptr; // wait until we find the config
642 std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;
643
644 io.post([&]() { createSensor(objectServer, sensor, systemBus); });
645
646 boost::asio::deadline_timer configTimer(io);
647
648 std::function<void(sdbusplus::message::message&)> eventHandler =
649 [&](sdbusplus::message::message& message) {
650 configTimer.expires_from_now(boost::posix_time::seconds(1));
651 // create a timer because normally multiple properties change
652 configTimer.async_wait([&](const boost::system::error_code& ec) {
653 if (ec == boost::asio::error::operation_aborted)
654 {
655 return; // we're being canceled
656 }
657 createSensor(objectServer, sensor, systemBus);
658 if (!sensor)
659 {
660 std::cout << "Configuration not detected\n";
661 }
662 });
663 };
664 constexpr const std::array<const char*, 2> monitorIfaces = {exitAirIface,
665 cfmIface};
666 for (const char* type : monitorIfaces)
667 {
668 auto match = std::make_unique<sdbusplus::bus::match::match>(
669 static_cast<sdbusplus::bus::bus&>(*systemBus),
670 "type='signal',member='PropertiesChanged',path_namespace='" +
671 std::string(inventoryPath) + "',arg0namespace='" + type + "'",
672 eventHandler);
673 matches.emplace_back(std::move(match));
674 }
675
676 io.run();
677}