blob: 60ce21abf02f93949d77485ebfc19fce718a016b [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#include <sdbusplus/bus.hpp>
2#include <sdbusplus/message.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07003
4#include <iostream>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include <string>
James Feist1f802f52019-02-08 13:51:43 -08006#include <variant>
Patrick Venturee6206562018-03-08 15:36:53 -08007
8/* Fan Control */
9static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
10static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
Patrick Venturedc3b7902018-03-24 10:41:19 -070011static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
Patrick Venturee6206562018-03-08 15:36:53 -080012static constexpr auto property = "Manual";
James Feist1f802f52019-02-08 13:51:43 -080013using Value = std::variant<bool>;
Patrick Venturee6206562018-03-08 15:36:53 -080014
15/* Host Sensor. */
16static constexpr auto sobjectPath =
17 "/xyz/openbmc_project/extsensors/margin/sluggish0";
18static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
19static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value";
20static constexpr auto sproperty = "Value";
James Feist1f802f52019-02-08 13:51:43 -080021using sValue = std::variant<int64_t>;
Patrick Venturee6206562018-03-08 15:36:53 -080022
Patrick Venturee6206562018-03-08 15:36:53 -080023static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
24
25static void SetHostSensor(void)
26{
27 int64_t value = 300;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 sValue v{value};
Patrick Venturee6206562018-03-08 15:36:53 -080029
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 std::string busname{sbusName};
James Feist9fa90c12019-01-11 15:35:22 -080031 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070032 std::string path{sobjectPath};
Patrick Venturee6206562018-03-08 15:36:53 -080033
34 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070035 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080036
37 pimMsg.append(sintf);
38 pimMsg.append(sproperty);
39 pimMsg.append(v);
40
Patrick Venture4fd8cff2018-10-31 14:24:12 -070041 try
42 {
43 auto responseMsg = PropertyWriteBus.call(pimMsg);
44 fprintf(stderr, "call to Set the host sensor value succeeded.\n");
45 }
46 catch (const sdbusplus::exception::SdBusError& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080047 {
48 fprintf(stderr, "call to Set the host sensor value failed.\n");
49 }
Patrick Venturee6206562018-03-08 15:36:53 -080050}
51
52static std::string GetControlPath(int8_t zone)
53{
54 return std::string(objectPath) + std::to_string(zone);
55}
56
57static void SetManualMode(int8_t zone)
58{
59 bool setValue = (bool)0x01;
60
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070061 Value v{setValue};
Patrick Venturee6206562018-03-08 15:36:53 -080062
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070063 std::string busname{busName};
James Feist9fa90c12019-01-11 15:35:22 -080064 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Venturee6206562018-03-08 15:36:53 -080065 std::string path = GetControlPath(zone);
66
67 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070068 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080069
70 pimMsg.append(intf);
71 pimMsg.append(property);
72 pimMsg.append(v);
73
Patrick Venture4fd8cff2018-10-31 14:24:12 -070074 try
75 {
76 auto responseMsg = PropertyWriteBus.call(pimMsg);
77 fprintf(stderr, "call to Set the manual mode succeeded.\n");
78 }
79 catch (const sdbusplus::exception::SdBusError& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080080 {
81 fprintf(stderr, "call to Set the manual mode failed.\n");
82 }
Patrick Venturee6206562018-03-08 15:36:53 -080083}
84
85int main(int argc, char* argv[])
86{
87 int rc = 0;
88
89 int64_t zone = 0x01;
90
91 SetManualMode(zone);
92 SetHostSensor();
93 return rc;
94}