summaryrefslogtreecommitdiffstats
path: root/setsensor.cpp
blob: d1c9e532abe85fc649c5ddf332e1724a64a43547 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
#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::SdBusError& 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::SdBusError& ex)
    {
        fprintf(stderr, "call to Set the manual mode failed.\n");
    }
}

int main(int argc, char* argv[])
{
    int rc = 0;

    int64_t zone = 0x01;

    SetManualMode(zone);
    SetHostSensor();
    return rc;
}
OpenPOWER on IntegriCloud