1 #include <sdbusplus/bus.hpp>
2 #include <sdbusplus/exception.hpp>
3 #include <sdbusplus/message.hpp>
4 #include <xyz/openbmc_project/Control/Mode/client.hpp>
5 #include <xyz/openbmc_project/Sensor/Value/client.hpp>
6
7 #include <cstdint>
8 #include <cstdio>
9 #include <string>
10 #include <variant>
11
12 /* Fan Control */
13 static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
14 static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
15 using Value = std::variant<bool>;
16
17 using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
18 using ControlMode = sdbusplus::common::xyz::openbmc_project::control::Mode;
19
20 /* Host Sensor. */
21 static constexpr auto sobjectPath =
22 "/xyz/openbmc_project/extsensors/margin/sluggish0";
23 static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
24 using sValue = std::variant<int64_t>;
25
26 static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
27
SetHostSensor(void)28 static void SetHostSensor(void)
29 {
30 int64_t value = 300;
31 sValue v{value};
32
33 std::string busname{sbusName};
34 auto PropertyWriteBus = sdbusplus::bus::new_system();
35 std::string path{sobjectPath};
36
37 auto pimMsg = PropertyWriteBus.new_method_call(
38 busname.c_str(), path.c_str(), propertiesintf, "Set");
39
40 pimMsg.append(SensorValue::interface);
41 pimMsg.append(SensorValue::property_names::value);
42 pimMsg.append(v);
43
44 try
45 {
46 auto responseMsg = PropertyWriteBus.call(pimMsg);
47 fprintf(stderr, "call to Set the host sensor value succeeded.\n");
48 }
49 catch (const sdbusplus::exception_t& ex)
50 {
51 fprintf(stderr, "call to Set the host sensor value failed.\n");
52 }
53 }
54
GetControlPath(int8_t zone)55 static std::string GetControlPath(int8_t zone)
56 {
57 return std::string(objectPath) + std::to_string(zone);
58 }
59
SetManualMode(int8_t zone)60 static void SetManualMode(int8_t zone)
61 {
62 bool setValue = true;
63
64 Value v{setValue};
65
66 std::string busname{busName};
67 auto PropertyWriteBus = sdbusplus::bus::new_system();
68 std::string path = GetControlPath(zone);
69
70 auto pimMsg = PropertyWriteBus.new_method_call(
71 busname.c_str(), path.c_str(), propertiesintf, "Set");
72
73 pimMsg.append(ControlMode::interface);
74 pimMsg.append(ControlMode::property_names::manual);
75 pimMsg.append(v);
76
77 try
78 {
79 auto responseMsg = PropertyWriteBus.call(pimMsg);
80 fprintf(stderr, "call to Set the manual mode succeeded.\n");
81 }
82 catch (const sdbusplus::exception_t& ex)
83 {
84 fprintf(stderr, "call to Set the manual mode failed.\n");
85 }
86 }
87
main(int argc,char * argv[])88 int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
89 {
90 int rc = 0;
91
92 int64_t zone = 0x01;
93
94 SetManualMode(zone);
95 SetHostSensor();
96 return rc;
97 }
98