feat: page-based navigation shell + Tests page wizard

Replace the monolithic MainWindow with a SelectedPage-driven shell
(Dashboard / Pump / Bench / Tests / Results / Settings). The Tests
page gets the Plan -> Preconditions -> Running -> Done wizard from
ui-structure.md \u00a74, backed by a 7-item precondition gate and
shared sub-views (PhaseCardView / TestSectionView / GraphicIndicatorView)
extracted from the now-deleted monolithic TestPanelView.

New VMs / views:
- Tests wizard: TestPreconditions, PhaseCard, GraphicIndicator,
  TestSection, TestPlan, TestRunning, TestDone
- Dashboard panels: DashboardConnection, DashboardReadings,
  DashboardAlarms, InterlockBanner, ResultHistory
- Pump / bench panels: PumpIdentificationPanel, PumpLiveData,
  UnlockPanel, BenchDriveControl, BenchReadings, RelayBank,
  TemperatureControl, DtcList, AuthGate
- Dialogs: generic ConfirmDialog, UserManageDialog, UserPromptDialog

Supporting changes:
- IsOilPumpOn exposed on MainViewModel for precondition evaluation
- RequiresAuth added to TestDefinition (XML round-trip)
- BipStatusDefinition + CompletedTestRun models
- ~35 new Test.* localization keys (en + es)
- Settings moved from modal dialog to full page
- Pause / Retry / Skip stubs in TestRunningView; full spec in
  docs/gap-test-running-controls.md for follow-up implementation
- docs/ui-structure.md captures the wizard design

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-18 13:11:34 +02:00
parent 37d099cdbd
commit 0280a2fad1
110 changed files with 8008 additions and 1115 deletions

View File

@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
namespace HC_APTBS.Models
{
// BIP (Begin of Injection Period) status definitions.
// Applies only to pre-injection PSG5-PI pumps (Type 2 T15xxx / Type 3 T18xxx Ford).
// Null on standard VP44 pumps.
//
// Data model only in this revision: runtime polling of a BIP capture source
// (KWP RAM read of ADR-S_BIP_HW_UW / 0x0106, or a dedicated CAN frame) is not
// yet wired. PumpBipDefinition.Match(ushort) is the seam for future work.
/// <summary>
/// One BIP-STATUS entry: a 16-bit HEX pattern matched against the captured BIP
/// status word, together with the reaction to apply on a match.
/// </summary>
public class BipStatusDefinition
{
/// <summary>Whether this definition participates in pattern matching.</summary>
public bool Enabled { get; set; } = true;
/// <summary>
/// 16-bit nibble pattern compared against the captured BIP status word.
/// Legacy examples: 0x0000 = BIP OK, 0x000F = no BIP in window,
/// 0x00F0 = no BIP + MV off, 0x0F00 = no MV drive, 0xF00F = deviation too large.
/// </summary>
public ushort HexPattern { get; set; }
/// <summary>
/// Reaction code applied on match:
/// 0 = none, 1 = abort (emergency stop), 2 = warning, 3 = log-only.
/// </summary>
public int Reaction { get; set; } = 0;
/// <summary>
/// Special-function marker from legacy CFG:
/// 9 = standard handling, 0xB = Ford timing-correction (Type 3 only).
/// </summary>
public int SpecialFunction { get; set; } = 9;
/// <summary>Human-readable description shown on match.</summary>
public string Description { get; set; } = string.Empty;
}
/// <summary>
/// Per-pump BIP status container. Holds up to 8 <see cref="BipStatusDefinition"/>
/// entries (max by legacy convention; not validated).
/// </summary>
public class PumpBipDefinition
{
/// <summary>Ordered BIP status definitions (max 8).</summary>
public List<BipStatusDefinition> Bits { get; set; } = new();
/// <summary>
/// Returns the first enabled definition whose <see cref="BipStatusDefinition.HexPattern"/>
/// exactly equals <paramref name="value"/>, or null if none match.
/// </summary>
public BipStatusDefinition? Match(ushort value) =>
Bits.FirstOrDefault(b => b.Enabled && b.HexPattern == value);
}
}

View File

