Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Patrick Venture | cdd6134 | 2020-08-07 15:49:56 -0700 | [diff] [blame] | 17 | #include "build_utils.hpp" |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 18 | |
Patrick Venture | cdd6134 | 2020-08-07 15:49:56 -0700 | [diff] [blame] | 19 | namespace pid_control |
| 20 | { |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 21 | |
| 22 | static constexpr auto external_sensor = |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 23 | "/xyz/openbmc_project/extsensors/"; // type/ |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 24 | static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/ |
| 25 | static constexpr auto sysfs = "/sys/"; |
| 26 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 27 | IOInterfaceType getWriteInterfaceType(const std::string& path) |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 28 | { |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 29 | if (path.empty() || "None" == path) |
| 30 | { |
| 31 | return IOInterfaceType::NONE; |
| 32 | } |
| 33 | |
| 34 | if (path.find(sysfs) != std::string::npos) |
| 35 | { |
| 36 | // A sysfs read sensor. |
| 37 | return IOInterfaceType::SYSFS; |
| 38 | } |
| 39 | |
Patrick Venture | 081b035 | 2019-07-15 11:05:17 -0700 | [diff] [blame] | 40 | if (path.find(openbmc_sensor) != std::string::npos) |
James Feist | 7136a5a | 2018-07-19 09:52:05 -0700 | [diff] [blame] | 41 | { |
| 42 | return IOInterfaceType::DBUSACTIVE; |
| 43 | } |
| 44 | |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 45 | return IOInterfaceType::UNKNOWN; |
| 46 | } |
| 47 | |
Patrick Venture | 7af157b | 2018-10-30 11:24:40 -0700 | [diff] [blame] | 48 | IOInterfaceType getReadInterfaceType(const std::string& path) |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 49 | { |
Patrick Venture | e620656 | 2018-03-08 15:36:53 -0800 | [diff] [blame] | 50 | if (path.empty() || "None" == path) |
| 51 | { |
| 52 | return IOInterfaceType::NONE; |
| 53 | } |
| 54 | |
| 55 | if (path.find(external_sensor) != std::string::npos) |
| 56 | { |
| 57 | return IOInterfaceType::EXTERNAL; |
| 58 | } |
| 59 | |
| 60 | if (path.find(openbmc_sensor) != std::string::npos) |
| 61 | { |
| 62 | return IOInterfaceType::DBUSPASSIVE; |
| 63 | } |
| 64 | |
| 65 | if (path.find(sysfs) != std::string::npos) |
| 66 | { |
| 67 | return IOInterfaceType::SYSFS; |
| 68 | } |
| 69 | |
| 70 | return IOInterfaceType::UNKNOWN; |
| 71 | } |
Patrick Venture | cdd6134 | 2020-08-07 15:49:56 -0700 | [diff] [blame] | 72 | |
| 73 | } // namespace pid_control |