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