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> |
Patrick Williams | 457993f | 2021-11-19 12:24:08 -0600 | [diff] [blame] | 10 | #include <sdbusplus/bus/match.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 11 | #include <sdbusplus/message.hpp> |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 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( |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 44 | sdbusplus::bus_t& bus, const std::string& type, const std::string& id, |
| 45 | 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 Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 49 | DbusPassive(sdbusplus::bus_t& 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, |
Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 52 | const SensorProperties& settings, bool failed, |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 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 | |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 59 | void updateValue(double value, bool force); |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame^] | 60 | void setValue(double value, double unscaled); |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 61 | void setValue(double value); |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 62 | |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 63 | void setFailed(bool value); |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 64 | void setFunctional(bool value); |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 65 | void setAvailable(bool value); |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 66 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 67 | int64_t getScale(void); |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 68 | std::string getID(void); |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 69 | double getMax(void); |
| 70 | double getMin(void); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 71 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 72 | private: |
Patrick Williams | 457993f | 2021-11-19 12:24:08 -0600 | [diff] [blame] | 73 | sdbusplus::bus::match_t _signal; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 74 | int64_t _scale; |
| 75 | std::string _id; // for debug identification |
Patrick Venture | 8729eb9 | 2020-08-10 10:38:44 -0700 | [diff] [blame] | 76 | std::unique_ptr<DbusHelperInterface> _helper; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 77 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 78 | std::mutex _lock; |
| 79 | double _value = 0; |
Josh Lehan | b300575 | 2022-02-22 20:48:07 -0800 | [diff] [blame^] | 80 | double _unscaled = 0; |
James Feist | 75eb769 | 2019-02-25 12:50:02 -0800 | [diff] [blame] | 81 | double _max = 0; |
| 82 | double _min = 0; |
James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 83 | bool _failed = false; |
James Feist | 4b36f26 | 2020-07-07 16:56:41 -0700 | [diff] [blame] | 84 | bool _functional = true; |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 85 | bool _available = true; |
| 86 | bool _unavailableAsFailed = true; |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 87 | |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 88 | bool _typeMargin = false; |
Alex.Song | 8f73ad7 | 2021-10-07 00:18:27 +0800 | [diff] [blame] | 89 | bool _typeFan = false; |
Josh Lehan | 3e2f758 | 2020-09-20 22:06:03 -0700 | [diff] [blame] | 90 | bool _badReading = false; |
| 91 | bool _marginHot = false; |
| 92 | |
James Feist | 98b704e | 2019-06-03 16:24:53 -0700 | [diff] [blame] | 93 | std::string path; |
| 94 | std::shared_ptr<DbusPassiveRedundancy> redundancy; |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 95 | /* The last time the value was refreshed, not necessarily changed. */ |
| 96 | std::chrono::high_resolution_clock::time_point _updated; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 99 | int handleSensorValue(sdbusplus::message_t& msg, DbusPassive* owner); |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 100 | |
| 101 | } // namespace pid_control |