1 #include <iostream>
2 #include <sdbusplus/bus.hpp>
3 #include <sdbusplus/message.hpp>
4 #include <string>
5 #include <variant>
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";
10 static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
11 static constexpr auto property = "Manual";
12 using Value = std::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 = std::variant<int64_t>;
21 
22 static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
23 
24 static void SetHostSensor(void)
25 {
26     int64_t value = 300;
27     sValue v{value};
28 
29     std::string busname{sbusName};
30     auto PropertyWriteBus = sdbusplus::bus::new_system();
31     std::string path{sobjectPath};
32 
33     auto pimMsg = PropertyWriteBus.new_method_call(
34         busname.c_str(), path.c_str(), propertiesintf, "Set");
35 
36     pimMsg.append(sintf);
37     pimMsg.append(sproperty);
38     pimMsg.append(v);
39 
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)
46     {
47         fprintf(stderr, "call to Set the host sensor value failed.\n");
48     }
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 
60     Value v{setValue};
61 
62     std::string busname{busName};
63     auto PropertyWriteBus = sdbusplus::bus::new_system();
64     std::string path = GetControlPath(zone);
65 
66     auto pimMsg = PropertyWriteBus.new_method_call(
67         busname.c_str(), path.c_str(), propertiesintf, "Set");
68 
69     pimMsg.append(intf);
70     pimMsg.append(property);
71     pimMsg.append(v);
72 
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)
79     {
80         fprintf(stderr, "call to Set the manual mode failed.\n");
81     }
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 }
94