blob: bea8fbad8e071bd9538dadfd5fccff932e017bdb [file] [log] [blame]
James Feistbc896df2018-11-26 16:28:17 -08001#pragma once
James Feistbc896df2018-11-26 16:28:17 -08002#include <boost/container/flat_map.hpp>
James Feist38fb5982020-05-28 10:09:54 -07003#include <sdbusplus/bus/match.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07004#include <sensor.hpp>
James Feist38fb5982020-05-28 10:09:54 -07005
James Feistbc896df2018-11-26 16:28:17 -08006#include <chrono>
7#include <limits>
Patrick Venturefd6ba732019-10-31 14:27:39 -07008#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -07009#include <string>
James Feistbc896df2018-11-26 16:28:17 -080010#include <vector>
11
James Feistb2eb3f52018-12-04 16:17:50 -080012struct ExitAirTempSensor;
James Feist9a25ed42019-10-15 15:43:44 -070013struct CFMSensor : public Sensor, std::enable_shared_from_this<CFMSensor>
James Feistbc896df2018-11-26 16:28:17 -080014{
James Feistb2eb3f52018-12-04 16:17:50 -080015 std::vector<std::string> tachs;
Ed Tanousa771f6a2022-01-14 09:36:51 -080016 double c1 = 0.0;
17 double c2 = 0.0;
18 double maxCFM = 0.0;
19 double tachMinPercent = 0.0;
20 double tachMaxPercent = 0.0;
James Feistb2eb3f52018-12-04 16:17:50 -080021
22 std::shared_ptr<ExitAirTempSensor> parent;
23
James Feistd8705872019-02-08 13:26:09 -080024 CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
25 const std::string& name, const std::string& sensorConfiguration,
26 sdbusplus::asio::object_server& objectServer,
Ed Tanous2049bd22022-07-09 07:20:26 -070027 std::vector<thresholds::Threshold>&& thresholdData,
James Feistd8705872019-02-08 13:26:09 -080028 std::shared_ptr<ExitAirTempSensor>& parent);
Ed Tanous8a57ec02020-10-09 12:46:52 -070029 ~CFMSensor() override;
James Feistb2eb3f52018-12-04 16:17:50 -080030
Ed Tanous2049bd22022-07-09 07:20:26 -070031 bool calculate(double& /*value*/);
James Feistb2eb3f52018-12-04 16:17:50 -080032 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070033 void setupMatches(void);
James Feist13452092019-03-07 16:38:12 -080034 void createMaxCFMIface(void);
James Feist9a25ed42019-10-15 15:43:44 -070035 void addTachRanges(const std::string& serviceName, const std::string& path);
James Feistb2eb3f52018-12-04 16:17:50 -080036 void checkThresholds(void) override;
Ed Tanous2049bd22022-07-09 07:20:26 -070037 uint64_t getMaxRpm(uint64_t cfmMax) const;
James Feistb2eb3f52018-12-04 16:17:50 -080038
39 private:
Patrick Williams92f8f512022-07-22 19:26:55 -050040 std::vector<sdbusplus::bus::match_t> matches;
James Feistb2eb3f52018-12-04 16:17:50 -080041 boost::container::flat_map<std::string, double> tachReadings;
42 boost::container::flat_map<std::string, std::pair<double, double>>
43 tachRanges;
James Feist13452092019-03-07 16:38:12 -080044 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface;
45 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface;
James Feistd8705872019-02-08 13:26:09 -080046 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080047};
48
James Feist38fb5982020-05-28 10:09:54 -070049struct ExitAirTempSensor :
50 public Sensor,
51 std::enable_shared_from_this<ExitAirTempSensor>
James Feistbc896df2018-11-26 16:28:17 -080052{
Ed Tanousa771f6a2022-01-14 09:36:51 -080053 double powerFactorMin = 0.0;
54 double powerFactorMax = 0.0;
55 double qMin = 0.0;
56 double qMax = 0.0;
57 double alphaS = 0.0;
58 double alphaF = 0.0;
59 double pOffset = 0.0;
James Feistbc896df2018-11-26 16:28:17 -080060
James Feistd8705872019-02-08 13:26:09 -080061 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
62 const std::string& name,
63 const std::string& sensorConfiguration,
64 sdbusplus::asio::object_server& objectServer,
Ed Tanous2049bd22022-07-09 07:20:26 -070065 std::vector<thresholds::Threshold>&& thresholdData);
Ed Tanous8a57ec02020-10-09 12:46:52 -070066 ~ExitAirTempSensor() override;
James Feistbc896df2018-11-26 16:28:17 -080067
68 void checkThresholds(void) override;
69 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070070 void setupMatches(void);
James Feistbc896df2018-11-26 16:28:17 -080071
72 private:
Ed Tanousa771f6a2022-01-14 09:36:51 -080073 double lastReading = 0.0;
James Feistbc896df2018-11-26 16:28:17 -080074
Patrick Williams92f8f512022-07-22 19:26:55 -050075 std::vector<sdbusplus::bus::match_t> matches;
James Feistb2eb3f52018-12-04 16:17:50 -080076 double inletTemp = std::numeric_limits<double>::quiet_NaN();
Zhikui Ren12e3d672020-12-03 15:14:49 -080077 boost::container::flat_map<std::string, double> powerReadings;
James Feistb2eb3f52018-12-04 16:17:50 -080078
James Feist523828e2019-03-04 14:38:37 -080079 sdbusplus::asio::object_server& objServer;
Zhikui Ren12e3d672020-12-03 15:14:49 -080080 std::chrono::time_point<std::chrono::steady_clock> lastTime;
Ed Tanous2049bd22022-07-09 07:20:26 -070081 static double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080082 bool calculate(double& val);
James Feist9566bfa2019-01-29 15:31:23 -080083};