| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 1 | #include <sdbusplus/bus.hpp> |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 2 | #include <sdbusplus/exception.hpp> |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 3 | #include <sdbusplus/message.hpp> |
| Alexander Hansen | dae4a3a | 2025-11-11 17:12:01 +0100 | [diff] [blame^] | 4 | #include <xyz/openbmc_project/Sensor/Value/client.hpp> |
| Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 5 | |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 6 | #include <cstdint> |
| 7 | #include <cstdio> |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 8 | #include <string> |
| James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 9 | #include <variant> |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 10 | |
| 11 | /* Fan Control */ |
| 12 | static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone"; |
| 13 | static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl"; |
| Patrick Venture | dc3b790 | 2018-03-24 10:41:19 -0700 | [diff] [blame] | 14 | static constexpr auto intf = "xyz.openbmc_project.Control.Mode"; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 15 | static constexpr auto property = "Manual"; |
| James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 16 | using Value = std::variant<bool>; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 17 | |
| Alexander Hansen | dae4a3a | 2025-11-11 17:12:01 +0100 | [diff] [blame^] | 18 | using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value; |
| 19 | |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 20 | /* Host Sensor. */ |
| 21 | static constexpr auto sobjectPath = |
| 22 | "/xyz/openbmc_project/extsensors/margin/sluggish0"; |
| 23 | static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external"; |
| James Feist | 1f802f5 | 2019-02-08 13:51:43 -0800 | [diff] [blame] | 24 | using sValue = std::variant<int64_t>; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 25 | |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 26 | static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties"; |
| 27 | |
| 28 | static void SetHostSensor(void) |
| 29 | { |
| 30 | int64_t value = 300; |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 31 | sValue v{value}; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 32 | |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 33 | std::string busname{sbusName}; |
| James Feist | 9fa90c1 | 2019-01-11 15:35:22 -0800 | [diff] [blame] | 34 | auto PropertyWriteBus = sdbusplus::bus::new_system(); |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 35 | std::string path{sobjectPath}; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 36 | |
| 37 | auto pimMsg = PropertyWriteBus.new_method_call( |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 38 | busname.c_str(), path.c_str(), propertiesintf, "Set"); |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 39 | |
| Alexander Hansen | dae4a3a | 2025-11-11 17:12:01 +0100 | [diff] [blame^] | 40 | pimMsg.append(SensorValue::interface); |
| 41 | pimMsg.append(SensorValue::property_names::value); |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 42 | pimMsg.append(v); |
| 43 | |
| Patrick Venture | 4fd8cff | 2018-10-31 14:24:12 -0700 | [diff] [blame] | 44 | try |
| 45 | { |
| 46 | auto responseMsg = PropertyWriteBus.call(pimMsg); |
| 47 | fprintf(stderr, "call to Set the host sensor value succeeded.\n"); |
| 48 | } |
| Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 49 | catch (const sdbusplus::exception_t& ex) |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 50 | { |
| 51 | fprintf(stderr, "call to Set the host sensor value failed.\n"); |
| 52 | } |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static std::string GetControlPath(int8_t zone) |
| 56 | { |
| 57 | return std::string(objectPath) + std::to_string(zone); |
| 58 | } |
| 59 | |
| 60 | static void SetManualMode(int8_t zone) |
| 61 | { |
| Ed Tanous | d2768c5 | 2025-06-26 11:42:57 -0700 | [diff] [blame] | 62 | bool setValue = true; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 63 | |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 64 | Value v{setValue}; |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 65 | |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 66 | std::string busname{busName}; |
| James Feist | 9fa90c1 | 2019-01-11 15:35:22 -0800 | [diff] [blame] | 67 | auto PropertyWriteBus = sdbusplus::bus::new_system(); |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 68 | std::string path = GetControlPath(zone); |
| 69 | |
| 70 | auto pimMsg = PropertyWriteBus.new_method_call( |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 71 | busname.c_str(), path.c_str(), propertiesintf, "Set"); |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 72 | |
| 73 | pimMsg.append(intf); |
| 74 | pimMsg.append(property); |
| 75 | pimMsg.append(v); |
| 76 | |
| Patrick Venture | 4fd8cff | 2018-10-31 14:24:12 -0700 | [diff] [blame] | 77 | try |
| 78 | { |
| 79 | auto responseMsg = PropertyWriteBus.call(pimMsg); |
| 80 | fprintf(stderr, "call to Set the manual mode succeeded.\n"); |
| 81 | } |
| Patrick Williams | b228bc3 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 82 | catch (const sdbusplus::exception_t& ex) |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 83 | { |
| 84 | fprintf(stderr, "call to Set the manual mode failed.\n"); |
| 85 | } |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| Harvey.Wu | a1ae4fa | 2022-10-28 17:38:35 +0800 | [diff] [blame] | 88 | int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 89 | { |
| 90 | int rc = 0; |
| 91 | |
| 92 | int64_t zone = 0x01; |
| 93 | |
| 94 | SetManualMode(zone); |
| 95 | SetHostSensor(); |
| 96 | return rc; |
| 97 | } |