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