Brad Bishop | 26b815f | 2017-01-04 13:32:47 -0500 | [diff] [blame] | 1 | #pragma once |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 2 | |
| 3 | #include <fstream> |
| 4 | #include <string> |
| 5 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 6 | namespace sysfs { |
| 7 | |
Brad Bishop | a9b5f05 | 2017-01-17 14:50:08 -0500 | [diff] [blame] | 8 | inline std::string make_sysfs_path(const std::string& path, |
| 9 | const std::string& type, |
| 10 | const std::string& id, |
| 11 | const std::string& entry) |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 12 | { |
| 13 | using namespace std::literals; |
| 14 | |
| 15 | return path + "/"s + type + id + "_"s + entry; |
| 16 | } |
| 17 | |
Brad Bishop | 613a5b3 | 2017-01-05 20:58:13 -0500 | [diff] [blame] | 18 | |
| 19 | /** @brief Find hwmon instances |
| 20 | * |
| 21 | * Look for a matching hwmon instance given an |
| 22 | * open firmware device path. |
| 23 | * |
| 24 | * @param[in] ofNode- The open firmware device path. |
| 25 | * |
| 26 | * @returns[in] - The hwmon instance path or an empty |
| 27 | * string if no match is found. |
| 28 | */ |
| 29 | std::string findHwmon(const std::string& ofNode); |
| 30 | |
Brad Bishop | 4db6442 | 2017-02-16 11:33:32 -0500 | [diff] [blame] | 31 | /** @brief Read an hwmon sysfs value. |
| 32 | * |
| 33 | * Calls exit(3) with bad status on failure. |
| 34 | * |
| 35 | * @param[in] root - The hwmon class root. |
| 36 | * @param[in] instance - The hwmon instance (ex. hwmon1). |
| 37 | * @param[in] type - The hwmon type (ex. temp). |
| 38 | * @param[in] id - The hwmon id (ex. 1). |
| 39 | * @param[in] sensor - The hwmon sensor (ex. input). |
| 40 | * |
| 41 | * @returns - The read value. |
| 42 | */ |
| 43 | int readSysfsWithCallout(const std::string& root, |
| 44 | const std::string& instance, |
| 45 | const std::string& type, |
| 46 | const std::string& id, |
| 47 | const std::string& sensor); |
| 48 | |
Matthew Barth | 048ac87 | 2017-03-09 14:36:08 -0600 | [diff] [blame] | 49 | /** @brief Write a hwmon sysfs value |
| 50 | * |
| 51 | * Calls exit(3) with bad status on failure |
| 52 | * |
| 53 | * @param[in] value - The value to be written |
| 54 | * @param[in] root - The hwmon class root. |
| 55 | * @param[in] instance - The hwmon instance (ex. hwmon1). |
| 56 | * @param[in] type - The hwmon type (ex. fan). |
| 57 | * @param[in] id - The hwmon id (ex. 1). |
| 58 | * @param[in] sensor - The hwmon sensor (ex. target). |
| 59 | * |
| 60 | * @returns - The value written |
| 61 | */ |
| 62 | uint64_t writeSysfsWithCallout(const uint64_t& value, |
| 63 | const std::string& root, |
| 64 | const std::string& instance, |
| 65 | const std::string& type, |
| 66 | const std::string& id, |
| 67 | const std::string& sensor); |
| 68 | |
Patrick Venture | 1e6324f | 2017-06-01 14:07:05 -0700 | [diff] [blame^] | 69 | } |
| 70 | |
Brad Bishop | 03476f1 | 2016-12-19 13:09:12 -0500 | [diff] [blame] | 71 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |