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