Files
HC_APTBS/Models/BenchConfiguration.cs
LucianoDev 827b811b39 feat: developer tools page, auto-test orchestrator, BIP display, tests redesign
Bundles several feature streams that have been iterating on the working tree:

- Developer Tools page (Debug-only via DEVELOPER_TOOLS symbol): hosts the
  identification card, manual KWP write + transaction log, ROM/EEPROM dump
  card with progress banner and completion message, persisted custom-commands
  library, persisted EEPROM passwords library. New service primitives:
  IKwpService.SendRawCustomAsync / ReadEepromAsync / ReadRomEepromAsync.
  Persistence mirrors the Clients XML pattern in two new files
  (custom_commands.xml, eeprom_passwords.xml).
- Auto-test orchestrator (IAutoTestOrchestrator + AutoTestState): linear
  K-Line read -> unlock -> bench-on -> test sequence with snackbar UI and
  progress dialog VM, gated on dashboard alarms.
- BIP-STATUS display: BipDisplayViewModel + BipDisplayView, RAM read at
  0x0106 via IKwpService.ReadBipStatusAsync; status definitions in
  BipStatusDefinition.
- Tests page redesign: TestSectionCard + PhaseTileView replacing the old
  TestPlanView/TestRunningView/TestDoneView/TestPreconditionsView/
  TestSectionView controls and their VMs.
- Pump command sliders: Fluent thick-track style with overhang thumb,
  click-anywhere-and-drag, mouse-wheel adjustment.
- Window startup: app.manifest declares PerMonitorV2 DPI awareness,
  MainWindow installs a WM_GETMINMAXINFO hook in OnSourceInitialized and
  maximizes there (after the hook is in place) so the app fits the work
  area exactly on any display configuration.
- Misc: PercentToPixelsConverter, seed_aliases.py one-shot pump-alias
  importer, tools/Import-BipStatus.ps1, kline_eeprom_spec.md and
  dump-functions reference docs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-07 13:59:50 +02:00

185 lines
9.9 KiB
C#

