blob: 3681996de61852f7ee6fc83dc6d91a4b68192b29 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#include <iostream>
Patrick Venturee6206562018-03-08 15:36:53 -08002#include <sdbusplus/bus.hpp>
3#include <sdbusplus/message.hpp>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07004#include <string>
Patrick Venturee6206562018-03-08 15:36:53 -08005
6/* Fan Control */
7static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
8static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
Patrick Venturedc3b7902018-03-24 10:41:19 -07009static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
Patrick Venturee6206562018-03-08 15:36:53 -080010static constexpr auto property = "Manual";
11using Value = sdbusplus::message::variant<bool>;
12
13/* Host Sensor. */
14static constexpr auto sobjectPath =
15 "/xyz/openbmc_project/extsensors/margin/sluggish0";
16static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
17static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value";
18static constexpr auto sproperty = "Value";
19using sValue = sdbusplus::message::variant<int64_t>;
20
Patrick Venturee6206562018-03-08 15:36:53 -080021static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
22
23static void SetHostSensor(void)
24{
25 int64_t value = 300;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026 sValue v{value};
Patrick Venturee6206562018-03-08 15:36:53 -080027
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070028 std::string busname{sbusName};
Patrick Venturee6206562018-03-08 15:36:53 -080029 auto PropertyWriteBus = sdbusplus::bus::new_default();
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 std::string path{sobjectPath};
Patrick Venturee6206562018-03-08 15:36:53 -080031
32 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070033 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080034
35 pimMsg.append(sintf);
36 pimMsg.append(sproperty);
37 pimMsg.append(v);
38
Patrick Venture4fd8cff2018-10-31 14:24:12 -070039 try
40 {
41 auto responseMsg = PropertyWriteBus.call(pimMsg);
42 fprintf(stderr, "call to Set the host sensor value succeeded.\n");
43 }
44 catch (const sdbusplus::exception::SdBusError& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080045 {
46 fprintf(stderr, "call to Set the host sensor value failed.\n");
47 }
Patrick Venturee6206562018-03-08 15:36:53 -080048}
49
50static std::string GetControlPath(int8_t zone)
51{
52 return std::string(objectPath) + std::to_string(zone);
53}
54
55static void SetManualMode(int8_t zone)
56{
57 bool setValue = (bool)0x01;
58
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070059 Value v{setValue};
Patrick Venturee6206562018-03-08 15:36:53 -080060
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070061 std::string busname{busName};
Patrick Venturee6206562018-03-08 15:36:53 -080062 auto PropertyWriteBus = sdbusplus::bus::new_default();
63 std::string path = GetControlPath(zone);
64
65 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070066 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080067
68 pimMsg.append(intf);
69 pimMsg.append(property);
70 pimMsg.append(v);
71
Patrick Venture4fd8cff2018-10-31 14:24:12 -070072 try
73 {
74 auto responseMsg = PropertyWriteBus.call(pimMsg);
75 fprintf(stderr, "call to Set the manual mode succeeded.\n");
76 }
77 catch (const sdbusplus::exception::SdBusError& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080078 {
79 fprintf(stderr, "call to Set the manual mode failed.\n");
80 }
Patrick Venturee6206562018-03-08 15:36:53 -080081}
82
83int main(int argc, char* argv[])
84{
85 int rc = 0;
86
87 int64_t zone = 0x01;
88
89 SetManualMode(zone);
90 SetHostSensor();
91 return rc;
92}