1 #include <sdbusplus/bus.hpp> 2 #include <sdbusplus/message.hpp> 3 4 #include <iostream> 5 #include <string> 6 #include <variant> 7 8 /* Fan Control */ 9 static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone"; 10 static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl"; 11 static constexpr auto intf = "xyz.openbmc_project.Control.Mode"; 12 static constexpr auto property = "Manual"; 13 using Value = std::variant<bool>; 14 15 /* Host Sensor. */ 16 static constexpr auto sobjectPath = 17 "/xyz/openbmc_project/extsensors/margin/sluggish0"; 18 static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external"; 19 static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value"; 20 static constexpr auto sproperty = "Value"; 21 using sValue = std::variant<int64_t>; 22 23 static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties"; 24 25 static void SetHostSensor(void) 26 { 27 int64_t value = 300; 28 sValue v{value}; 29 30 std::string busname{sbusName}; 31 auto PropertyWriteBus = sdbusplus::bus::new_system(); 32 std::string path{sobjectPath}; 33 34 auto pimMsg = PropertyWriteBus.new_method_call( 35 busname.c_str(), path.c_str(), propertiesintf, "Set"); 36 37 pimMsg.append(sintf); 38 pimMsg.append(sproperty); 39 pimMsg.append(v); 40 41 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::exception& ex) 47 { 48 fprintf(stderr, "call to Set the host sensor value failed.\n"); 49 } 50 } 51 52 static std::string GetControlPath(int8_t zone) 53 { 54 return std::string(objectPath) + std::to_string(zone); 55 } 56 57 static void SetManualMode(int8_t zone) 58 { 59 bool setValue = (bool)0x01; 60 61 Value v{setValue}; 62 63 std::string busname{busName}; 64 auto PropertyWriteBus = sdbusplus::bus::new_system(); 65 std::string path = GetControlPath(zone); 66 67 auto pimMsg = PropertyWriteBus.new_method_call( 68 busname.c_str(), path.c_str(), propertiesintf, "Set"); 69 70 pimMsg.append(intf); 71 pimMsg.append(property); 72 pimMsg.append(v); 73 74 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::exception& ex) 80 { 81 fprintf(stderr, "call to Set the manual mode failed.\n"); 82 } 83 } 84 85 int 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 } 95