Files
HC_APTBS/Services/IBenchService.cs
2026-04-11 12:45:18 +02:00

182 lines
9.2 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.
/// </summary>
void SetRpm(double rpm);
// ── 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);
// ── 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
}
}