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; |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 16 | double c1 = 0.0; |
| 17 | double c2 = 0.0; |
| 18 | double maxCFM = 0.0; |
| 19 | double tachMinPercent = 0.0; |
| 20 | double tachMaxPercent = 0.0; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 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, |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 27 | std::vector<thresholds::Threshold>&& thresholdData, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 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 | |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 31 | bool calculate(double& /*value*/); |
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; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 37 | uint64_t getMaxRpm(uint64_t cfmMax) const; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 38 | |
| 39 | private: |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 40 | std::vector<sdbusplus::bus::match_t> matches; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 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 | { |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 53 | double powerFactorMin = 0.0; |
| 54 | double powerFactorMax = 0.0; |
| 55 | double qMin = 0.0; |
| 56 | double qMax = 0.0; |
| 57 | double alphaS = 0.0; |
| 58 | double alphaF = 0.0; |
| 59 | double pOffset = 0.0; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 60 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 61 | ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 62 | const std::string& name, |
| 63 | const std::string& sensorConfiguration, |
| 64 | sdbusplus::asio::object_server& objectServer, |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 65 | std::vector<thresholds::Threshold>&& thresholdData); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 66 | ~ExitAirTempSensor() override; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 67 | |
| 68 | void checkThresholds(void) override; |
| 69 | void updateReading(void); |
James Feist | 9a25ed4 | 2019-10-15 15:43:44 -0700 | [diff] [blame] | 70 | void setupMatches(void); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 71 | |
| 72 | private: |
Ed Tanous | a771f6a | 2022-01-14 09:36:51 -0800 | [diff] [blame] | 73 | double lastReading = 0.0; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 74 | |
Patrick Williams | 92f8f51 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 75 | std::vector<sdbusplus::bus::match_t> matches; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 76 | double inletTemp = std::numeric_limits<double>::quiet_NaN(); |
Zhikui Ren | 12e3d67 | 2020-12-03 15:14:49 -0800 | [diff] [blame] | 77 | boost::container::flat_map<std::string, double> powerReadings; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 78 | |
James Feist | 523828e | 2019-03-04 14:38:37 -0800 | [diff] [blame] | 79 | sdbusplus::asio::object_server& objServer; |
Zhikui Ren | 12e3d67 | 2020-12-03 15:14:49 -0800 | [diff] [blame] | 80 | std::chrono::time_point<std::chrono::steady_clock> lastTime; |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 81 | static double getTotalCFM(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 82 | bool calculate(double& val); |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 83 | }; |