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