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