fix(v2c): use qBound for min/maxIntensity clamp in initialize()

qMin(32, m_maxIntensity) gives 0 when firmware returns 0 for MaxIntensity
(aberrant value).  maxIntensity()==0 then causes every setMaxChargingCurrent
call to be clamped to 0, falling into the <6 A path which pauses charging
silently — the user sees the action succeed but the charger stops.

qBound(6, val, 32) is correct in all cases:
  - firmware reports 16 A (mono Trydan) → 16 (real installation limit kept)
  - firmware reports 0 (aberrant)        →  6 (safe floor, does not claim 32 A)
  - firmware reports 65535 (aberrant)    → 32 (IEC absolute ceiling)

The real installation limit still comes from MaxIntensity read on the device;
the bounds [6, 32] are only IEC guardrails, not hardcoded defaults.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Patrick Schurig 2026-06-12 14:22:13 +02:00
parent 18655452d9
commit f0be2d00a2

View File

@ -58,9 +58,14 @@ bool TrydanModbusTcpMaster::initialize()
runReadSequence(buildInitSteps(), [this](bool ok) {
m_initializing = false;
if (ok) {
// Clamp to safe IEC 61851 bounds in case firmware reports unusual values.
m_minIntensity = qMax(6, m_minIntensity);
m_maxIntensity = qMin(32, m_maxIntensity);
// qBound to IEC 61851 absolute limits [6, 32]. The real installation
// ceiling comes from MaxIntensity read above (a 16 A mono Trydan reports
// 16, not 32). The lower guard (qMax 6 was wrong for aberrant 0 returns:
// qMin(32, 0)=0 → maxIntensity()==0 → every setpoint gets clamped to 0
// and then the <6 A path pauses charging silently). qBound floors to 6
// on a spurious 0 and caps to 32 on a spurious 65535.
m_minIntensity = qBound(6, m_minIntensity, 32);
m_maxIntensity = qBound(6, m_maxIntensity, 32);
}
emit initializationFinished(ok);
});