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