blob: 3933e5df0ce51e610becc2bc134ffa953f160684 [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>
Alexander Hansendae4a3a2025-11-11 17:12:01 +01004#include <xyz/openbmc_project/Sensor/Value/client.hpp>
Patrick Venturea83a3ec2020-08-04 09:52:05 -07005
Ed Tanousf8b6e552025-06-27 13:27:50 -07006#include <cstdint>
7#include <cstdio>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07008#include <string>
James Feist1f802f52019-02-08 13:51:43 -08009#include <variant>
Patrick Venturee6206562018-03-08 15:36:53 -080010
11/* Fan Control */
12static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
13static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
Patrick Venturedc3b7902018-03-24 10:41:19 -070014static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
Patrick Venturee6206562018-03-08 15:36:53 -080015static constexpr auto property = "Manual";
James Feist1f802f52019-02-08 13:51:43 -080016using Value = std::variant<bool>;
Patrick Venturee6206562018-03-08 15:36:53 -080017
Alexander Hansendae4a3a2025-11-11 17:12:01 +010018using SensorValue = sdbusplus::common::xyz::openbmc_project::sensor::Value;
19
Patrick Venturee6206562018-03-08 15:36:53 -080020/* Host Sensor. */
21static constexpr auto sobjectPath =
22 "/xyz/openbmc_project/extsensors/margin/sluggish0";
23static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
James Feist1f802f52019-02-08 13:51:43 -080024using sValue = std::variant<int64_t>;
Patrick Venturee6206562018-03-08 15:36:53 -080025
Patrick Venturee6206562018-03-08 15:36:53 -080026static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
27
28static void SetHostSensor(void)
29{
30 int64_t value = 300;
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070031 sValue v{value};
Patrick Venturee6206562018-03-08 15:36:53 -080032
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070033 std::string busname{sbusName};
James Feist9fa90c12019-01-11 15:35:22 -080034 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070035 std::string path{sobjectPath};
Patrick Venturee6206562018-03-08 15:36:53 -080036
37 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070038 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080039
Alexander Hansendae4a3a2025-11-11 17:12:01 +010040 pimMsg.append(SensorValue::interface);
41 pimMsg.append(SensorValue::property_names::value);
Patrick Venturee6206562018-03-08 15:36:53 -080042 pimMsg.append(v);
43
Patrick Venture4fd8cff2018-10-31 14:24:12 -070044 try
45 {
46 auto responseMsg = PropertyWriteBus.call(pimMsg);
47 fprintf(stderr, "call to Set the host sensor value succeeded.\n");
48 }
Patrick Williamsb228bc32022-07-22 19:26:56 -050049 catch (const sdbusplus::exception_t& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080050 {
51 fprintf(stderr, "call to Set the host sensor value failed.\n");
52 }
Patrick Venturee6206562018-03-08 15:36:53 -080053}
54
55static std::string GetControlPath(int8_t zone)
56{
57 return std::string(objectPath) + std::to_string(zone);
58}
59
60static void SetManualMode(int8_t zone)
61{
Ed Tanousd2768c52025-06-26 11:42:57 -070062 bool setValue = true;
Patrick Venturee6206562018-03-08 15:36:53 -080063
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070064 Value v{setValue};
Patrick Venturee6206562018-03-08 15:36:53 -080065
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070066 std::string busname{busName};
James Feist9fa90c12019-01-11 15:35:22 -080067 auto PropertyWriteBus = sdbusplus::bus::new_system();
Patrick Venturee6206562018-03-08 15:36:53 -080068 std::string path = GetControlPath(zone);
69
70 auto pimMsg = PropertyWriteBus.new_method_call(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070071 busname.c_str(), path.c_str(), propertiesintf, "Set");
Patrick Venturee6206562018-03-08 15:36:53 -080072
73 pimMsg.append(intf);
74 pimMsg.append(property);
75 pimMsg.append(v);
76
Patrick Venture4fd8cff2018-10-31 14:24:12 -070077 try
78 {
79 auto responseMsg = PropertyWriteBus.call(pimMsg);
80 fprintf(stderr, "call to Set the manual mode succeeded.\n");
81 }
Patrick Williamsb228bc32022-07-22 19:26:56 -050082 catch (const sdbusplus::exception_t& ex)
Patrick Venturee6206562018-03-08 15:36:53 -080083 {
84 fprintf(stderr, "call to Set the manual mode failed.\n");
85 }
Patrick Venturee6206562018-03-08 15:36:53 -080086}
87
Harvey.Wua1ae4fa2022-10-28 17:38:35 +080088int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
Patrick Venturee6206562018-03-08 15:36:53 -080089{
90 int rc = 0;
91
92 int64_t zone = 0x01;
93
94 SetManualMode(zone);
95 SetHostSensor();
96 return rc;
97}