blob: 2d69cece36b92a9ba3031fd8ec95aeb9ded9b9e0 [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;
James Feist13452092019-03-07 16:38:12 -080045 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface;
46 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface;
James Feistd8705872019-02-08 13:26:09 -080047 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080048};
49
James Feist38fb5982020-05-28 10:09:54 -070050struct ExitAirTempSensor :
51 public Sensor,
52 std::enable_shared_from_this<ExitAirTempSensor>
James Feistbc896df2018-11-26 16:28:17 -080053{
James Feistbc896df2018-11-26 16:28:17 -080054
55 double powerFactorMin;
56 double powerFactorMax;
57 double qMin;
58 double qMax;
59 double alphaS;
60 double alphaF;
61 double pOffset = 0;
62
James Feistb2eb3f52018-12-04 16:17:50 -080063 // todo: make this private once we don't have to hack in a reading
64 boost::container::flat_map<std::string, double> powerReadings;
65
James Feistd8705872019-02-08 13:26:09 -080066 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn,
67 const std::string& name,
68 const std::string& sensorConfiguration,
69 sdbusplus::asio::object_server& objectServer,
70 std::vector<thresholds::Threshold>&& thresholds);
James Feistbc896df2018-11-26 16:28:17 -080071 ~ExitAirTempSensor();
72
73 void checkThresholds(void) override;
74 void updateReading(void);
James Feist9a25ed42019-10-15 15:43:44 -070075 void setupMatches(void);
James Feistbc896df2018-11-26 16:28:17 -080076
77 private:
78 double lastReading;
79
James Feistb2eb3f52018-12-04 16:17:50 -080080 std::vector<sdbusplus::bus::match::match> matches;
81 double inletTemp = std::numeric_limits<double>::quiet_NaN();
82
James Feist523828e2019-03-04 14:38:37 -080083 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080084 std::chrono::time_point<std::chrono::system_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080085 double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080086 bool calculate(double& val);
James Feist9566bfa2019-01-29 15:31:23 -080087};