blob: d1c9e532abe85fc649c5ddf332e1724a64a43547 [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>
James Feist1f802f52019-02-08 13:51:43 -08005#include <variant>
Patrick Venturee6206562018-03-08 15:36:53 -08006
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";
James Feist1f802f52019-02-08 13:51:43 -080012using Value = std::variant<bool>;
Patrick Venturee6206562018-03-08 15:36:53 -080013
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";
James Feist1f802f52019-02-08 13:51:43 -080020using sValue = std::variant<int64_t>;
Patrick Venturee6206562018-03-08 15:36:53 -080021
Patrick Venturee6206562018-03-08 15:36:53 -080022static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
23
24static void SetHostSensor(void)
25{
26 int64_t value = 300;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027 sValue v{value};
Patrick Venturee6206562018-03-08 15:36:53 -080028
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070029 std::string busname{sbusName};
James Feist9fa90c12019-01-11 15:35:22 -080030 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031 std::string path{sobjectPath};
Patrick Venturee6206562018-03-08 15:36:53 -080032
33 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070034 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080035
36 pimMsg.append(sintf);
37 pimMsg.append(sproperty);
38 pimMsg.append(v);
39
Patrick Venture4fd8cff2018-10-31 14:24:12 -070040 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)
Patrick Venturee6206562018-03-08 15:36:53 -080046 {
47 fprintf(stderr, "call to Set the host sensor value failed.\n");
48 }
Patrick Venturee6206562018-03-08 15:36:53 -080049}
50
51static std::string GetControlPath(int8_t zone)
52{
53 return std::string(objectPath) + std::to_string(zone);
54}
55
56static void SetManualMode(int8_t zone)
57{
58 bool setValue = (bool)0x01;
59
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060 Value v{setValue};
Patrick Venturee6206562018-03-08 15:36:53 -080061
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070062 std::string busname{busName};
James Feist9fa90c12019-01-11 15:35:22 -080063 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Venturee6206562018-03-08 15:36:53 -080064 std::string path = GetControlPath(zone);
65
66 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070067 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080068
69 pimMsg.append(intf);
70 pimMsg.append(property);
71 pimMsg.append(v);
72
Patrick Venture4fd8cff2018-10-31 14:24:12 -070073 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)
Patrick Venturee6206562018-03-08 15:36:53 -080079 {
80 fprintf(stderr, "call to Set the manual mode failed.\n");
81 }
Patrick Venturee6206562018-03-08 15:36:53 -080082}
83
84int 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}