Restore the full bench control panel from the old source with MVVM architecture: - Two-column left panel layout: bench info displays (RPM with target/voltage, temps, pressures, Q-flow, pump live values) and user commands (direction toggle, start/stop with RPM popup and quick-select buttons, oil pump toggle, turn downcounter with CAN send) - PID RPM ramp controller (BenchPidController) with bumpless startup, anti-windup, and derivative-on-measurement for smooth motor speed transitions - Real-time flowmeter charts (LiveChartsCore) for Q-Delivery and Q-Over with tolerance band overlays - Bench/pump CAN liveness detection in PcanAdapter (receive-only IDs) - K-Line connection status indicator (placeholder) - Periodic relay bitmask sender (~21ms) and ElectronicMsg keepalive start on CAN connect, pump sender starts immediately on pump load Fix critical CAN message ID bug: default bench XML values were incorrectly converted from old source (decimal-notation hex parsed as actual hex digits, e.g. "10" -> "A" instead of keeping "10" which parses as 0x10). Corrected all IDs to match hardware: 0x10, 0x11, 0x13, 0x14, 0x15, 0x50, 0x51, 0x55. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
218 lines
11 KiB
C#
218 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
|
|
|
|
// ── 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
|
|
}
|
|
}
|