Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 3 | #include "conf.hpp" |
Patrick Venture | aadb30d | 2020-08-10 09:17:11 -0700 | [diff] [blame] | 4 | #include "dbushelper_interface.hpp" |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 5 | #include "dbuspassiveredundancy.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 6 | #include "interfaces.hpp" |
James Feist | 0c8223b | 2019-05-08 15:33:33 -0700 | [diff] [blame] | 7 | #include "util.hpp" |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 8 | |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
| 10 | #include <sdbusplus/message.hpp> |
| 11 | #include <sdbusplus/server.hpp> |
| 12 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 13 | #include <chrono> |
| 14 | #include <cmath> |
| 15 | #include <iostream> |
| 16 | #include <map> |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 17 | #include <memory> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 18 | #include <mutex> |
| 19 | #include <set> |
| 20 | #include <string> |
| 21 | #include <tuple> |
| 22 | #include <vector> |
| 23 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 24 | namespace pid_control |
| 25 | { |
| 26 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 27 | int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * This ReadInterface will passively listen for Value updates from whomever |
| 31 | * owns the associated dbus object. |
| 32 | * |
| 33 | * This requires another modification in phosphor-dbus-interfaces that will |
| 34 | * signal a value update every time it's read instead of only when it changes |
| 35 | * to help us: |
| 36 | * - ensure we're still receiving data (since we don't control the reader) |
| 37 | * - simplify stale data detection |
| 38 | * - simplify error detection |
| 39 | */ |
| 40 | class DbusPassive : public ReadInterface |
| 41 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 42 | public: |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 43 | static std::unique_ptr<ReadInterface> createDbusPassive( |
| 44 | sdbusplus::bus::bus& bus, const std::string& type, |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 45 | const std::string& id, std::unique_ptr<DbusHelperInterface> helper, |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 46 | const conf::SensorConfig* info, |
| 47 | const std::shared_ptr<DbusPassiveRedundancy>& redundancy); |
Patrick Venture | 0ef1faf | 2018-06-13 12:50:53 -0700 | [diff] [blame] | 48 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 49 | DbusPassive(sdbusplus::bus::bus& bus, const std::string& type, |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 50 | const std::string& id, |
| 51 | std::unique_ptr<DbusHelperInterface> helper, |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 52 | const struct SensorProperties& settings, bool failed, |
| 53 | const std::string& path, |
| 54 | const std::shared_ptr<DbusPassiveRedundancy>& redundancy); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 55 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 56 | ReadReturn read(void) override; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 57 | bool getFailed(void) const override; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 58 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 59 | void setValue(double value); |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 60 | void setFailed(bool value); |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 61 | void setFunctional(bool value); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 62 | int64_t getScale(void); |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 63 | std::string getID(void); |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 64 | double getMax(void); |
| 65 | double getMin(void); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 66 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 67 | private: |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 68 | sdbusplus::server::match::match _signal; |
| 69 | int64_t _scale; |
| 70 | std::string _id; // for debug identification |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 71 | std::unique_ptr<DbusHelperInterface> _helper; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 72 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 73 | std::mutex _lock; |
| 74 | double _value = 0; |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 75 | double _max = 0; |
| 76 | double _min = 0; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 77 | bool _failed = false; |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 78 | bool _functional = true; |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 79 | |
| 80 | std::string path; |
| 81 | std::shared_ptr<DbusPassiveRedundancy> redundancy; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 82 | /* The last time the value was refreshed, not necessarily changed. */ |
| 83 | std::chrono::high_resolution_clock::time_point _updated; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 86 | int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner); |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 87 | |
| 88 | } // namespace pid_control |