blob: 1b5efb8a5a0cea6219b0201af992de251ae6391e [file] [log] [blame]
Alexander Hansen46a755f2025-10-27 16:31:08 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2017 Google Inc
Patrick Venturee6206562018-03-08 15:36:53 -08003
Patrick Venturecdd61342020-08-07 15:49:56 -07004#include "build_utils.hpp"
Patrick Venturee6206562018-03-08 15:36:53 -08005
Ed Tanousf8b6e552025-06-27 13:27:50 -07006#include <string>
7
Patrick Venturecdd61342020-08-07 15:49:56 -07008namespace pid_control
9{
Patrick Venturee6206562018-03-08 15:36:53 -080010
11static constexpr auto external_sensor =
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070012 "/xyz/openbmc_project/extsensors/"; // type/
Patrick Venturee6206562018-03-08 15:36:53 -080013static constexpr auto openbmc_sensor = "/xyz/openbmc_project/"; // type/
14static constexpr auto sysfs = "/sys/";
15
Patrick Venture7af157b2018-10-30 11:24:40 -070016IOInterfaceType getWriteInterfaceType(const std::string& path)
Patrick Venturee6206562018-03-08 15:36:53 -080017{
Patrick Venturee6206562018-03-08 15:36:53 -080018 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 Venture081b0352019-07-15 11:05:17 -070029 if (path.find(openbmc_sensor) != std::string::npos)
James Feist7136a5a2018-07-19 09:52:05 -070030 {
31 return IOInterfaceType::DBUSACTIVE;
32 }
33
Patrick Venturee6206562018-03-08 15:36:53 -080034 return IOInterfaceType::UNKNOWN;
35}
36
Patrick Venture7af157b2018-10-30 11:24:40 -070037IOInterfaceType getReadInterfaceType(const std::string& path)
Patrick Venturee6206562018-03-08 15:36:53 -080038{
Patrick Venturee6206562018-03-08 15:36:53 -080039 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 Venturecdd61342020-08-07 15:49:56 -070061
62} // namespace pid_control