| 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 | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 3 | |
| 4 | #include "pluggable.hpp" |
| 5 | |
| Potin Lai | e1fa859 | 2025-08-29 15:27:08 +0800 | [diff] [blame] | 6 | #include "hoststatemonitor.hpp" |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 7 | #include "interfaces.hpp" |
| 8 | |
| 9 | #include <cstdint> |
| 10 | #include <string> |
| 11 | |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 12 | namespace pid_control |
| 13 | { |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 14 | |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 15 | ReadReturn PluggableSensor::read(void) |
| 16 | { |
| 17 | return _reader->read(); |
| 18 | } |
| 19 | |
| 20 | void PluggableSensor::write(double value) |
| 21 | { |
| 22 | _writer->write(value); |
| 23 | } |
| James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 24 | |
| Josh Lehan | 2400ce4 | 2020-10-01 01:50:39 -0700 | [diff] [blame] | 25 | void PluggableSensor::write(double value, bool force, int64_t* written) |
| 26 | { |
| 27 | _writer->write(value, force, written); |
| 28 | } |
| 29 | |
| James Feist | 36b7d8e | 2018-10-05 15:39:01 -0700 | [diff] [blame] | 30 | bool PluggableSensor::getFailed(void) |
| 31 | { |
| Potin Lai | e1fa859 | 2025-08-29 15:27:08 +0800 | [diff] [blame] | 32 | bool isFailed = _reader->getFailed(); |
| 33 | |
| 34 | if (isFailed && getIgnoreFailIfHostOff()) |
| 35 | { |
| 36 | auto& hostState = HostStateMonitor::getInstance(); |
| 37 | if (!hostState.isPowerOn()) |
| 38 | { |
| 39 | return false; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return isFailed; |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| Harvey Wu | a427007 | 2024-05-29 16:11:13 +0800 | [diff] [blame] | 46 | std::string PluggableSensor::getFailReason(void) |
| 47 | { |
| 48 | return _reader->getFailReason(); |
| 49 | } |
| 50 | |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 51 | } // namespace pid_control |