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