blob: cc36ef4792f71409f253f10d56fb45f2723bcd59 [file] [log] [blame]
Brad Bishop26b815f2017-01-04 13:32:47 -05001#pragma once
Patrick Williams3667cf32015-10-20 22:39:11 -05002
3#include <fstream>
4#include <string>
5
Brad Bishopa9b5f052017-01-17 14:50:08 -05006inline std::string make_sysfs_path(const std::string& path,
7 const std::string& type,
8 const std::string& id,
9 const std::string& entry)
Patrick Williams3667cf32015-10-20 22:39:11 -050010{
11 using namespace std::literals;
12
13 return path + "/"s + type + id + "_"s + entry;
14}
15
Brad Bishop613a5b32017-01-05 20:58:13 -050016
17/** @brief Find hwmon instances
18 *
19 * Look for a matching hwmon instance given an
20 * open firmware device path.
21 *
22 * @param[in] ofNode- The open firmware device path.
23 *
24 * @returns[in] - The hwmon instance path or an empty
25 * string if no match is found.
26 */
27std::string findHwmon(const std::string& ofNode);
28
Brad Bishop4db64422017-02-16 11:33:32 -050029/** @brief Read an hwmon sysfs value.
30 *
31 * Calls exit(3) with bad status on failure.
32 *
33 * @param[in] root - The hwmon class root.
34 * @param[in] instance - The hwmon instance (ex. hwmon1).
35 * @param[in] type - The hwmon type (ex. temp).
36 * @param[in] id - The hwmon id (ex. 1).
37 * @param[in] sensor - The hwmon sensor (ex. input).
38 *
39 * @returns - The read value.
40 */
41int readSysfsWithCallout(const std::string& root,
42 const std::string& instance,
43 const std::string& type,
44 const std::string& id,
45 const std::string& sensor);
46
Matthew Barth048ac872017-03-09 14:36:08 -060047 /** @brief Write a hwmon sysfs value
48 *
49 * Calls exit(3) with bad status on failure
50 *
51 * @param[in] value - The value to be written
52 * @param[in] root - The hwmon class root.
53 * @param[in] instance - The hwmon instance (ex. hwmon1).
54 * @param[in] type - The hwmon type (ex. fan).
55 * @param[in] id - The hwmon id (ex. 1).
56 * @param[in] sensor - The hwmon sensor (ex. target).
57 *
58 * @returns - The value written
59 */
60uint64_t writeSysfsWithCallout(const uint64_t& value,
61 const std::string& root,
62 const std::string& instance,
63 const std::string& type,
64 const std::string& id,
65 const std::string& sensor);
66
Brad Bishop03476f12016-12-19 13:09:12 -050067// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4