Files
HC_APTBS/Models/PumpDefinition.cs
LucianoDev 0280a2fad1 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>
2026-04-18 13:11:34 +02:00

169 lines
8.1 KiB
C#

using System.Collections.Generic;
using Peak.Can.Basic;
using TPCANHandle = System.UInt16;
namespace HC_APTBS.Models
{
/// <summary>
/// Describes a diesel injection pump model supported by the test bench.
/// This is the configuration-time definition loaded from the pump database.
/// Runtime state (current RPM, temperature, test progress) lives in the ViewModel.
/// </summary>
public class PumpDefinition
{
// ── Identity ──────────────────────────────────────────────────────────────
/// <summary>Pump identifier code (e.g. "VP44-0460424", loaded from K-Line EEPROM).</summary>
public string Id { get; set; } = string.Empty;
/// <summary>Pump model name shown in the UI.</summary>
public string Model { get; set; } = string.Empty;
/// <summary>Serial number stamped on the pump body.</summary>
public string SerialNumber { get; set; } = string.Empty;
/// <summary>Injector nozzle specification string (parsed from ECU text).</summary>
public string Injector { get; set; } = string.Empty;
/// <summary>High-pressure tube specification.</summary>
public string Tube { get; set; } = string.Empty;
/// <summary>Solenoid valve specification.</summary>
public string Valve { get; set; } = string.Empty;
/// <summary>Electrical supply tension.</summary>
public string Tension { get; set; } = string.Empty;
/// <summary>Free-text info line from the pump database.</summary>
public string Info { get; set; } = string.Empty;
/// <summary>Raw ECU text returned by ReadEcuInfo over K-Line.</summary>
public string EcuText { get; set; } = string.Empty;
/// <summary>Lock-angle (shaft timing reference) in degrees.</summary>
public string Chaveta { get; set; } = string.Empty;
// ── Physical parameters ───────────────────────────────────────────────────
/// <summary>
/// Injection timing lock angle (degrees) used during the Lock Angle test phase.
/// </summary>
public double LockAngle { get; set; }
/// <summary>Measured lock angle result, populated after the Lock Angle phase completes.</summary>
public double LockAngleResult { get; set; }
/// <summary>True if this pump model has a pilot/pre-injection solenoid.</summary>
public bool HasPreInjection { get; set; }
/// <summary>True for 4-cylinder pump configurations; false for 6-cylinder.</summary>
public bool Is4Cylinder { get; set; } = true;
/// <summary>Unlock protocol variant (0 = none, 1 = type 1, 2 = type 2).</summary>
public int UnlockType { get; set; }
/// <summary>
/// Pump shaft rotation direction.
/// See <see cref="RotationDirection.LeftName"/> and <see cref="RotationDirection.RightName"/>.
/// </summary>
public string Rotation { get; set; } = RotationDirection.RightName;
// ── CAN configuration ─────────────────────────────────────────────────────
/// <summary>PCAN channel handle used to communicate with this pump.</summary>
public TPCANHandle CanChannel { get; set; } = PCANBasic.PCAN_USBBUS1;
/// <summary>CAN baudrate for this pump (most VP44 units use 500 kbps).</summary>
public TPCANBaudrate CanBaudrate { get; set; } = TPCANBaudrate.PCAN_BAUD_500K;
/// <summary>
/// Parameters specific to this pump, keyed by name for quick lookup.
/// These are separate from the bench parameters.
/// </summary>
public Dictionary<string, CanBusParameter> ParametersByName { get; set; } = new();
/// <summary>Pump CAN parameters grouped by message ID for frame decoding.</summary>
public Dictionary<uint, List<CanBusParameter>> ParametersById { get; set; } = new();
// ── K-Line data ───────────────────────────────────────────────────────────
/// <summary>
/// K-Line / KWP2000 data read from the pump ECU EEPROM.
/// Keys match <see cref="KlineKeys"/> constants.
/// </summary>
public Dictionary<string, string> KlineInfo { get; set; } = new();
/// <summary>
/// Pump hardware version used to select the correct KWP protocol variant.
/// 0 = V1 original, 1 = V2, 2 = V3/V4.
/// </summary>
public int KwpVersion { get; set; }
// ── Tests ─────────────────────────────────────────────────────────────────
/// <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>
public double ValueMe { get; set; }
/// <summary>Current FBKW (Füllungsbeiwert / fill factor) value from the pump ECU.</summary>
public double ValueFbkw { get; set; }
/// <summary>Current pre-injection quantity value from the pump ECU.</summary>
public double ValuePreIn { get; set; }
// ── Test helpers ──────────────────────────────────────────────────────────
/// <summary>
/// Merges phases from a WL-type test into the first F-type test in the list,
/// then renames it to WL. This matches the legacy pump database convention
/// where WL extends the base F test with warm-up phases.
/// </summary>
internal void CombineTestWL(TestDefinition wlTest)
{
foreach (var existing in Tests)
{
if (existing.Name == TestType.F)
{
existing.Phases.AddRange(wlTest.Phases);
existing.Name = TestType.Wl;
return;
}
}
}
// ── Helpers ───────────────────────────────────────────────────────────────
/// <summary>
/// Parses the injector, tube, valve, and tension fields from the raw ECU text string.
/// The ECU text format is: "(injector) tube valve tension"
/// </summary>
public void ParseEcuText()
{
if (string.IsNullOrEmpty(EcuText)) return;
int closeParenPos = EcuText.IndexOf(')') + 1;
Injector = EcuText[..closeParenPos].Trim();
var rest = EcuText[closeParenPos..];
var parts = rest.Split(new[] { " " }, System.StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 0) Tube = parts[0].Trim();
if (parts.Length > 1) Valve = parts[1].Trim();
if (parts.Length > 2) Tension = parts[2].Trim();
}
}
}