blob: 3a1ed73d85aae9b49993ffb14862cd2865223012 [file] [log] [blame]
Matthew Barth35819382018-04-18 14:53:01 -05001#include <experimental/filesystem>
2
3#include <phosphor-logging/elog-errors.hpp>
4#include <xyz/openbmc_project/Sensor/Device/error.hpp>
5
6#include "sensor.hpp"
7#include "sensorset.hpp"
8#include "hwmon.hpp"
9#include "sysfs.hpp"
10
11namespace sensor
12{
13
Matthew Barth2e41b132018-05-07 14:15:45 -050014Sensor::Sensor(const SensorSet::key_type& sensor,
15 const hwmonio::HwmonIO& ioAccess,
16 const std::string& devPath) :
17 sensor(sensor),
18 ioAccess(ioAccess),
19 devPath(devPath)
Matthew Barth9c431062018-05-07 13:55:29 -050020{
21}
22
Matthew Barth2e41b132018-05-07 14:15:45 -050023std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info)
Matthew Barth35819382018-04-18 14:53:01 -050024{
25 namespace fs = std::experimental::filesystem;
26
27 std::shared_ptr<StatusObject> iface = nullptr;
28 static constexpr bool deferSignals = true;
29 auto& bus = *std::get<sdbusplus::bus::bus*>(info);
30 auto& objPath = std::get<std::string>(info);
31 auto& obj = std::get<Object>(info);
32
33 // Check if fault sysfs file exists
34 std::string faultName = sensor.first;
35 std::string faultID = sensor.second;
36 std::string entry = hwmon::entry::fault;
37
38 auto sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(),
39 faultName,
40 faultID,
41 entry);
42 if (fs::exists(sysfsFullPath))
43 {
44 bool functional = true;
45 uint32_t fault = 0;
46 try
47 {
48 fault = ioAccess.read(faultName,
49 faultID,
50 entry,
51 hwmonio::retries,
52 hwmonio::delay);
53 if (fault != 0)
54 {
55 functional = false;
56 }
57 }
58 catch (const std::system_error& e)
59 {
60 using namespace phosphor::logging;
61 using namespace sdbusplus::xyz::openbmc_project::
62 Sensor::Device::Error;
63 using metadata = xyz::openbmc_project::Sensor::
64 Device::ReadFailure;
65
66 report<ReadFailure>(
67 metadata::CALLOUT_ERRNO(e.code().value()),
68 metadata::CALLOUT_DEVICE_PATH(devPath.c_str()));
69
70 log<level::INFO>("Logging failing sysfs file",
71 phosphor::logging::entry(
72 "FILE=%s", sysfsFullPath.c_str()));
73 }
74
75 iface = std::make_shared<StatusObject>(
76 bus,
77 objPath.c_str(),
78 deferSignals);
79 // Set functional property
80 iface->functional(functional);
81
82 obj[InterfaceType::STATUS] = iface;
83 }
84
85 return iface;
86}
87
88} // namespace sensor