blob: 9f20c70e18d982bd437762729367cdf2c802a632 [file] [log] [blame]
James Feistbc896df2018-11-26 16:28:17 -08001#pragma once
Ed Tanous18b61862025-01-30 10:56:28 -08002#include "Thresholds.hpp"
3
James Feistbc896df2018-11-26 16:28:17 -08004#include <boost/container/flat_map.hpp>
Ed Tanous18b61862025-01-30 10:56:28 -08005#include <sdbusplus/asio/connection.hpp>
6#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -07007#include <sdbusplus/bus/match.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07008#include <sensor.hpp>
James Feist38fb5982020-05-28 10:09:54 -07009
James Feistbc896df2018-11-26 16:28:17 -080010#include <chrono>
Ed Tanous18b61862025-01-30 10:56:28 -080011#include <cstdint>
James Feistbc896df2018-11-26 16:28:17 -080012#include <limits>
Patrick Venturefd6ba732019-10-31 14:27:39 -070013#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070014#include <string>
Ed Tanous18b61862025-01-30 10:56:28 -080015#include <utility>
James Feistbc896df2018-11-26 16:28:17 -080016#include <vector>
17
James Feistb2eb3f52018-12-04 16:17:50 -080018struct ExitAirTempSensor;
James Feist9a25ed42019-10-15 15:43:44 -070019struct CFMSensor : public Sensor, std::enable_shared_from_this<CFMSensor>
James Feistbc896df2018-11-26 16:28:17 -080020{
James Feistb2eb3f52018-12-04 16:17:50 -080021 std::vector<std::string> tachs;
Ed Tanousa771f6a2022-01-14 09:36:51 -080022 double c1 = 0.0;
23 double c2 = 0.0;
24 double maxCFM = 0.0;
25 double tachMinPercent = 0.0;
26 double tachMaxPercent = 0.0;
James Feistb2eb3f52018-12-04 16:17:50 -080027
28 std::shared_ptr<ExitAirTempSensor> parent;
29
James Feistd8705872019-02-08 13:26:09 -080030 CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
31 const std::string& name, const std::string& sensorConfiguration,
32 sdbusplus::asio::object_server& objectServer,
Ed Tanous2049bd22022-07-09 07:20:26 -070033 std::vector<thresholds::Threshold>&& thresholdData,
James Feistd8705872019-02-08 13:26:09 -080034 std::shared_ptr<ExitAirTempSensor>& parent);
Ed Tanous8a57ec02020-10-09 12:46:52 -070035 ~CFMSensor() override;
James Feistb2eb3f52018-12-04 16:17:50 -080036
Ed Tanous2049bd22022-07-09 07:20:26 -070037 bool calculate(double& /*value*/);
Ed Tanous201a1012024-04-03 18:07:28 -070038 void updateReading();
39 void setupMatches();
40 void createMaxCFMIface();
James Feist9a25ed42019-10-15 15:43:44 -070041 void addTachRanges(const std::string& serviceName, const std::string& path);
Ed Tanous201a1012024-04-03 18:07:28 -070042 void checkThresholds() override;
Ed Tanous2049bd22022-07-09 07:20:26 -070043 uint64_t getMaxRpm(uint64_t cfmMax) const;
James Feistb2eb3f52018-12-04 16:17:50 -080044
45 private:
Patrick Williams92f8f512022-07-22 19:26:55 -050046 std::vector<sdbusplus::bus::match_t> matches;
James Feistb2eb3f52018-12-04 16:17:50 -080047 boost::container::flat_map<std::string, double> tachReadings;
48 boost::container::flat_map<std::string, std::pair<double, double>>
49 tachRanges;
James Feist13452092019-03-07 16:38:12 -080050 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface;
51 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface;
James Feistd8705872019-02-08 13:26:09 -080052 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080053};
54
James Feist38fb5982020-05-28 10:09:54 -070055struct ExitAirTempSensor :
56 public Sensor,
57 std::enable_shared_from_this<ExitAirTempSensor>
James Feistbc896df2018-11-26 16:28:17 -080058{
Ed Tanousa771f6a2022-01-14 09:36:51 -080059 double powerFactorMin = 0.0;
60 double powerFactorMax = 0.0;
61 double qMin = 0.0;
62 double qMax = 0.0;
63 double alphaS = 0.0;
64 double alphaF = 0.0;
65 double pOffset = 0.0;
James Feistbc896df2018-11-26 16:28:17 -080066
James Feistd8705872019-02-08 13:26:09 -080067 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
68 const std::string& name,
69 const std::string& sensorConfiguration,
70 sdbusplus::asio::object_server& objectServer,
Ed Tanous2049bd22022-07-09 07:20:26 -070071 std::vector<thresholds::Threshold>&& thresholdData);
Ed Tanous8a57ec02020-10-09 12:46:52 -070072 ~ExitAirTempSensor() override;
James Feistbc896df2018-11-26 16:28:17 -080073
Ed Tanous201a1012024-04-03 18:07:28 -070074 void checkThresholds() override;
75 void updateReading();
76 void setupMatches();
James Feistbc896df2018-11-26 16:28:17 -080077
78 private:
Ed Tanousa771f6a2022-01-14 09:36:51 -080079 double lastReading = 0.0;
James Feistbc896df2018-11-26 16:28:17 -080080
Patrick Williams92f8f512022-07-22 19:26:55 -050081 std::vector<sdbusplus::bus::match_t> matches;
James Feistb2eb3f52018-12-04 16:17:50 -080082 double inletTemp = std::numeric_limits<double>::quiet_NaN();
Zhikui Ren12e3d672020-12-03 15:14:49 -080083 boost::container::flat_map<std::string, double> powerReadings;
James Feistb2eb3f52018-12-04 16:17:50 -080084
James Feist523828e2019-03-04 14:38:37 -080085 sdbusplus::asio::object_server& objServer;
Zhikui Ren12e3d672020-12-03 15:14:49 -080086 std::chrono::time_point<std::chrono::steady_clock> lastTime;
Ed Tanous201a1012024-04-03 18:07:28 -070087 static double getTotalCFM();
James Feistd8705872019-02-08 13:26:09 -080088 bool calculate(double& val);
James Feist9566bfa2019-01-29 15:31:23 -080089};