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> |
| 5 | #include <chrono> |
| 6 | #include <limits> |
| 7 | #include <vector> |
| 8 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 9 | struct ExitAirTempSensor; |
| 10 | struct CFMSensor : public Sensor |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 11 | { |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 12 | std::vector<std::string> tachs; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 13 | int32_t c1; |
| 14 | int32_t c2; |
| 15 | int32_t maxCFM; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 16 | double tachMinPercent; |
| 17 | double tachMaxPercent; |
| 18 | |
| 19 | std::shared_ptr<ExitAirTempSensor> parent; |
| 20 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 21 | CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 22 | const std::string& name, const std::string& sensorConfiguration, |
| 23 | sdbusplus::asio::object_server& objectServer, |
| 24 | std::vector<thresholds::Threshold>&& thresholds, |
| 25 | std::shared_ptr<ExitAirTempSensor>& parent); |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 26 | ~CFMSensor(); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 27 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 28 | bool calculate(double&); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 29 | void updateReading(void); |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 30 | void createMaxCFMIface(void); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 31 | void checkThresholds(void) override; |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 32 | uint64_t getMaxRpm(uint64_t cfmMax); |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 33 | |
| 34 | private: |
| 35 | std::vector<sdbusplus::bus::match::match> matches; |
| 36 | boost::container::flat_map<std::string, double> tachReadings; |
| 37 | boost::container::flat_map<std::string, std::pair<double, double>> |
| 38 | tachRanges; |
| 39 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
James Feist | 1345209 | 2019-03-07 16:38:12 -0800 | [diff] [blame] | 40 | std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface; |
| 41 | std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 42 | sdbusplus::asio::object_server& objServer; |
| 43 | void addTachRanges(const std::string& serviceName, const std::string& path); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct ExitAirTempSensor : public Sensor |
| 47 | { |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 48 | |
| 49 | double powerFactorMin; |
| 50 | double powerFactorMax; |
| 51 | double qMin; |
| 52 | double qMax; |
| 53 | double alphaS; |
| 54 | double alphaF; |
| 55 | double pOffset = 0; |
| 56 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 57 | // todo: make this private once we don't have to hack in a reading |
| 58 | boost::container::flat_map<std::string, double> powerReadings; |
| 59 | |
| 60 | std::vector<std::unique_ptr<CFMSensor>> cfmSensors; |
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, |
| 65 | std::vector<thresholds::Threshold>&& thresholds); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 66 | ~ExitAirTempSensor(); |
| 67 | |
| 68 | void checkThresholds(void) override; |
| 69 | void updateReading(void); |
| 70 | |
| 71 | private: |
| 72 | double lastReading; |
| 73 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 74 | std::vector<sdbusplus::bus::match::match> matches; |
| 75 | double inletTemp = std::numeric_limits<double>::quiet_NaN(); |
| 76 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 77 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
James Feist | 523828e | 2019-03-04 14:38:37 -0800 | [diff] [blame] | 78 | sdbusplus::asio::object_server& objServer; |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 79 | std::chrono::time_point<std::chrono::system_clock> lastTime; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 80 | double getTotalCFM(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 81 | bool calculate(double& val); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 82 | void setupMatches(void); |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 83 | }; |