@@ -105,6 +105,19 @@ namespace HC_APTBS.Models
/// </summary>
public double Alpha { get; set; } = 1.0;
// ── Runtime-warning plumbing ──────────────────────────────────────────────
/// <summary>
/// Static logging hook invoked when <see cref="GetTransformResult"/> encounters
/// a zero denominator. Wired at app startup to <c>IAppLogger.Warning</c>.
/// Left null keeps the Models layer DI-free and testable.
/// Signature: (source, message).
/// </summary>
public static Action<string, string>? WarningLogger { get; set; }
/// <summary>Set once per instance after the first zero-denominator warning, to prevent hot-loop log spam.</summary>
private bool _warnedDenomZero;
// ── Convenience alias kept for cross-file compatibility ───────────────────
/// <summary>Alias for <see cref="MessageId"/> — used by legacy call sites.</summary>
@@ -144,16 +157,40 @@ namespace HC_APTBS.Models
/// <summary>
/// Applies the P1P6 rational transfer function to <see cref="Value"/>.
/// Used only by pump params (<see cref="UseLegacyTransform"/> = true).
/// Returns 0 and warns once if the denominator is zero.
/// </summary>
public double GetTransformResult()
{
if (IsReceive)
{
return (-P2 - P3 * P5 - P4 * P6 + P4 * Value)
/ (P1 + P3 * P5 + P3 * P6 - P3 * Value);
double denom = P1 + P3 * P5 + P3 * P6 - P3 * Value;
if (denom == 0.0)
{
if (!_warnedDenomZero)
{
WarningLogger?.Invoke(nameof(CanBusParameter),
$"Zero denominator for '{Name}' (receive). Returning 0.");
_warnedDenomZero = true;
}
return 0.0;
}
return (-P2 - P3 * P5 - P4 * P6 + P4 * Value) / denom;
}
return ((P1 * Value + P2) / (P3 * Value + P4)) + P5 + P6;
{
double denom = P3 * Value + P4;
if (denom == 0.0)
{
if (!_warnedDenomZero)
{
WarningLogger?.Invoke(nameof(CanBusParameter),
$"Zero denominator for '{Name}' (transmit). Returning 0.");
_warnedDenomZero = true;
}
return 0.0;
}
return ((P1 * Value + P2) / denom) + P5 + P6;
}
}
/// <summary>
@@ -185,13 +222,22 @@ namespace HC_APTBS.Models
/// </summary>
public static CanBusParameter FromXml(XElement xe)
{
string name = xe.Name.LocalName;
ushort byteh = ushort.Parse(xe.Attribute("byteh")?.Value ?? "0");
ushort bytel = ushort.Parse(xe.Attribute("bytel")?.Value ?? "0");
if (byteh > 7 || bytel > 7)
{
throw new ArgumentOutOfRangeException(nameof(xe),
$"Param '{name}': byteh={byteh} bytel={bytel} out of 0-7.");
}
var p = new CanBusParameter
{
Name = xe.Name.LocalName,
Name = name,
MessageId = uint.Parse(xe.Attribute("busid")?.Value ?? "0",
NumberStyles.HexNumber),
ByteH = ushort.Parse(xe.Attribute("byteh")?.Value ?? "0"),
ByteL = ushort.Parse(xe.Attribute("bytel")?.Value ?? "0"),
ByteH = byteh,
ByteL = bytel,
Type = int.Parse(xe.Attribute("type")?.Value ?? "0"),
IsReceive = !string.Equals(xe.Attribute("send")?.Value, "true",
StringComparison.OrdinalIgnoreCase),

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace HC_APTBS.Models
{
/// <summary>
/// Immutable snapshot of a completed test session captured at the moment
/// <see cref="Services.IBenchService.TestFinished"/> fires. Lives only for the
/// lifetime of the current app session — there is no cross-session storage.
///
/// <para>The <see cref="PumpSnapshot"/> is a deep copy of the pump's metadata and
/// <see cref="TestDefinition"/> list (including per-parameter results) so that
/// re-running a test on the same pump does not mutate prior history entries.
/// It can be handed directly to <see cref="Services.IPdfService.GenerateReport"/>
/// to reproduce the exact PDF for this run.</para>
/// </summary>
public sealed class CompletedTestRun
{
/// <summary>Unique identifier for the run — used as the key for per-entry delete.</summary>
public Guid Id { get; init; } = Guid.NewGuid();
/// <summary>Wall-clock time the <c>TestFinished</c> event fired.</summary>
public DateTime CompletedAt { get; init; }
/// <summary>Pump model string copied from the source pump at capture time.</summary>
public string PumpModel { get; init; } = string.Empty;
/// <summary>Pump serial number copied from the source pump at capture time.</summary>
public string PumpSerial { get; init; } = string.Empty;
/// <summary>True when every evaluated parameter in every enabled phase passed.</summary>
public bool OverallPassed { get; init; }
/// <summary>True when the run ended via abort / stop instead of normal completion.</summary>
public bool Interrupted { get; init; }
/// <summary>
/// Deep-cloned pump containing metadata + deep-cloned <see cref="TestDefinition"/>
/// list with results. Safe to hand directly to <see cref="Services.IPdfService"/>.
/// </summary>
public PumpDefinition PumpSnapshot { get; init; } = null!;
/// <summary>
/// Operator observations edited on the Results page. Mutable after capture,
/// persisted back from the <see cref="ViewModels.Dialogs.ReportViewModel"/>
/// when the operator exports a PDF.
/// </summary>
public string Observations { get; set; } = string.Empty;
/// <summary>
/// Space-separated list of test names in the snapshot (e.g. "WL · UP · PFP"),
/// shown as a secondary label in the history list.
/// </summary>
public string TestNames =>
PumpSnapshot?.Tests != null && PumpSnapshot.Tests.Count > 0
? string.Join(" \u00B7 ", PumpSnapshot.Tests.Select(t => t.Name))
: string.Empty;
}
}

View File

@@ -104,6 +104,15 @@ namespace HC_APTBS.Models
/// <summary>Ordered list of test procedures applicable to this pump model.</summary>
public List<TestDefinition> Tests { get; set; } = new();
// ── BIP (pre-injection only) ──────────────────────────────────────────────
/// <summary>
/// BIP (Begin of Injection Period) status definitions. Non-null only on
/// pre-injection PSG5-PI pumps (Type 2 T15xxx / Type 3 T18xxx Ford). Null on
/// standard VP44 pumps. See <see cref="PumpBipDefinition"/>.
/// </summary>
public PumpBipDefinition? BipStatus { get; set; }
// ── Runtime live values ────────────────────────────────────────────────────
/// <summary>Current fuel quantity feedback value (me) from the pump ECU.</summary>

View File

@@ -49,5 +49,12 @@ namespace HC_APTBS.Models
/// <summary>Human-readable description of this state.</summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// Reaction code applied when the owning status bit enters this state during
/// a test phase:
/// 0 = none, 1 = abort (emergency stop), 2 = warning, 3 = log-only.
/// </summary>
public int Reaction { get; set; } = 0;
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Xml.Linq;
namespace HC_APTBS.Models
@@ -41,18 +42,41 @@ namespace HC_APTBS.Models
/// <summary>Additive offset correction applied after the gain.</summary>
public double Offset { get; set; } = 0;
/// <summary>
/// Static logging hook used by runtime guards and <see cref="TryParse"/>.
/// Wired at app startup to <c>IAppLogger.Warning</c>. Left null keeps the
/// Models layer DI-free and testable. Signature: (source, message).
/// </summary>
public static Action<string, string>? WarningLogger { get; set; }
/// <summary>Set once per instance after the first zero-range warning, to prevent hot-loop log spam.</summary>
private bool _warnedRangeZero;
/// <summary>
/// Converts a raw CAN bus ADC count to a calibrated engineering-unit value.
/// Returns 0 and warns once if <c>MaxVolt == MinVolt</c>.
/// </summary>
/// <param name="rawCanBusValue">10-bit ADC count from the CAN frame.</param>
/// <returns>Calibrated value in engineering units.</returns>
public double GetValueFromRaw(double rawCanBusValue)
{
double range = MaxVolt - MinVolt;
if (range == 0.0)
{
if (!_warnedRangeZero)
{
WarningLogger?.Invoke(nameof(SensorConfiguration),
$"MaxVolt == MinVolt for sensor '{SensorName}' (channel {Number}). Returning 0.");
_warnedRangeZero = true;
}
return 0.0;
}
// Convert ADC counts → volts (10-bit ADC, 5 V reference)
double volts = rawCanBusValue * 5000.0 / 1024.0 / 1000.0;
// Map voltage range → engineering-unit range
double value = volts * ((MaxVal - MinVal) / (MaxVolt - MinVolt));
double value = volts * ((MaxVal - MinVal) / range);
return value * Gain + Offset;
}
@@ -73,17 +97,21 @@ namespace HC_APTBS.Models
public static SensorConfiguration FromXml(XElement element)
{
var sc = new SensorConfiguration();
TryParse(element.Attribute("num")?.Value, v => sc.Number = short.Parse(v));
TryParse(element.Attribute("name")?.Value, v => sc.SensorName = v);
TryParse(element.Element("Gain")?.Value, v => sc.Gain = double.Parse(v));
TryParse(element.Element("Offset")?.Value, v => sc.Offset = double.Parse(v));
TryParse(element.Element("MinVolt")?.Value, v => sc.MinVolt = double.Parse(v));
TryParse(element.Element("MaxVolt")?.Value, v => sc.MaxVolt = double.Parse(v));
TryParse(element.Element("MinVal")?.Value, v => sc.MinVal = double.Parse(v));
TryParse(element.Element("MaxVal")?.Value, v => sc.MaxVal = double.Parse(v));
TryParse(element.Attribute("num")?.Value, "num", v => sc.Number = short.Parse(v, CultureInfo.InvariantCulture));
TryParse(element.Attribute("name")?.Value, "name", v => sc.SensorName = v);
TryParse(element.Element("Gain")?.Value, "Gain", v => sc.Gain = ParseInvariant(v));
TryParse(element.Element("Offset")?.Value, "Offset", v => sc.Offset = ParseInvariant(v));
TryParse(element.Element("MinVolt")?.Value, "MinVolt", v => sc.MinVolt = ParseInvariant(v));
TryParse(element.Element("MaxVolt")?.Value, "MaxVolt", v => sc.MaxVolt = ParseInvariant(v));
TryParse(element.Element("MinVal")?.Value, "MinVal", v => sc.MinVal = ParseInvariant(v));
TryParse(element.Element("MaxVal")?.Value, "MaxVal", v => sc.MaxVal = ParseInvariant(v));
return sc;
}
/// <summary>Parses a decimal under <see cref="CultureInfo.InvariantCulture"/>, tolerating comma separators.</summary>
private static double ParseInvariant(string v)
=> double.Parse(v.Replace(',', '.'), CultureInfo.InvariantCulture);
/// <summary>Creates the default pressure sensor calibration for channel 1.</summary>
public static SensorConfiguration DefaultPressureSensor()
=> new SensorConfiguration
@@ -97,10 +125,15 @@ namespace HC_APTBS.Models
MaxVal = 20
};
private static void TryParse(string? value, Action<string> assign)
private static void TryParse(string? value, string fieldName, Action<string> assign)
{
if (!string.IsNullOrEmpty(value))
try { assign(value!); } catch { /* Ignore malformed XML values */ }
if (string.IsNullOrEmpty(value)) return;
try { assign(value!); }
catch (Exception ex)
{
WarningLogger?.Invoke(nameof(SensorConfiguration),
$"Skipped malformed '{fieldName}' value '{value}': {ex.Message}");
}
}
}
}

