blob: 04e8d0574c19b9e12d2f810c0563d9770616e0ca [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001/**
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 Venturecdd61342020-08-07 15:49:56 -070017#include "build_utils.hpp"
Patrick Venturee6206562018-03-08 15:36:53 -080018
Ed Tanousf8b6e552025-06-27 13:27:50 -070019#include <string>
20
Patrick Venturecdd61342020-08-07 15:49:56 -070021namespace pid_control
22{
Patrick Venturee6206562018-03-08 15:36:53 -080023
24static constexpr auto external_sensor =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 "/xyz/openbmc_project/extsensors/"; // type/
Patrick Venturee6206562018-03-08 15:36:53 -080026static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
27static constexpr auto sysfs = "/sys/";
28
Patrick Venture7af157b2018-10-30 11:24:40 -070029IOInterfaceType getWriteInterfaceType(const std::string& path)
Patrick Venturee6206562018-03-08 15:36:53 -080030{
Patrick Venturee6206562018-03-08 15:36:53 -080031 if (path.empty() || "None" == path)
32 {
33 return IOInterfaceType::NONE;
34 }
35
36 if (path.find(sysfs) != std::string::npos)
37 {
38 // A sysfs read sensor.
39 return IOInterfaceType::SYSFS;
40 }
41
Patrick Venture081b0352019-07-15 11:05:17 -070042 if (path.find(openbmc_sensor) != std::string::npos)
James Feist7136a5a2018-07-19 09:52:05 -070043 {
44 return IOInterfaceType::DBUSACTIVE;
45 }
46
Patrick Venturee6206562018-03-08 15:36:53 -080047 return IOInterfaceType::UNKNOWN;
48}
49
Patrick Venture7af157b2018-10-30 11:24:40 -070050IOInterfaceType getReadInterfaceType(const std::string& path)
Patrick Venturee6206562018-03-08 15:36:53 -080051{
Patrick Venturee6206562018-03-08 15:36:53 -080052 if (path.empty() || "None" == path)
53 {
54 return IOInterfaceType::NONE;
55 }
56
57 if (path.find(external_sensor) != std::string::npos)
58 {
59 return IOInterfaceType::EXTERNAL;
60 }
61
62 if (path.find(openbmc_sensor) != std::string::npos)
63 {
64 return IOInterfaceType::DBUSPASSIVE;
65 }
66
67 if (path.find(sysfs) != std::string::npos)
68 {
69 return IOInterfaceType::SYSFS;
70 }
71
72 return IOInterfaceType::UNKNOWN;
73}
Patrick Venturecdd61342020-08-07 15:49:56 -070074
75} // namespace pid_control