1 #pragma once 2 #include "Thresholds.hpp" 3 4 #include <boost/container/flat_map.hpp> 5 #include <sdbusplus/asio/connection.hpp> 6 #include <sdbusplus/asio/object_server.hpp> 7 #include <sdbusplus/bus/match.hpp> 8 #include <sensor.hpp> 9 10 #include <chrono> 11 #include <cstdint> 12 #include <limits> 13 #include <memory> 14 #include <string> 15 #include <utility> 16 #include <vector> 17 18 struct ExitAirTempSensor; 19 struct CFMSensor : public Sensor, std::enable_shared_from_this<CFMSensor> 20 { 21 std::vector<std::string> tachs; 22 double c1 = 0.0; 23 double c2 = 0.0; 24 double maxCFM = 0.0; 25 double tachMinPercent = 0.0; 26 double tachMaxPercent = 0.0; 27 28 std::shared_ptr<ExitAirTempSensor> parent; 29 30 CFMSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, 31 const std::string& name, const std::string& sensorConfiguration, 32 sdbusplus::asio::object_server& objectServer, 33 std::vector<thresholds::Threshold>&& thresholdData, 34 std::shared_ptr<ExitAirTempSensor>& parent); 35 ~CFMSensor() override; 36 37 bool calculate(double& /*value*/); 38 void updateReading(); 39 void setupMatches(); 40 void createMaxCFMIface(); 41 void addTachRanges(const std::string& serviceName, const std::string& path); 42 void checkThresholds() override; 43 uint64_t getMaxRpm(uint64_t cfmMax) const; 44 45 private: 46 std::vector<sdbusplus::bus::match_t> matches; 47 boost::container::flat_map<std::string, double> tachReadings; 48 boost::container::flat_map<std::string, std::pair<double, double>> 49 tachRanges; 50 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface; 51 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface; 52 sdbusplus::asio::object_server& objServer; 53 }; 54 55 struct ExitAirTempSensor : 56 public Sensor, 57 std::enable_shared_from_this<ExitAirTempSensor> 58 { 59 double powerFactorMin = 0.0; 60 double powerFactorMax = 0.0; 61 double qMin = 0.0; 62 double qMax = 0.0; 63 double alphaS = 0.0; 64 double alphaF = 0.0; 65 double pOffset = 0.0; 66 67 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection>& conn, 68 const std::string& name, 69 const std::string& sensorConfiguration, 70 sdbusplus::asio::object_server& objectServer, 71 std::vector<thresholds::Threshold>&& thresholdData); 72 ~ExitAirTempSensor() override; 73 74 void checkThresholds() override; 75 void updateReading(); 76 void setupMatches(); 77 78 private: 79 double lastReading = 0.0; 80 81 std::vector<sdbusplus::bus::match_t> matches; 82 double inletTemp = std::numeric_limits<double>::quiet_NaN(); 83 boost::container::flat_map<std::string, double> powerReadings; 84 85 sdbusplus::asio::object_server& objServer; 86 std::chrono::time_point<std::chrono::steady_clock> lastTime; 87 static double getTotalCFM(); 88 bool calculate(double& val); 89 }; 90