blob: 1e774cff8dcd06a0d631347a170c8322263e3f32 [file] [log] [blame]
James Feistbc896df2018-11-26 16:28:17 -08001#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 Feistb2eb3f52018-12-04 16:17:50 -08009struct ExitAirTempSensor;
10struct CFMSensor : public Sensor
James Feistbc896df2018-11-26 16:28:17 -080011{
James Feistb2eb3f52018-12-04 16:17:50 -080012 std::vector<std::string> tachs;
James Feistbc896df2018-11-26 16:28:17 -080013 int32_t c1;
14 int32_t c2;
15 int32_t maxCFM;
James Feistb2eb3f52018-12-04 16:17:50 -080016 double tachMinPercent;
17 double tachMaxPercent;
18
19 std::shared_ptr<ExitAirTempSensor> parent;
20
James Feistd8705872019-02-08 13:26:09 -080021 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 Feist9566bfa2019-01-29 15:31:23 -080026 ~CFMSensor();
James Feistb2eb3f52018-12-04 16:17:50 -080027
James Feistd8705872019-02-08 13:26:09 -080028 bool calculate(double&);
James Feistb2eb3f52018-12-04 16:17:50 -080029 void updateReading(void);
James Feist13452092019-03-07 16:38:12 -080030 void createMaxCFMIface(void);
James Feistb2eb3f52018-12-04 16:17:50 -080031 void checkThresholds(void) override;
James Feist13452092019-03-07 16:38:12 -080032 uint64_t getMaxRpm(uint64_t cfmMax);
James Feistb2eb3f52018-12-04 16:17:50 -080033
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 Feist13452092019-03-07 16:38:12 -080040 std::shared_ptr<sdbusplus::asio::dbus_interface> pwmLimitIface;
41 std::shared_ptr<sdbusplus::asio::dbus_interface> cfmLimitIface;
James Feistd8705872019-02-08 13:26:09 -080042 sdbusplus::asio::object_server& objServer;
43 void addTachRanges(const std::string& serviceName, const std::string& path);
James Feistbc896df2018-11-26 16:28:17 -080044};
45
46struct ExitAirTempSensor : public Sensor
47{
James Feistbc896df2018-11-26 16:28:17 -080048
49 double powerFactorMin;
50 double powerFactorMax;
51 double qMin;
52 double qMax;
53 double alphaS;
54 double alphaF;
55 double pOffset = 0;
56
James Feistb2eb3f52018-12-04 16:17:50 -080057 // 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 Feistd8705872019-02-08 13:26:09 -080061 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 Feistbc896df2018-11-26 16:28:17 -080066 ~ExitAirTempSensor();
67
68 void checkThresholds(void) override;
69 void updateReading(void);
70
71 private:
72 double lastReading;
73
James Feistb2eb3f52018-12-04 16:17:50 -080074 std::vector<sdbusplus::bus::match::match> matches;
75 double inletTemp = std::numeric_limits<double>::quiet_NaN();
76
James Feistbc896df2018-11-26 16:28:17 -080077 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
James Feist523828e2019-03-04 14:38:37 -080078 sdbusplus::asio::object_server& objServer;
James Feistbc896df2018-11-26 16:28:17 -080079 std::chrono::time_point<std::chrono::system_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080080 double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080081 bool calculate(double& val);
James Feistbc896df2018-11-26 16:28:17 -080082 void setupMatches(void);
James Feist9566bfa2019-01-29 15:31:23 -080083};