Files
HC_APTBS/Services/AutoTestState.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

118 lines
4.2 KiB
C#

namespace HC_APTBS.Services
{
/// <summary>
/// Phases of the Dashboard "Connect &amp; Auto Test" orchestration.
/// Drives the inline snackbar label and the orchestrator's internal branching.
/// </summary>
public enum AutoTestState
{
/// <summary>No auto-test sequence is active.</summary>
Idle = 0,
/// <summary>Pre-flight gate before any hardware action (e.g. operator confirmation).</summary>
Preflight,
/// <summary>Opening the K-Line session over FTDI.</summary>
ConnectingKLine,
/// <summary>Reading pump identification/DFI/serial over K-Line.</summary>
ReadingPump,
/// <summary>Running the immobilizer unlock (Ford VP44 Types 1 and 2).</summary>
Unlocking,
/// <summary>Energising the electronic relay and starting CAN senders.</summary>
TurningOnBench,
/// <summary>Energising the oil-pump relay.</summary>
StartingOilPump,
/// <summary>Kicking off <c>RunTestsAsync</c>.</summary>
StartingTest,
/// <summary>Test sequence executing; phase/sample updates from BenchService.</summary>
Running,
/// <summary>Sequence finished successfully.</summary>
Completed,
/// <summary>Sequence aborted; <see cref="AutoTestFailureReason"/> carries the cause.</summary>
Aborted,
}
/// <summary>
/// Reason an auto-test sequence aborted, for snackbar messaging and logging.
/// </summary>
public enum AutoTestFailureReason
{
/// <summary>No failure (default).</summary>
None = 0,
/// <summary>Operator cancelled from the snackbar or dismissed the pre-flight dialog.</summary>
UserCancelled,
/// <summary>CanExecute gate failed after click (alarm appeared between render and execute).</summary>
PreflightDenied,
/// <summary>FTDI port not found or <see cref="IKwpService.ConnectAsync"/> threw.</summary>
KLineConnectFailed,
/// <summary>K-Line session dropped to Failed state mid-sequence.</summary>
KLineLost,
/// <summary>Pump identification read failed (exception or result=0).</summary>
ReadFailed,
/// <summary>K-Line read completed but the pump ID is not in <c>pumps.xml</c>.</summary>
PumpNotRecognized,
/// <summary>Unlock sequence failed or verification returned locked.</summary>
UnlockFailed,
/// <summary>Bench CAN liveness dropped mid-sequence.</summary>
BenchCanLost,
/// <summary>Pump ECU CAN liveness dropped mid-sequence.</summary>
PumpCanLost,
/// <summary>A critical alarm bit transitioned to active during the sequence.</summary>
AlarmTriggered,
/// <summary>Operator has not enabled AutoTestSkipsOilPumpConfirm and the auto flow cannot proceed.</summary>
OilPumpNotConfirmed,
/// <summary>BenchService.RunTestsAsync signalled <c>interrupted=true</c>.</summary>
TestInterrupted,
/// <summary>BenchService.RunTestsAsync completed with <c>success=false</c>.</summary>
TestFailed,
/// <summary>Unexpected exception not covered by the categories above.</summary>
Unexpected,
}
/// <summary>Extension helpers for <see cref="AutoTestState"/>.</summary>
public static class AutoTestStateExtensions
{
/// <summary>
/// True for all intermediate phases (not Idle / Completed / Aborted).
/// Used by MainViewModel.CanAutoTest to block re-entry and to pick the button's
/// "Cancel" variant.
/// </summary>
public static bool IsRunning(this AutoTestState state) =>
state != AutoTestState.Idle &&
state != AutoTestState.Completed &&
state != AutoTestState.Aborted;
/// <summary>
/// True once the bench has been energised, i.e. after a failure the auto-flow
/// must request an emergency stop (not just disconnect).
/// </summary>
public static bool IsPastBenchOn(this AutoTestState state) =>
state == AutoTestState.TurningOnBench ||
state == AutoTestState.StartingOilPump ||
state == AutoTestState.StartingTest ||
state == AutoTestState.Running;
}
}