blob: 74db80bc5f1bc8e72c37caf256536d7208780075 [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
James Feist75eb7692019-02-25 12:50:02 -08003#include "conf.hpp"
James Feist98b704e2019-06-03 16:24:53 -07004#include "dbuspassiveredundancy.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include "interfaces.hpp"
James Feist0c8223b2019-05-08 15:33:33 -07006#include "util.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07007
Patrick Venturea83a3ec2020-08-04 09:52:05 -07008#include <sdbusplus/bus.hpp>
9#include <sdbusplus/message.hpp>
10#include <sdbusplus/server.hpp>
11
Patrick Venture863b9242018-03-08 08:29:23 -080012#include <chrono>
13#include <cmath>
14#include <iostream>
15#include <map>
Patrick Venture0ef1faf2018-06-13 12:50:53 -070016#include <memory>
Patrick Venture863b9242018-03-08 08:29:23 -080017#include <mutex>
18#include <set>
19#include <string>
20#include <tuple>
21#include <vector>
22
Patrick Venturea0764872020-08-08 07:48:43 -070023namespace pid_control
24{
25
Patrick Venture7af157b2018-10-30 11:24:40 -070026int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);
Patrick Venture863b9242018-03-08 08:29:23 -080027
28/*
29 * This ReadInterface will passively listen for Value updates from whomever
30 * owns the associated dbus object.
31 *
32 * This requires another modification in phosphor-dbus-interfaces that will
33 * signal a value update every time it's read instead of only when it changes
34 * to help us:
35 * - ensure we're still receiving data (since we don't control the reader)
36 * - simplify stale data detection
37 * - simplify error detection
38 */
39class DbusPassive : public ReadInterface
40{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070041 public:
James Feist98b704e2019-06-03 16:24:53 -070042 static std::unique_ptr<ReadInterface> createDbusPassive(
43 sdbusplus::bus::bus& bus, const std::string& type,
44 const std::string& id, DbusHelperInterface* helper,
45 const conf::SensorConfig* info,
46 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture0ef1faf2018-06-13 12:50:53 -070047
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070048 DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
Patrick Venturef8cb4642018-10-30 12:02:53 -070049 const std::string& id, DbusHelperInterface* helper,
James Feist98b704e2019-06-03 16:24:53 -070050 const struct SensorProperties& settings, bool failed,
51 const std::string& path,
52 const std::shared_ptr<DbusPassiveRedundancy>& redundancy);
Patrick Venture863b9242018-03-08 08:29:23 -080053
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 ReadReturn read(void) override;
James Feist36b7d8e2018-10-05 15:39:01 -070055 bool getFailed(void) const override;
Patrick Venture863b9242018-03-08 08:29:23 -080056
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070057 void setValue(double value);
James Feist36b7d8e2018-10-05 15:39:01 -070058 void setFailed(bool value);
James Feist4b36f262020-07-07 16:56:41 -070059 void setFunctional(bool value);
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 int64_t getScale(void);
Patrick Venture563a3562018-10-30 09:31:26 -070061 std::string getID(void);
James Feist75eb7692019-02-25 12:50:02 -080062 double getMax(void);
63 double getMin(void);
Patrick Venture863b9242018-03-08 08:29:23 -080064
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070065 private:
66 sdbusplus::bus::bus& _bus;
67 sdbusplus::server::match::match _signal;
68 int64_t _scale;
69 std::string _id; // for debug identification
70 DbusHelperInterface* _helper;
Patrick Venture863b9242018-03-08 08:29:23 -080071
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070072 std::mutex _lock;
73 double _value = 0;
James Feist75eb7692019-02-25 12:50:02 -080074 double _max = 0;
75 double _min = 0;
James Feist36b7d8e2018-10-05 15:39:01 -070076 bool _failed = false;
James Feist4b36f262020-07-07 16:56:41 -070077 bool _functional = true;
James Feist98b704e2019-06-03 16:24:53 -070078
79 std::string path;
80 std::shared_ptr<DbusPassiveRedundancy> redundancy;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070081 /* The last time the value was refreshed, not necessarily changed. */
82 std::chrono::high_resolution_clock::time_point _updated;
Patrick Venture863b9242018-03-08 08:29:23 -080083};
84
Patrick Venture7af157b2018-10-30 11:24:40 -070085int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);
Patrick Venturea0764872020-08-08 07:48:43 -070086
87} // namespace pid_control