Unlock progress UI:
- UnlockProgressDialog with dark-themed progress ring, phase indicator, elapsed
time, and cancel/close buttons (non-modal, draggable borderless window)
- UnlockProgressViewModel with event-driven progress tracking via IUnlockService
- Triggers on pump selection (manual or K-Line auto-detect), not test start
UnlockService rewrite:
- Persistent CAN senders that outlive the unlock sequence (StopSenders on pump change)
- Concurrent K-Line fast unlock: awaits session Connected, sends RAM timer shortcut
({02 88 02 03 A8 01 00}), verifies via CAN TestUnlock before skipping wait
- Fix Type 1 verification (Value == 0 means unlocked, was inverted)
K-Line fast unlock support:
- IKwpService.TryFastUnlockAsync / KwpService implementation
Additional features:
- ILocalizationService with ES/EN resource dictionaries and runtime switching
- Safety dialogs: VoltageWarning, OilPumpConfirm, RpmSafetyWarning
- SettingsDialog for app configuration
- BenchService enhancements, ConfigurationService improvements, PDF report updates
- All UI strings localized via DynamicResource
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
231 lines
11 KiB
C#
231 lines
11 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
|
|
|
|
// ── 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();
|
|
|
|
// ── 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
|
|
}
|
|
}
|