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