| Alexander Hansen | 46a755f | 2025-10-27 16:31:08 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2017 Google Inc |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 3 | |
| Patrick Venture | cdd6134 | 2020-08-07 15:49:56 -0700 | [diff] [blame] | 4 | #include "build_utils.hpp" |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 5 | |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | |
| Patrick Venture | cdd6134 | 2020-08-07 15:49:56 -0700 | [diff] [blame] | 8 | namespace pid_control |
| 9 | { |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 10 | |
| 11 | static constexpr auto external_sensor = |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 12 | "/xyz/openbmc_project/extsensors/"; // type/ |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 13 | static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/ |
| 14 | static constexpr auto sysfs = "/sys/"; |
| 15 | |
| Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 16 | IOInterfaceType getWriteInterfaceType(const std::string& path) |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 17 | { |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 18 | if (path.empty() || "None" == path) |
| 19 | { |
| 20 | return IOInterfaceType::NONE; |
| 21 | } |
| 22 | |
| 23 | if (path.find(sysfs) != std::string::npos) |
| 24 | { |
| 25 | // A sysfs read sensor. |
| 26 | return IOInterfaceType::SYSFS; |
| 27 | } |
| 28 | |
| Patrick Venture | 081b035 | 2019-07-15 11:05:17 -0700 | [diff] [blame] | 29 | if (path.find(openbmc_sensor) != std::string::npos) |
| James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 30 | { |
| 31 | return IOInterfaceType::DBUSACTIVE; |
| 32 | } |
| 33 | |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 34 | return IOInterfaceType::UNKNOWN; |
| 35 | } |
| 36 | |
| Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 37 | IOInterfaceType getReadInterfaceType(const std::string& path) |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 38 | { |
| Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 39 | if (path.empty() || "None" == path) |
| 40 | { |
| 41 | return IOInterfaceType::NONE; |
| 42 | } |
| 43 | |
| 44 | if (path.find(external_sensor) != std::string::npos) |
| 45 | { |
| 46 | return IOInterfaceType::EXTERNAL; |
| 47 | } |
| 48 | |
| 49 | if (path.find(openbmc_sensor) != std::string::npos) |
| 50 | { |
| 51 | return IOInterfaceType::DBUSPASSIVE; |
| 52 | } |
| 53 | |
| 54 | if (path.find(sysfs) != std::string::npos) |
| 55 | { |
| 56 | return IOInterfaceType::SYSFS; |
| 57 | } |
| 58 | |
| 59 | return IOInterfaceType::UNKNOWN; |
| 60 | } |
| Patrick Venture | cdd6134 | 2020-08-07 15:49:56 -0700 | [diff] [blame] | 61 | |
| 62 | } // namespace pid_control |