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