James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "sensor.hpp" |
| 3 | |
| 4 | #include <boost/container/flat_map.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 5 | #include <sdbusplus/bus/match.hpp> |
| 6 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 7 | #include <chrono> |
| 8 | #include <limits> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 9 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 10 | #include <string> |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 13 | struct ExitAirTempSensor; |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 14 | struct CFMSensor : public Sensor, std::enable_shared_from_this<CFMSensor> |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 15 | { |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 16 | std::vector<std::string> tachs; |
James Feist | a5e5872 | 2019-04-22 14:43:11 -0700 | [diff] [blame] | 17 | double c1; |
| 18 | double c2; |
| 19 | double maxCFM; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 20 | double tachMinPercent; |
| 21 | double tachMaxPercent; |
| 22 | |
| 23 | std::shared_ptr<ExitAirTempSensor> parent; |
| 24 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 25 | 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 Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 30 | ~CFMSensor(); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 31 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 32 | bool calculate(double&); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 33 | void updateReading(void); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 34 | void setupMatches(void); |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 35 | void createMaxCFMIface(void); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 36 | void addTachRanges(const std::string& serviceName, const std::string& path); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 37 | void checkThresholds(void) override; |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 38 | uint64_t getMaxRpm(uint64_t cfmMax); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 39 | |
| 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 Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 45 | std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface; |
| 46 | std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 47 | sdbusplus::asio::object_server& objServer; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 50 | struct ExitAirTempSensor : |
| 51 | public Sensor, |
| 52 | std::enable_shared_from_this<ExitAirTempSensor> |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 53 | { |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 54 | |
| 55 | double powerFactorMin; |
| 56 | double powerFactorMax; |
| 57 | double qMin; |
| 58 | double qMax; |
| 59 | double alphaS; |
| 60 | double alphaF; |
| 61 | double pOffset = 0; |
| 62 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 63 | // 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 Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 66 | 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 Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 71 | ~ExitAirTempSensor(); |
| 72 | |
| 73 | void checkThresholds(void) override; |
| 74 | void updateReading(void); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 75 | void setupMatches(void); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | double lastReading; |
| 79 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 80 | std::vector<sdbusplus::bus::match::match> matches; |
| 81 | double inletTemp = std::numeric_limits<double>::quiet_NaN(); |
| 82 | |
James Feist | 523828e | 2019-03-04 14:38:37 -0800 | [diff] [blame] | 83 | sdbusplus::asio::object_server& objServer; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 84 | std::chrono::time_point<std::chrono::system_clock> lastTime; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 85 | double getTotalCFM(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 86 | bool calculate(double& val); |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 87 | }; |