Files
HC_APTBS/Models/PumpDefinition.cs
LucianoDev 827b811b39 feat: developer tools page, auto-test orchestrator, BIP display, tests redesign
Bundles several feature streams that have been iterating on the working tree:

- Developer Tools page (Debug-only via DEVELOPER_TOOLS symbol): hosts the
  identification card, manual KWP write + transaction log, ROM/EEPROM dump
  card with progress banner and completion message, persisted custom-commands
  library, persisted EEPROM passwords library. New service primitives:
  IKwpService.SendRawCustomAsync / ReadEepromAsync / ReadRomEepromAsync.
  Persistence mirrors the Clients XML pattern in two new files
  (custom_commands.xml, eeprom_passwords.xml).
- Auto-test orchestrator (IAutoTestOrchestrator + AutoTestState): linear
  K-Line read -> unlock -> bench-on -> test sequence with snackbar UI and
  progress dialog VM, gated on dashboard alarms.
- BIP-STATUS display: BipDisplayViewModel + BipDisplayView, RAM read at
  0x0106 via IKwpService.ReadBipStatusAsync; status definitions in
  BipStatusDefinition.
- Tests page redesign: TestSectionCard + PhaseTileView replacing the old
  TestPlanView/TestRunningView/TestDoneView/TestPreconditionsView/
  TestSectionView controls and their VMs.
- Pump command sliders: Fluent thick-track style with overhang thumb,
  click-anywhere-and-drag, mouse-wheel adjustment.
- Window startup: app.manifest declares PerMonitorV2 DPI awareness,
  MainWindow installs a WM_GETMINMAXINFO hook in OnSourceInitialized and
  maximizes there (after the hook is in place) so the app fits the work
  area exactly on any display configuration.
- Misc: PercentToPixelsConverter, seed_aliases.py one-shot pump-alias
  importer, tools/Import-BipStatus.ps1, kline_eeprom_spec.md and
  dump-functions reference docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-07 13:59:50 +02:00

184 lines
8.9 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;
/// <summary>
/// Alternative K-Line pump-IDs that should resolve to this canonical pump.
/// Used when the ECU reports a Bosch number (e.g. 1093423001) that differs from
/// this pump's canonical <see cref="Id"/> (e.g. 0470504027). Loaded from the
/// per-pump <c>&lt;Aliases&gt;&lt;KlineId&gt;</c> entries in <c>pumps.xml</c>.
/// </summary>
public List<string> KlineAliases { get; set; } = new();
/// <summary>
/// Alternative <c>ModelReference</c> strings (12-char ECU prefix, e.g. ME190297C150)
/// that should resolve to this canonical pump. Loaded from the per-pump
/// <c>&lt;Aliases&gt;&lt;ModelRef&gt;</c> entries in <c>pumps.xml</c>.
/// </summary>
public List<string> ModelRefAliases { get; set; } = new();
// ── 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();
}
}
}