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); |
| 30 | void checkThresholds(void) override; |
| 31 | |
| 32 | private: |
| 33 | std::vector<sdbusplus::bus::match::match> matches; |
| 34 | boost::container::flat_map<std::string, double> tachReadings; |
| 35 | boost::container::flat_map<std::string, std::pair<double, double>> |
| 36 | tachRanges; |
| 37 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame^] | 38 | sdbusplus::asio::object_server& objServer; |
| 39 | void addTachRanges(const std::string& serviceName, const std::string& path); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | struct ExitAirTempSensor : public Sensor |
| 43 | { |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 44 | |
| 45 | double powerFactorMin; |
| 46 | double powerFactorMax; |
| 47 | double qMin; |
| 48 | double qMax; |
| 49 | double alphaS; |
| 50 | double alphaF; |
| 51 | double pOffset = 0; |
| 52 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 53 | // todo: make this private once we don't have to hack in a reading |
| 54 | boost::container::flat_map<std::string, double> powerReadings; |
| 55 | |
| 56 | std::vector<std::unique_ptr<CFMSensor>> cfmSensors; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame^] | 57 | ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 58 | const std::string& name, |
| 59 | const std::string& sensorConfiguration, |
| 60 | sdbusplus::asio::object_server& objectServer, |
| 61 | std::vector<thresholds::Threshold>&& thresholds); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 62 | ~ExitAirTempSensor(); |
| 63 | |
| 64 | void checkThresholds(void) override; |
| 65 | void updateReading(void); |
| 66 | |
| 67 | private: |
| 68 | double lastReading; |
| 69 | |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 70 | std::vector<sdbusplus::bus::match::match> matches; |
| 71 | double inletTemp = std::numeric_limits<double>::quiet_NaN(); |
| 72 | |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 73 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
| 74 | std::chrono::time_point<std::chrono::system_clock> lastTime; |
James Feist | b2eb3f5 | 2018-12-04 16:17:50 -0800 | [diff] [blame] | 75 | double getTotalCFM(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame^] | 76 | bool calculate(double& val); |
James Feist | bc896df | 2018-11-26 16:28:17 -0800 | [diff] [blame] | 77 | void setupMatches(void); |
James Feist | 9566bfa | 2019-01-29 15:31:23 -0800 | [diff] [blame] | 78 | }; |