blob: cef8090768a85e3af443a656c2db0d6ac8612d71 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#include <iostream>
2#include <string>
3
4#include <sdbusplus/bus.hpp>
5#include <sdbusplus/message.hpp>
6
7/* Fan Control */
8static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
9static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
Patrick Venturedc3b7902018-03-24 10:41:19 -070010static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
Patrick Venturee6206562018-03-08 15:36:53 -080011static constexpr auto property = "Manual";
12using Value = sdbusplus::message::variant<bool>;
13
14/* Host Sensor. */
15static constexpr auto sobjectPath =
16 "/xyz/openbmc_project/extsensors/margin/sluggish0";
17static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
18static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value";
19static constexpr auto sproperty = "Value";
20using sValue = sdbusplus::message::variant<int64_t>;
21
22
23static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
24
25static 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
55static std::string GetControlPath(int8_t zone)
56{
57 return std::string(objectPath) + std::to_string(zone);
58}
59
60static 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
91int 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}