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