using System.Collections.Generic;
using Peak.Can.Basic;
using TPCANHandle = System.UInt16;
namespace HC_APTBS.Models
{
/// <summary>
/// Complete bench parameter configuration: CAN parameter map plus relay definitions.
/// Loaded from bench.xml at startup and edited via the BenchParamConfig view.
/// </summary>
public class BenchConfiguration
{
/// <summary>PCAN channel handle used for bench communication.</summary>
public TPCANHandle Channel { get; set; } = PCANBasic.PCAN_USBBUS1;
/// <summary>All bench parameters, keyed by name for quick lookup.</summary>
public Dictionary<string, CanBusParameter> ParametersByName { get; set; } = new();
/// <summary>Bench parameters grouped by CAN message ID for frame decoding.</summary>
public Dictionary<uint, List<CanBusParameter>> ParametersById { get; set; } = new();
/// <summary>Relay / solenoid output definitions, keyed by name.</summary>
public Dictionary<string, Relay> Relays { get; set; } = new();
}
/// <summary>
/// Application-wide configuration settings persisted in config.xml.
/// </summary>
public class AppSettings
{
// ── Temperature control ───────────────────────────────────────────────
/// <summary>Maximum allowable oil temperature (°C) before the bench raises an alarm.</summary>
public int TempMax { get; set; } = 45;
/// <summary>Minimum oil temperature (°C) required before tests begin.</summary>
public int TempMin { get; set; } = 35;
// ── Refresh intervals ─────────────────────────────────────────────────
/// <summary>UI status refresh period (ms) during normal bench operation.</summary>
public int RefreshBenchInterfaceMs { get; set; } = 20;
/// <summary>UI refresh period (ms) while reading pump EEPROM data over K-Line.</summary>
public int RefreshWhileReadingMs { get; set; } = 1500;
/// <summary>CAN bus polling interval (ms) on the read thread.</summary>
public int RefreshCanBusReadMs { get; set; } = 2;
/// <summary>Interval (ms) between pump-status CAN request messages.</summary>
public int RefreshPumpRequestMs { get; set; } = 250;
/// <summary>Interval (ms) between pump-parameter CAN request messages.</summary>
public int RefreshPumpParamsMs { get; set; } = 4;
/// <summary>Blink period (ms) for LED indicator controls.</summary>
public int BlinkIntervalMs { get; set; } = 1000;
/// <summary>Flasher relay toggle interval (ms).</summary>
public int FlasherIntervalMs { get; set; } = 800;
/// <summary>RPM trend chart update rate on the Pump page (Hz). Drives a fixed-rate timer independent of value changes.</summary>
public int RpmChartUpdateHz { get; set; } = 15;
// ── PID temperature controller ────────────────────────────────────────
/// <summary>Proportional gain.</summary>
public double PidP { get; set; } = 0.1;
/// <summary>Integral gain.</summary>
public double PidI { get; set; } = 0.1;
/// <summary>Derivative gain.</summary>
public double PidD { get; set; } = 0.04;
/// <summary>PID loop period (ms).</summary>
public int PidLoopMs { get; set; } = 250;
// ── Safety limits ─────────────────────────────────────────────────────
/// <summary>Maximum allowable bench speed (RPM) before the bench triggers an emergency stop.</summary>
public int SecurityRpmLimit { get; set; } = 2500;
/// <summary>Maximum allowable bench pressure (bar).</summary>
public int MaxPressureBar { get; set; } = 26;
// ── Test tolerance extensions ─────────────────────────────────────────
/// <summary>
/// Fractional tolerance extension for UP tests.
/// A value of 0.08 extends each tolerance bound by 8% of its magnitude.
/// </summary>
public double ToleranceUpExtension { get; set; } = 0.08;
/// <summary>
/// Fractional tolerance extension for PFP tests.
/// A value of 0.1 extends each tolerance bound by 10% of its magnitude.
/// </summary>
public double TolerancePfpExtension { get; set; } = 0.1;
// ── Encoder ───────────────────────────────────────────────────────────
/// <summary>Encoder pulses per revolution (default 4096 for PSG encoder).</summary>
public int EncoderResolution { get; set; } = 4096;
// ── Motor control ─────────────────────────────────────────────────────
/// <summary>Analogue output voltage (V) that corresponds to maximum RPM.</summary>
public double VoltageForMaxRpm { get; set; } = 10;
/// <summary>Maximum motor speed the bench can command (RPM).</summary>
public int MaxRpm { get; set; } = 2500;
// ── Direction ─────────────────────────────────────────────────────────
/// <summary>Default relay state for the "right" rotation direction.</summary>
public bool RightRelayValue { get; set; } = true;
/// <summary>Last rotation direction selected by the operator.</summary>
public short LastRotationDirection { get; set; } = RotationDirection.Right;
/// <summary>When true, the T-in temperature sensor check is bypassed.</summary>
public bool DefaultIgnoreTin { get; set; } = true;
// ── Auto Test ─────────────────────────────────────────────────────────
/// <summary>
/// When true, the Dashboard "Connect &amp; Auto Test" flow bypasses the oil-pump
/// leak-check dialog. Operator accepts that responsibility up front by enabling
/// this toggle. Does not affect the manual Bench page oil-pump toggle, which
/// always shows the dialog.
/// </summary>
public bool AutoTestSkipsOilPumpConfirm { get; set; }
// ── Log rotation ──────────────────────────────────────────────────────
/// <summary>Number of daily log files to retain before the oldest is deleted.</summary>
public int DaysKeepLogs { get; set; } = 7;
// ── Report ────────────────────────────────────────────────────────────
/// <summary>Company name printed in the report header.</summary>
public string CompanyName { get; set; } = string.Empty;
/// <summary>Company address/info printed in the report header.</summary>
public string CompanyInfo { get; set; } = string.Empty;
/// <summary>Absolute path to the company logo image for the report.</summary>
public string ReportLogoPath { get; set; } = string.Empty;
/// <summary>
/// Comma-separated <c>user:salt:hash</c> credential entries for operator authentication
/// before report generation. Salt is 16-byte Base64, hash is PBKDF2-HMAC-SHA256 (600 000 iterations, 32-byte output) Base64.
/// Legacy <c>user:password</c> entries are auto-migrated on first load.
/// </summary>
public string Users { get; set; } = string.Empty;
// ── K-Line port ───────────────────────────────────────────────────────
/// <summary>Serial port or FTDI device identifier for the K-Line interface.</summary>
public string KLinePort { get; set; } = string.Empty;
// ── UI ────────────────────────────────────────────────────────────────
/// <summary>UI language code, e.g. "ESP" or "ENG".</summary>
public string Language { get; set; } = "ESP";
// ── Relations ─────────────────────────────────────────────────────────
/// <summary>RPM-to-voltage lookup table for motor speed control.</summary>
public List<RpmVoltageRelation> Relations { get; set; } = new();
// ── Sensor calibration ────────────────────────────────────────────────
/// <summary>Calibration data for each analogue sensor channel (keyed by channel number).</summary>
public Dictionary<int, SensorConfiguration> Sensors { get; set; } = new();
// ── Alarms ────────────────────────────────────────────────────────────
/// <summary>Active alarm definitions loaded from alarms.xml.</summary>
public List<Alarm> Alarms { get; set; } = new();
}
}