blob: e06c20d2c031920b8de010c8fafca2f6204a2171 [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);
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 Feistd8705872019-02-08 13:26:09 -080038 sdbusplus::asio::object_server& objServer;
39 void addTachRanges(const std::string& serviceName, const std::string& path);
James Feistbc896df2018-11-26 16:28:17 -080040};
41
42struct ExitAirTempSensor : public Sensor
43{
James Feistbc896df2018-11-26 16:28:17 -080044
45 double powerFactorMin;
46 double powerFactorMax;
47 double qMin;
48 double qMax;
49 double alphaS;
50 double alphaF;
51 double pOffset = 0;
52
James Feistb2eb3f52018-12-04 16:17:50 -080053 // 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 Feistd8705872019-02-08 13:26:09 -080057 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 Feistbc896df2018-11-26 16:28:17 -080062 ~ExitAirTempSensor();
63
64 void checkThresholds(void) override;
65 void updateReading(void);
66
67 private:
68 double lastReading;
69
James Feistb2eb3f52018-12-04 16:17:50 -080070 std::vector<sdbusplus::bus::match::match> matches;
71 double inletTemp = std::numeric_limits<double>::quiet_NaN();
72
James Feistbc896df2018-11-26 16:28:17 -080073 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
74 std::chrono::time_point<std::chrono::system_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080075 double getTotalCFM(void);
James Feistd8705872019-02-08 13:26:09 -080076 bool calculate(double& val);
James Feistbc896df2018-11-26 16:28:17 -080077 void setupMatches(void);
James Feist9566bfa2019-01-29 15:31:23 -080078};