summaryrefslogtreecommitdiffstats
path: root/sensor.cpp
blob: 3a1ed73d85aae9b49993ffb14862cd2865223012 (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
#include <experimental/filesystem>

#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Sensor/Device/error.hpp>

#include "sensor.hpp"
#include "sensorset.hpp"
#include "hwmon.hpp"
#include "sysfs.hpp"

namespace sensor
{

Sensor::Sensor(const SensorSet::key_type& sensor,
               const hwmonio::HwmonIO& ioAccess,
               const std::string& devPath) :
    sensor(sensor),
    ioAccess(ioAccess),
    devPath(devPath)
{
}

std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info)
{
    namespace fs = std::experimental::filesystem;

    std::shared_ptr<StatusObject> iface = nullptr;
    static constexpr bool deferSignals = true;
    auto& bus = *std::get<sdbusplus::bus::bus*>(info);
    auto& objPath = std::get<std::string>(info);
    auto& obj = std::get<Object>(info);

    // Check if fault sysfs file exists
    std::string faultName = sensor.first;
    std::string faultID = sensor.second;
    std::string entry = hwmon::entry::fault;

    auto sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
                                                faultName,
                                                faultID,
                                                entry);
    if (fs::exists(sysfsFullPath))
    {
        bool functional = true;
        uint32_t fault = 0;
        try
        {
            fault = ioAccess.read(faultName,
                                  faultID,
                                  entry,
                                  hwmonio::retries,
                                  hwmonio::delay);
            if (fault != 0)
            {
                functional = false;
            }
        }
        catch (const std::system_error& e)
        {
            using namespace phosphor::logging;
            using namespace sdbusplus::xyz::openbmc_project::
                Sensor::Device::Error;
            using metadata = xyz::openbmc_project::Sensor::
                Device::ReadFailure;

            report<ReadFailure>(
                    metadata::CALLOUT_ERRNO(e.code().value()),
                    metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));

            log<level::INFO>("Logging failing sysfs file",
                    phosphor::logging::entry(
                            "FILE=%s", sysfsFullPath.c_str()));
        }

        iface = std::make_shared<StatusObject>(
                bus,
                objPath.c_str(),
                deferSignals);
        // Set functional property
        iface->functional(functional);

        obj[InterfaceType::STATUS] = iface;
    }

    return iface;
}

} // namespace sensor
OpenPOWER on IntegriCloud