blob: 55da2030569848509012a91b56741fe8d894b05e [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 Feistd8705872019-02-08 13:26:09 -080062 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
63 const std::string& name,
64 const std::string& sensorConfiguration,
65 sdbusplus::asio::object_server& objectServer,
66 std::vector<thresholds::Threshold>&& thresholds);
Ed Tanous8a57ec02020-10-09 12:46:52 -070067 ~ExitAirTempSensor() override;
James Feistbc896df2018-11-26 16:28:17 -080068
69 void checkThresholds(void) override;
70 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070071 void setupMatches(void);
James Feistbc896df2018-11-26 16:28:17 -080072
73 private:
74 double lastReading;
75
James Feistb2eb3f52018-12-04 16:17:50 -080076 std::vector<sdbusplus::bus::match::match> matches;
77 double inletTemp = std::numeric_limits<double>::quiet_NaN();
Zhikui Ren12e3d672020-12-03 15:14:49 -080078 boost::container::flat_map<std::string, double> powerReadings;
James Feistb2eb3f52018-12-04 16:17:50 -080079
James Feist523828e2019-03-04 14:38:37 -080080 sdbusplus::asio::object_server& objServer;
Zhikui Ren12e3d672020-12-03 15:14:49 -080081 std::chrono::time_point<std::chrono::steady_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080082 double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080083 bool calculate(double& val);
James Feist9566bfa2019-01-29 15:31:23 -080084};