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