blob: f18fd9b4083c105c43099eab329e044f3ae4a454 [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
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 Feistbc896df2018-11-26 16:28:17 -080039};
40
41struct ExitAirTempSensor : public Sensor
42{
James Feistbc896df2018-11-26 16:28:17 -080043
44 double powerFactorMin;
45 double powerFactorMax;
46 double qMin;
47 double qMax;
48 double alphaS;
49 double alphaF;
50 double pOffset = 0;
51
James Feistb2eb3f52018-12-04 16:17:50 -080052 // 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 Feistbc896df2018-11-26 16:28:17 -080056 ExitAirTempSensor(std::shared_ptr<sdbusplus::asio::connection> &conn,
James Feistb2eb3f52018-12-04 16:17:50 -080057 const std::string &name,
James Feistbc896df2018-11-26 16:28:17 -080058 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 Feistb2eb3f52018-12-04 16:17:50 -080069 std::vector<sdbusplus::bus::match::match> matches;
70 double inletTemp = std::numeric_limits<double>::quiet_NaN();
71
James Feistbc896df2018-11-26 16:28:17 -080072 std::shared_ptr<sdbusplus::asio::connection> dbusConnection;
73 std::chrono::time_point<std::chrono::system_clock> lastTime;
James Feistb2eb3f52018-12-04 16:17:50 -080074 double getTotalCFM(void);
James Feistbc896df2018-11-26 16:28:17 -080075 bool calculate(double &val);
76 void setupMatches(void);
77};