portduino Sensors: address review findings

- Read the command sensor after the INA219/260/3221, MAX17048 and RAK
  readers in getEnvironmentTelemetry(). Those ran after the sensors list
  and overwrote a configured voltage or current command.
- Drop a reading whose scaled value is not finite (value * Scale can
  overflow), so inf is never sent and never reaches an integer cast.
- A non-finite Scale (.inf, .nan) falls back to 1; --check warns.
- An empty `Sensors:` is skipped like any other empty section. A normal
  boot rejected it as "not a list" while --check called it clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011C7D9dE4aUYBrGdpPyHs25
This commit is contained in:
Claude committed 2026-11-02 20:54:37 +00:00
1 parent fc2fc97730
commit 2b85dbdbeb
9 files changed
+89 -18

No files matched your search

@@ -7,6 +7,7 @@
#include "PortduinoGlue.h"
#include "UptimeClock.h"
#include "mesh/Throttle.h"
#include <cmath>
// getMetrics() also runs for screen refreshes and phone requests; this keeps those from re-running every command.
static constexpr uint32_t COMMAND_SENSOR_CACHE_MS = 30 * 1000;
@@ -45,7 +46,12 @@ void CommandSensor::refresh(size_t index)
LOG_WARN("Sensor %s: command output is not a number: '%s'", sensor.type.c_str(), output.c_str());
return;
}
reading.value = value * sensor.scale;
const float scaled = value * sensor.scale;
if (!std::isfinite(scaled)) {
LOG_WARN("Sensor %s: %f scaled by %f is not a finite number", sensor.type.c_str(), value, sensor.scale);
return;
}
reading.value = scaled;
reading.valid = true;
LOG_DEBUG("Sensor %s: %f", sensor.type.c_str(), reading.value);
}