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

254 lines
13 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using HC_APTBS.Models;
namespace HC_APTBS.Services
{
/// <summary>
/// Orchestrates the test bench: relay control, temperature PID, RPM control,
/// and test sequence execution.
/// </summary>
public interface IBenchService
{
// ── Events ────────────────────────────────────────────────────────────────
/// <summary>Raised when a test sequence starts.</summary>
event Action? TestStarted;
/// <summary>
/// Raised when a test sequence completes (normally or via stop).
/// <c>interrupted</c> is true if stopped early; <c>success</c> is the overall pass/fail result.
/// </summary>
event Action<bool , bool >? TestFinished; //interrupted,success
/// <summary>Raised at each phase transition with the phase name.</summary>
event Action<string >? PhaseChanged; //phaseName
/// <summary>Raised with verbose status text during test execution (e.g. "Conditioning… 45s").</summary>
event Action<string >? VerboseMessage; //message
/// <summary>Raised when a PSG sync-pulse error halts a SVME test.</summary>
event Action? PsgSyncError;
/// <summary>
/// Raised after a phase finishes with its name and pass/fail result.
/// </summary>
event Action<string , bool >? PhaseCompleted; // phaseName,passed
/// <summary>
/// Raised when a safety check triggers an emergency stop. The bench motor
/// and pump parameters are already stopped when this fires.
/// Fires on a background thread — consumers must marshal to the UI thread.
/// </summary>
event Action<string >? EmergencyStopTriggered; //reason
/// <summary>
/// Raised on a 0→1 transition to a pump-status state whose
/// <see cref="StatusBitValue.Reaction"/> is non-zero during a measurement phase.
/// Args: (bit, reaction, description) where reaction is 1=abort, 2=warning, 3=log.
/// Fires on a background thread — consumers must marshal to the UI thread.
/// </summary>
event Action<int, int, string>? StatusReactionTriggered; //bit, reaction, description
// ── Active pump ───────────────────────────────────────────────────────────
/// <summary>
/// Registers the currently selected pump so that pump-specific CAN parameters
/// (me, FBKW, mepi, RPM, Temp, Tein, Status, Empf3) can be read and written
/// through <see cref="ReadParameter"/> and <see cref="SetParameter"/>.
/// </summary>
void SetActivePump(PumpDefinition? pump);
// ── Bench parameter access ────────────────────────────────────────────────
/// <summary>
/// Returns the current live value of a bench parameter by name.
/// </summary>
/// <param name="parameterName">Bench parameter name (see <see cref="BenchParameterNames"/>).</param>
double ReadBenchParameter(string parameterName);
/// <summary>
/// Returns the current live value of a pump parameter by name.
/// </summary>
/// <param name="parameterName">Pump parameter name (see <see cref="PumpParameterNames"/>).</param>
double ReadPumpParameter(string parameterName);
/// <summary>
/// Returns the current live value of a parameter by name.
/// Looks in the active pump's parameters first, then falls back to bench parameters.
/// Use <see cref="ReadBenchParameter"/> or <see cref="ReadPumpParameter"/> when the source is known.
/// </summary>
/// <param name="parameterName">Parameter name (see <see cref="BenchParameterNames"/> / <see cref="PumpParameterNames"/>).</param>
double ReadParameter(string parameterName);
/// <summary>Sets a pump/bench parameter value in the local parameter map.</summary>
/// <param name="parameterName">Parameter name.</param>
/// <param name="value">New value in engineering units.</param>
void SetParameter(string parameterName, double value);
/// <summary>Flushes all pending parameter changes to the CAN bus.</summary>
/// <param name="messageId">CAN message ID to transmit.</param>
void SendParameters(uint messageId);
// ── Pump control sender ───────────────────────────────────────────────────
/// <summary>
/// Sets the target value for a pump control parameter (me, FBKW, mepi).
/// FBKW is written immediately; ME and PreIn are slew-rate filtered by the periodic sender.
/// </summary>
void SetPumpControlValue(string parameterName, double targetValue);
/// <summary>Starts the periodic CAN sender that transmits pump control parameters.</summary>
void StartPumpSender();
/// <summary>Stops the periodic pump control CAN sender.</summary>
void StopPumpSender();
/// <summary>Starts the periodic MemoryRequest sender that polls the pump ECU for Tein data.</summary>
void StartMemoryRequestSender();
/// <summary>Stops the periodic MemoryRequest sender.</summary>
void StopMemoryRequestSender();
/// <summary>Starts the periodic ElectronicMsg keepalive sender (1-second interval).</summary>
void StartElectronicMsgSender();
/// <summary>Stops the periodic ElectronicMsg keepalive sender.</summary>
void StopElectronicMsgSender();
/// <summary>
/// Raised when a pump control value is set (e.g. during test execution),
/// so the ViewModel can update slider positions. Arguments: parameterName, value.
/// </summary>
event Action<string, double>? PumpControlValueSet;
// ── RPM control ───────────────────────────────────────────────────────────
/// <summary>
/// Commands the bench motor to the specified RPM by computing and applying
/// the corresponding voltage from the RPM-to-voltage lookup table.
/// Used by automated test execution for direct voltage jumps.
/// </summary>
void SetRpm(double rpm);
/// <summary>
/// Starts the PID-based RPM ramp controller to smoothly reach the target RPM.
/// Sends an initial voltage jump from the RPM-voltage lookup table, then hands
/// control to the PID loop after an approach delay.
/// Used for interactive (manual) bench control.
/// </summary>
/// <param name="targetRpm">Desired RPM setpoint.</param>
void StartRpmPid(double targetRpm);
/// <summary>
/// Stops the PID RPM controller, sends 0 V to the motor.
/// </summary>
void StopRpmPid();
/// <summary>The last RPM target that was commanded via <see cref="SetRpm"/> or <see cref="StartRpmPid"/>.</summary>
double LastTargetRpm { get; }
/// <summary>The last voltage value sent to the motor CAN parameter.</summary>
double LastCommandVoltage { get; }
/// <summary>Raised after a voltage command is sent to the motor (from <see cref="SetRpm"/> or the PID loop).</summary>
event Action? RpmCommandSent;
// ── Temperature control ───────────────────────────────────────────────────
/// <summary>
/// Sets the temperature PID setpoint.
/// </summary>
/// <param name="setpointCelsius">Target temperature in °C.</param>
/// <param name="toleranceCelsius">Acceptable deviation in °C.</param>
/// <returns>
/// True if the temperature check should be ignored (e.g. sensor fault or
/// the DefaultIgnoreTin setting is active).
/// </returns>
bool SetTemperatureSetpoint(double setpointCelsius, double toleranceCelsius);
// ── Relay control ─────────────────────────────────────────────────────────
/// <summary>Energises or de-energises the named relay.</summary>
/// <param name="relayName">Relay name (see <see cref="RelayNames"/>).</param>
/// <param name="state">True = ON, false = OFF.</param>
void SetRelay(string relayName, bool state);
/// <summary>
/// Transmits the current relay bitmask once. Called on CAN connect so the
/// bench controller receives the initial relay state immediately.
/// </summary>
void SendInitialRelayState();
/// <summary>Starts the periodic relay bitmask sender (~21 ms cycle).</summary>
void StartRelaySender();
/// <summary>Stops the periodic relay bitmask sender.</summary>
void StopRelaySender();
// ── Test execution ────────────────────────────────────────────────────────
/// <summary>
/// Starts the full test sequence for the given pump in a background task.
/// </summary>
/// <param name="pump">Pump definition containing tests and CAN parameters.</param>
/// <param name="ct">Cancellation token — cancel to trigger a controlled stop.</param>
Task RunTestsAsync(PumpDefinition pump, CancellationToken ct);
/// <summary>Requests a controlled stop of the currently running test sequence.</summary>
void StopTests();
/// <summary>
/// Immediately triggers an emergency stop: zeros RPM, zeros pump parameters,
/// cancels any running test, and fires <see cref="EmergencyStopTriggered"/>.
/// Intended for operator-initiated E-Stop from the Dashboard.
/// </summary>
/// <param name="reason">Human-readable reason logged and propagated to the event.</param>
void RequestEmergencyStop(string reason);
// ── Lock angle ────────────────────────────────────────────────────────────
/// <summary>
/// Raised during test execution to signal that the Lock Angle measurement phase
/// is ready. The ViewModel should display the lock angle acquisition UI.
/// </summary>
event Action? LockAngleFaseReady;
/// <summary>
/// Raised when the PSG encoder synchronisation phase begins.
/// </summary>
event Action? PsgModeFaseReady;
// ── DFI auto-adjust ───────────────────────────────────────────────────────
/// <summary>Returns true if auto-DFI adjustment is currently enabled by the operator.</summary>
bool IsAutoDfiEnabled { get; }
/// <summary>
/// Writes a new DFI value to the pump ECU as part of the auto-adjust loop.
/// </summary>
void SetDfi(double dfi);
// ── Tolerance display ─────────────────────────────────────────────────────
/// <summary>
/// Raised so the chart view can draw tolerance bands for the specified parameter.
/// </summary>
event Action<string , double , double >? ToleranceUpdated; //parameterName, value, tolerance
/// <summary>
/// Raised for each individual measurement sample collected during a test phase.
/// Fires on a background thread — consumers must marshal to the UI thread.
/// </summary>
event Action<string , double >? MeasurementSampled; //parameterName, value
/// <summary>
/// Fires once per second during a phase's conditioning and measurement sub-sections.
/// Args: (section, remainingSeconds, totalSeconds) where section is "Conditioning" or "Measuring".
/// Fires on a background thread — consumers must marshal to the UI thread.
/// </summary>
event Action<string, int, int>? PhaseTimerTick;
}
}