PSUSensor.cpp - Removed PSU
Mark Woodward
woodwardm at google.com
Wed Jan 29 07:02:11 AEDT 2025
Here is a diff
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index e454c74..4072e07 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -133,6 +133,31 @@ void PSUSensor::deactivate()
i2cDevice = nullptr;
path = "";
}
+bool PSUSensor::readStatusClearValue(bool success)
+{
+ bool result = false;
+ if(success)
+ {
+ lastClear = 0;
+ }
+ else
+ {
+ unsigned int now = (unsigned int) time(0);
+ if(lastClear == 0)
+ {
+ lastClear = now;
+ }
+ else
+ {
+ if((now - lastClear) > timeout_before_clear)
+ {
+ result = true;
+ lastClear = 0;
+ }
+ }
+ }
+ return result;
+}
void PSUSensor::setupRead(void)
{
@@ -214,12 +239,19 @@ void PSUSensor::handleResponse(const
boost::system::error_code& err,
{
if (readingStateGood())
{
- std::cerr << name << " read failed\n";
+ std::cerr << name << " read failed:" << err << "\n";
+ if(readStatusClearValue(false))
+ {
+ std::cerr << name << " clearing value" << "\n";
+ updateValue(0 + sensorOffset);
+ }
}
restartRead();
return;
}
+ readStatusClearValue(true);
+
// null terminate the string so we don't walk off the end
std::array<char, 128>& bufferRef = *buffer;
bufferRef[bytesRead] = '\0';
diff --git a/src/PSUSensor.hpp b/src/PSUSensor.hpp
index b49235f..a7ee95d 100644
--- a/src/PSUSensor.hpp
+++ b/src/PSUSensor.hpp
@@ -61,6 +61,16 @@ class PSUSensor : public Sensor, public
std::enable_shared_from_this<PSUSensor>
static constexpr size_t warnAfterErrorCount = 10;
+ // Wait timeout_before_clear (5 minutes)
+ static constexpr unsigned int timeout_before_clear = 300;
+
+ // Time of last clear
+ unsigned int lastClear;
+
+ // Pass true if read was successful, else pass false
+ // If the value returned is true, clear the value
+ bool readStatusClearValue(bool success);
+
public:
static constexpr double defaultSensorPoll = 1.0;
static constexpr unsigned int defaultSensorPollMs =
On Mon, Jan 27, 2025 at 3:43 PM Mark Woodward <woodwardm at google.com> wrote:
> We are having an issue with psusensor in that when it is functioning with
> or without power, psusensor can read the status of the PSU. If the PSU is
> removed, the status of the PSU is never updated.
>
> It looks like in void PSUSensor::handleResponse() when there is a read
> error an error log string is output, restartRead () is called, but there is
> nothing done to the sensor data. This means that when a PSU is removed,
> aside from the log entry, there is no change to the sensor readings. It
> will just continue to report the last readings.
>
> Is a PoC, I added "updateValue(0 + sensorOffset);" in the error stanza, so
> that when the PSU is removed, the values are cleared.
>
> Is this expected behavior?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20250128/deed85b9/attachment.htm>
More information about the openbmc
mailing list