blob: 2142923e41a773ebb95201054c5ca4d25e71a5f0 [file] [log] [blame]
James Feistbc896df2018-11-26 16:28:17 -08001#pragma once
2#include "sensor.hpp"
3
4#include <boost/container/flat_map.hpp>
5#include <chrono>
6#include <limits>
7#include <vector>
8
James Feistb2eb3f52018-12-04 16:17:50 -08009struct ExitAirTempSensor;
James Feist9a25ed42019-10-15 15:43:44 -070010struct CFMSensor : public Sensor, std::enable_shared_from_this<CFMSensor>
James Feistbc896df2018-11-26 16:28:17 -080011{
James Feistb2eb3f52018-12-04 16:17:50 -080012 std::vector<std::string> tachs;
James Feista5e58722019-04-22 14:43:11 -070013 double c1;
14 double c2;
15 double maxCFM;
James Feistb2eb3f52018-12-04 16:17:50 -080016 double tachMinPercent;
17 double tachMaxPercent;
18
19 std::shared_ptr<ExitAirTempSensor> parent;
20
James Feistd8705872019-02-08 13:26:09 -080021 CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
22 const std::string& name, const std::string& sensorConfiguration,
23 sdbusplus::asio::object_server& objectServer,
24 std::vector<thresholds::Threshold>&& thresholds,
25 std::shared_ptr<ExitAirTempSensor>& parent);
James Feist9566bfa2019-01-29 15:31:23 -080026 ~CFMSensor();
James Feistb2eb3f52018-12-04 16:17:50 -080027
James Feistd8705872019-02-08 13:26:09 -080028 bool calculate(double&);
James Feistb2eb3f52018-12-04 16:17:50 -080029 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070030 void setupMatches(void);
James Feist13452092019-03-07 16:38:12 -080031 void createMaxCFMIface(void);
James Feist9a25ed42019-10-15 15:43:44 -070032 void addTachRanges(const std::string& serviceName, const std::string& path);
James Feistb2eb3f52018-12-04 16:17:50 -080033 void checkThresholds(void) override;
James Feist13452092019-03-07 16:38:12 -080034 uint64_t getMaxRpm(uint64_t cfmMax);
James Feistb2eb3f52018-12-04 16:17:50 -080035
36 private:
37 std::vector<sdbusplus::bus::match::match> matches;
38 boost::container::flat_map<std::string, double> tachReadings;
39 boost::container::flat_map<std::string, std::pair<double, double>>
40 tachRanges;
41 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist13452092019-03-07 16:38:12 -080042 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface;
43 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface;
James Feistd8705872019-02-08 13:26:09 -080044 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080045};
46
James Feist9a25ed42019-10-15 15:43:44 -070047struct ExitAirTempSensor : public Sensor,
48 std::enable_shared_from_this<ExitAirTempSensor>
James Feistbc896df2018-11-26 16:28:17 -080049{
James Feistbc896df2018-11-26 16:28:17 -080050
51 double powerFactorMin;
52 double powerFactorMax;
53 double qMin;
54 double qMax;
55 double alphaS;
56 double alphaF;
57 double pOffset = 0;
58
James Feistb2eb3f52018-12-04 16:17:50 -080059 // todo: make this private once we don't have to hack in a reading
60 boost::container::flat_map<std::string, double> powerReadings;
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);
James Feistbc896df2018-11-26 16:28:17 -080067 ~ExitAirTempSensor();
68
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();
78
James Feistbc896df2018-11-26 16:28:17 -080079 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist523828e2019-03-04 14:38:37 -080080 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080081 std::chrono::time_point<std::chrono::system_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};