blob: faca6b73ef4c9d682e8598f33d2d39a382b5c458 [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001#include <sdbusplus/bus.hpp>
Ed Tanousf8b6e552025-06-27 13:27:50 -07002#include <sdbusplus/exception.hpp>
Patrick Venturee6206562018-03-08 15:36:53 -08003#include <sdbusplus/message.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07004
Ed Tanousf8b6e552025-06-27 13:27:50 -07005#include <cstdint>
6#include <cstdio>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07007#include <string>
James Feist1f802f52019-02-08 13:51:43 -08008#include <variant>
Patrick Venturee6206562018-03-08 15:36:53 -08009
10/* Fan Control */
11static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
12static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
Patrick Venturedc3b7902018-03-24 10:41:19 -070013static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
Patrick Venturee6206562018-03-08 15:36:53 -080014static constexpr auto property = "Manual";
James Feist1f802f52019-02-08 13:51:43 -080015using Value = std::variant<bool>;
Patrick Venturee6206562018-03-08 15:36:53 -080016
17/* Host Sensor. */
18static constexpr auto sobjectPath =
19 "/xyz/openbmc_project/extsensors/margin/sluggish0";
20static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
21static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value";
22static constexpr auto sproperty = "Value";
James Feist1f802f52019-02-08 13:51:43 -080023using sValue = std::variant<int64_t>;
Patrick Venturee6206562018-03-08 15:36:53 -080024
Patrick Venturee6206562018-03-08 15:36:53 -080025static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
26
27static void SetHostSensor(void)
28{
29 int64_t value = 300;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 sValue v{value};
Patrick Venturee6206562018-03-08 15:36:53 -080031
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070032 std::string busname{sbusName};
James Feist9fa90c12019-01-11 15:35:22 -080033 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070034 std::string path{sobjectPath};
Patrick Venturee6206562018-03-08 15:36:53 -080035
36 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070037 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080038
39 pimMsg.append(sintf);
40 pimMsg.append(sproperty);
41 pimMsg.append(v);
42
Patrick Venture4fd8cff2018-10-31 14:24:12 -070043 try
44 {
45 auto responseMsg = PropertyWriteBus.call(pimMsg);
46 fprintf(stderr, "call to Set the host sensor value succeeded.\n");
47 }
Patrick Williamsb228bc32022-07-22 19:26:56 -050048 catch (const sdbusplus::exception_t& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080049 {
50 fprintf(stderr, "call to Set the host sensor value failed.\n");
51 }
Patrick Venturee6206562018-03-08 15:36:53 -080052}
53
54static std::string GetControlPath(int8_t zone)
55{
56 return std::string(objectPath) + std::to_string(zone);
57}
58
59static void SetManualMode(int8_t zone)
60{
Ed Tanousd2768c52025-06-26 11:42:57 -070061 bool setValue = true;
Patrick Venturee6206562018-03-08 15:36:53 -080062
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070063 Value v{setValue};
Patrick Venturee6206562018-03-08 15:36:53 -080064
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070065 std::string busname{busName};
James Feist9fa90c12019-01-11 15:35:22 -080066 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Venturee6206562018-03-08 15:36:53 -080067 std::string path = GetControlPath(zone);
68
69 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070070 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080071
72 pimMsg.append(intf);
73 pimMsg.append(property);
74 pimMsg.append(v);
75
Patrick Venture4fd8cff2018-10-31 14:24:12 -070076 try
77 {
78 auto responseMsg = PropertyWriteBus.call(pimMsg);
79 fprintf(stderr, "call to Set the manual mode succeeded.\n");
80 }
Patrick Williamsb228bc32022-07-22 19:26:56 -050081 catch (const sdbusplus::exception_t& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080082 {
83 fprintf(stderr, "call to Set the manual mode failed.\n");
84 }
Patrick Venturee6206562018-03-08 15:36:53 -080085}
86
Harvey.Wua1ae4fa2022-10-28 17:38:35 +080087int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
Patrick Venturee6206562018-03-08 15:36:53 -080088{
89 int rc = 0;
90
91 int64_t zone = 0x01;
92
93 SetManualMode(zone);
94 SetHostSensor();
95 return rc;
96}