View File

@@ -57,6 +57,13 @@ namespace HC_APTBS.Models
/// <summary>Execution order index within the pump's test list.</summary>
public int Order { get; set; }
/// <summary>
/// When true, the Tests page preconditions step gates Start on operator authentication
/// (<see cref="HC_APTBS.ViewModels.AuthGateViewModel"/>) before this test may run.
/// Backwards-compatible: absent attribute in older pumps.xml files defaults to false.
/// </summary>
public bool RequiresAuth { get; set; } = false;
/// <summary>Phase definitions, executed sequentially.</summary>
public List<PhaseDefinition> Phases { get; set; } = new();
@@ -90,7 +97,8 @@ namespace HC_APTBS.Models
new XAttribute("Tacond", ConditioningTimeSec),
new XAttribute("Tmeasur", MeasurementTimeSec),
new XAttribute("MeasurePerSecond", MeasurementsPerSecond),
new XAttribute("orden", Order));
new XAttribute("orden", Order),
new XAttribute("requiresAuth", RequiresAuth));
foreach (var phase in Phases)
node.Add(phase.ToXml());
@@ -108,7 +116,8 @@ namespace HC_APTBS.Models
MeasurementTimeSec = int.Parse(element.Attribute("Tmeasur")!.Value),
MeasurementsPerSecond = double.Parse(
element.Attribute("MeasurePerSecond")!.Value, CultureInfo.InvariantCulture),
Order = int.Parse(element.Attribute("orden")!.Value)
Order = int.Parse(element.Attribute("orden")!.Value),
RequiresAuth = bool.TryParse(element.Attribute("requiresAuth")?.Value, out var req) && req
};
foreach (var phaseEl in element.Elements(XmlPhase))

24
Models/TestFlowState.cs Normal file
View File

@@ -0,0 +1,24 @@
namespace HC_APTBS.Models
{
/// <summary>
/// Sequential state of the Tests page wizard flow.
/// Advance is gated: Plan → Preconditions (when phases are enabled),
/// Preconditions → Running (when all required checks pass),
/// Running → Done (when the bench service reports the test finished).
/// Back navigation is allowed only between Plan and Preconditions.
/// </summary>
public enum TestFlowState
{
/// <summary>Operator selects tests and enables individual phases.</summary>
Plan,
/// <summary>Pre-run safety and readiness checklist; Start is hard-blocked until all green.</summary>
Preconditions,
/// <summary>Test is executing on the bench. Live phase timeline and measurements.</summary>
Running,
/// <summary>Test finished (complete or aborted). Summary and next-step actions.</summary>
Done
}
}