blob: e3c2ef5cf951e0eef4ebfb43b799cb160051c167 [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>
James Feist38fb5982020-05-28 10:09:54 -07005#include <sdbusplus/bus/match.hpp>
6
James Feistbc896df2018-11-26 16:28:17 -08007#include <chrono>
8#include <limits>
Patrick Venturefd6ba732019-10-31 14:27:39 -07009#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070010#include <string>
James Feistbc896df2018-11-26 16:28:17 -080011#include <vector>
12
James Feistb2eb3f52018-12-04 16:17:50 -080013struct ExitAirTempSensor;
James Feist9a25ed42019-10-15 15:43:44 -070014struct CFMSensor : public Sensor, std::enable_shared_from_this<CFMSensor>
James Feistbc896df2018-11-26 16:28:17 -080015{
James Feistb2eb3f52018-12-04 16:17:50 -080016 std::vector<std::string> tachs;
James Feista5e58722019-04-22 14:43:11 -070017 double c1;
18 double c2;
19 double maxCFM;
James Feistb2eb3f52018-12-04 16:17:50 -080020 double tachMinPercent;
21 double tachMaxPercent;
22
23 std::shared_ptr<ExitAirTempSensor> parent;
24
James Feistd8705872019-02-08 13:26:09 -080025 CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
26 const std::string& name, const std::string& sensorConfiguration,
27 sdbusplus::asio::object_server& objectServer,
28 std::vector<thresholds::Threshold>&& thresholds,
29 std::shared_ptr<ExitAirTempSensor>& parent);
James Feist9566bfa2019-01-29 15:31:23 -080030 ~CFMSensor();
James Feistb2eb3f52018-12-04 16:17:50 -080031
James Feistd8705872019-02-08 13:26:09 -080032 bool calculate(double&);
James Feistb2eb3f52018-12-04 16:17:50 -080033 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070034 void setupMatches(void);
James Feist13452092019-03-07 16:38:12 -080035 void createMaxCFMIface(void);
James Feist9a25ed42019-10-15 15:43:44 -070036 void addTachRanges(const std::string& serviceName, const std::string& path);
James Feistb2eb3f52018-12-04 16:17:50 -080037 void checkThresholds(void) override;
James Feist13452092019-03-07 16:38:12 -080038 uint64_t getMaxRpm(uint64_t cfmMax);
James Feistb2eb3f52018-12-04 16:17:50 -080039
40 private:
41 std::vector<sdbusplus::bus::match::match> matches;
42 boost::container::flat_map<std::string, double> tachReadings;
43 boost::container::flat_map<std::string, std::pair<double, double>>
44 tachRanges;
45 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist13452092019-03-07 16:38:12 -080046 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface;
47 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface;
James Feistd8705872019-02-08 13:26:09 -080048 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080049};
50
James Feist38fb5982020-05-28 10:09:54 -070051struct ExitAirTempSensor :
52 public Sensor,
53 std::enable_shared_from_this<ExitAirTempSensor>
James Feistbc896df2018-11-26 16:28:17 -080054{
James Feistbc896df2018-11-26 16:28:17 -080055
56 double powerFactorMin;
57 double powerFactorMax;
58 double qMin;
59 double qMax;
60 double alphaS;
61 double alphaF;
62 double pOffset = 0;
63
James Feistb2eb3f52018-12-04 16:17:50 -080064 // todo: make this private once we don't have to hack in a reading
65 boost::container::flat_map<std::string, double> powerReadings;
66
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,
71 std::vector<thresholds::Threshold>&& thresholds);
James Feistbc896df2018-11-26 16:28:17 -080072 ~ExitAirTempSensor();
73
74 void checkThresholds(void) override;
75 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070076 void setupMatches(void);
James Feistbc896df2018-11-26 16:28:17 -080077
78 private:
79 double lastReading;
80
James Feistb2eb3f52018-12-04 16:17:50 -080081 std::vector<sdbusplus::bus::match::match> matches;
82 double inletTemp = std::numeric_limits<double>::quiet_NaN();
83
James Feistbc896df2018-11-26 16:28:17 -080084 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist523828e2019-03-04 14:38:37 -080085 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080086 std::chrono::time_point<std::chrono::system_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080087 double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080088 bool calculate(double& val);
James Feist9566bfa2019-01-29 15:31:23 -080089};