blob: 191f95f2aab6805769fdab026635d851da134602 [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;
James Feista5e58722019-04-22 14:43:11 -070016 double c1;
17 double c2;
18 double maxCFM;
James Feistb2eb3f52018-12-04 16:17:50 -080019 double tachMinPercent;
20 double tachMaxPercent;
21
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,
27 std::vector<thresholds::Threshold>&& thresholds,
28 std::shared_ptr<ExitAirTempSensor>& parent);
Ed Tanous8a57ec02020-10-09 12:46:52 -070029 ~CFMSensor() override;
James Feistb2eb3f52018-12-04 16:17:50 -080030
James Feistd8705872019-02-08 13:26:09 -080031 bool calculate(double&);
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;
James Feist13452092019-03-07 16:38:12 -080037 uint64_t getMaxRpm(uint64_t cfmMax);
James Feistb2eb3f52018-12-04 16:17:50 -080038
39 private:
40 std::vector<sdbusplus::bus::match::match> matches;
41 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{
James Feistbc896df2018-11-26 16:28:17 -080053
54 double powerFactorMin;
55 double powerFactorMax;
56 double qMin;
57 double qMax;
58 double alphaS;
59 double alphaF;
60 double pOffset = 0;
61
James Feistb2eb3f52018-12-04 16:17:50 -080062 // todo: make this private once we don't have to hack in a reading
63 boost::container::flat_map<std::string, double> powerReadings;
64
James Feistd8705872019-02-08 13:26:09 -080065 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
66 const std::string& name,
67 const std::string& sensorConfiguration,
68 sdbusplus::asio::object_server& objectServer,
69 std::vector<thresholds::Threshold>&& thresholds);
Ed Tanous8a57ec02020-10-09 12:46:52 -070070 ~ExitAirTempSensor() override;
James Feistbc896df2018-11-26 16:28:17 -080071
72 void checkThresholds(void) override;
73 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070074 void setupMatches(void);
James Feistbc896df2018-11-26 16:28:17 -080075
76 private:
77 double lastReading;
78
James Feistb2eb3f52018-12-04 16:17:50 -080079 std::vector<sdbusplus::bus::match::match> matches;
80 double inletTemp = std::numeric_limits<double>::quiet_NaN();
81
James Feist523828e2019-03-04 14:38:37 -080082 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080083 std::chrono::time_point<std::chrono::system_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080084 double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080085 bool calculate(double& val);
James Feist9566bfa2019-01-29 15:31:23 -080086};