代码拉取完成,页面将自动刷新
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
#include <iostream>
#include <string>
#include <variant>
/* Fan Control */
static constexpr auto objectPath = "/xyz/openbmc_project/settings/fanctrl/zone";
static constexpr auto busName = "xyz.openbmc_project.State.FanCtrl";
static constexpr auto intf = "xyz.openbmc_project.Control.Mode";
static constexpr auto property = "Manual";
using Value = std::variant<bool>;
/* Host Sensor. */
static constexpr auto sobjectPath =
"/xyz/openbmc_project/extsensors/margin/sluggish0";
static constexpr auto sbusName = "xyz.openbmc_project.Hwmon.external";
static constexpr auto sintf = "xyz.openbmc_project.Sensor.Value";
static constexpr auto sproperty = "Value";
using sValue = std::variant<int64_t>;
static constexpr auto propertiesintf = "org.freedesktop.DBus.Properties";
static void SetHostSensor(void)
{
int64_t value = 300;
sValue v{value};
std::string busname{sbusName};
auto PropertyWriteBus = sdbusplus::bus::new_system();
std::string path{sobjectPath};
auto pimMsg = PropertyWriteBus.new_method_call(
busname.c_str(), path.c_str(), propertiesintf, "Set");
pimMsg.append(sintf);
pimMsg.append(sproperty);
pimMsg.append(v);
try
{
auto responseMsg = PropertyWriteBus.call(pimMsg);
fprintf(stderr, "call to Set the host sensor value succeeded.\n");
}
catch (const sdbusplus::exception_t& ex)
{
fprintf(stderr, "call to Set the host sensor value failed.\n");
}
}
static std::string GetControlPath(int8_t zone)
{
return std::string(objectPath) + std::to_string(zone);
}
static void SetManualMode(int8_t zone)
{
bool setValue = (bool)0x01;
Value v{setValue};
std::string busname{busName};
auto PropertyWriteBus = sdbusplus::bus::new_system();
std::string path = GetControlPath(zone);
auto pimMsg = PropertyWriteBus.new_method_call(
busname.c_str(), path.c_str(), propertiesintf, "Set");
pimMsg.append(intf);
pimMsg.append(property);
pimMsg.append(v);
try
{
auto responseMsg = PropertyWriteBus.call(pimMsg);
fprintf(stderr, "call to Set the manual mode succeeded.\n");
}
catch (const sdbusplus::exception_t& ex)
{
fprintf(stderr, "call to Set the manual mode failed.\n");
}
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
int rc = 0;
int64_t zone = 0x01;
SetManualMode(zone);
SetHostSensor();
return rc;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。