From f0be2d00a2c110c16065cbd96490fa9cb1ce1c62 Mon Sep 17 00:00:00 2001 From: Patrick Schurig Date: Fri, 12 Jun 2026 14:22:13 +0200 Subject: [PATCH] fix(v2c): use qBound for min/maxIntensity clamp in initialize() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- v2c/trydanmodbustcpmaster.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/v2c/trydanmodbustcpmaster.cpp b/v2c/trydanmodbustcpmaster.cpp index 9fbd9de..a324827 100644 --- a/v2c/trydanmodbustcpmaster.cpp +++ b/v2c/trydanmodbustcpmaster.cpp @@ -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); });