Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame^] | 3 | #include <filesystem> |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 4 | #include <vector> |
| 5 | |
| 6 | #ifdef I2C_OCC |
| 7 | |
| 8 | namespace i2c_occ |
| 9 | { |
| 10 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame^] | 11 | namespace fs = std::filesystem; |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 12 | |
| 13 | /** @brief Get file content |
| 14 | * |
| 15 | * Get at most NAME_LENGTH bytes of content from file. If the file is smaller |
| 16 | * than NAME_LENGTH bytes, return the valid parts. |
| 17 | * |
| 18 | * @param[in] f - The path of file |
| 19 | * |
| 20 | * @return The string of file content |
| 21 | */ |
| 22 | std::string getFileContent(const fs::path& f); |
| 23 | |
| 24 | /** @brief Find all devices of occ hwmon |
| 25 | * |
| 26 | * It iterates in path, finds all occ hwmon devices |
| 27 | * |
| 28 | * E.g. If "path/3-0050/name" exists and its content is "p8-occ-hwmon", |
| 29 | * "3-0050" is returned. |
| 30 | * |
| 31 | * @param[in] path - The path to search |
| 32 | * |
| 33 | * @return A vector of strings containing the occ hwmon device path |
Lei YU | 41470e5 | 2017-11-30 16:03:50 +0800 | [diff] [blame] | 34 | where the first device is master occ |
Lei YU | 0ab90ca | 2017-07-13 17:02:23 +0800 | [diff] [blame] | 35 | */ |
| 36 | std::vector<std::string> getOccHwmonDevices(const char* path); |
| 37 | |
| 38 | /** @brief Convert i2c name to DBus path |
| 39 | * |
| 40 | * It converts '-' to '_' so that it becomes a valid DBus path. |
| 41 | * E.g. 3-0050 converts to 3_0050 |
| 42 | * |
| 43 | * @param[in,out] path - The i2c name to convert |
| 44 | */ |
| 45 | void i2cToDbus(std::string& name); |
| 46 | |
| 47 | /** @brief Convert DBus path to i2c name |
| 48 | * |
| 49 | * It converts '_' to '_' so that it becomes a valid i2c name |
| 50 | * E.g. 3_0050 converts to 3-0050 |
| 51 | * |
| 52 | * @param[in,out] path - The DBus path to convert |
| 53 | */ |
| 54 | void dbusToI2c(std::string& path); |
| 55 | |
| 56 | /** @brief Get i2c name from full DBus path |
| 57 | * |
| 58 | * It extract the i2c name from the full DBus path. |
| 59 | * E.g. /org/open_power/control/3_0050 returns "3-0050" |
| 60 | * |
| 61 | * @param[in] dbusPath - The full DBus path |
| 62 | * |
| 63 | * @return The i2c name |
| 64 | */ |
| 65 | std::string getI2cDeviceName(const std::string& dbusPath); |
| 66 | |
| 67 | } // namespace i2c_occ |
| 68 | |
| 69 | #endif |