Initial Commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
namespace TuneBoss.Core.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Holds all table data loaded from a connected TuneBoss device.
|
||||
/// Constructed after a successful populateInitTables sequence.
|
||||
///
|
||||
/// Acts as the single source of truth for the current session.
|
||||
/// ViewModels bind to properties on this object.
|
||||
/// Immutable by convention — table updates produce new instances.
|
||||
/// </summary>
|
||||
public sealed record EcuSession
|
||||
{
|
||||
// ── Device identity ───────────────────────────────────────────────────────
|
||||
public EcuInfo Info { get; init; } = null!;
|
||||
public MemoryLayout Layout { get; init; } = null!;
|
||||
public EcuVariant Variant { get; init; }
|
||||
|
||||
// ── 2D tuning tables — cylinder 1 ────────────────────────────────────────
|
||||
public TuningTable? Fuel_PulseWidth1 { get; init; }
|
||||
public TuningTable? Spark_Angle1 { get; init; }
|
||||
public TuningTable? Fuel_Angle2D { get; init; }
|
||||
public TuningTable? Secondary_Load_Conversion { get; init; }
|
||||
public TuningTable? Fuel_PulseWidth_Adjust1 { get; init; }
|
||||
public TuningTable? Spark_Angle_Adjust1 { get; init; }
|
||||
public AfrTable? AFR_Target1 { get; init; }
|
||||
|
||||
// ── Subtables — cylinder 1 ────────────────────────────────────────────────
|
||||
public SubTable? AFR_Target1_SubTable { get; init; }
|
||||
public SubTable? Fuel_PulseWidth_Adjust1_SubTable { get; init; }
|
||||
public SubTable? Spark_Angle_Adjust1_SubTable { get; init; }
|
||||
|
||||
// ── 2D tuning tables — cylinder 2 (isTwoCylinder only) ───────────────────
|
||||
public TuningTable? Fuel_PulseWidth2 { get; init; }
|
||||
public TuningTable? Spark_Angle2 { get; init; }
|
||||
public TuningTable? Fuel_Angle2D_2 { get; init; }
|
||||
public TuningTable? Fuel_PulseWidth_Adjust2 { get; init; }
|
||||
public TuningTable? Spark_Angle_Adjust2 { get; init; }
|
||||
public AfrTable? AFR_Target2 { get; init; }
|
||||
|
||||
// ── Subtables — cylinder 2 ────────────────────────────────────────────────
|
||||
public SubTable? AFR_Target2_SubTable { get; init; }
|
||||
public SubTable? Fuel_PulseWidth_Adjust2_SubTable { get; init; }
|
||||
public SubTable? Spark_Angle_Adjust2_SubTable { get; init; }
|
||||
|
||||
// ── 1D tables (up to 37, null = not available on this FW version) ─────────
|
||||
public OneDimTable?[] OneDimTables { get; init; } = new OneDimTable?[37];
|
||||
|
||||
// ── Misc values ───────────────────────────────────────────────────────────
|
||||
public MiscValues? Misc { get; init; }
|
||||
|
||||
// ── Derived ──────────────────────────────────────────────────────────────
|
||||
public bool IsTwoCylinder => Variant != EcuVariant.SingleCylinder;
|
||||
|
||||
public bool HasExtendedMisc => Info.FwVersion >= 150;
|
||||
|
||||
/// <summary>
|
||||
/// True when the session has been fully loaded —
|
||||
/// i.e. all tables available for this device have been read.
|
||||
/// </summary>
|
||||
public bool IsFullyLoaded { get; init; }
|
||||
|
||||
// ── Mutation helpers ──────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Returns a new session with Fuel_PulseWidth1 replaced.</summary>
|
||||
public EcuSession WithFuel1(TuningTable t) => this with { Fuel_PulseWidth1 = t };
|
||||
public EcuSession WithSpark1(TuningTable t) => this with { Spark_Angle1 = t };
|
||||
public EcuSession WithFuelAdjust1(TuningTable t) => this with { Fuel_PulseWidth_Adjust1 = t };
|
||||
public EcuSession WithSparkAdjust1(TuningTable t) => this with { Spark_Angle_Adjust1 = t };
|
||||
public EcuSession WithFuelAngle(TuningTable t) => this with { Fuel_Angle2D = t };
|
||||
public EcuSession WithAfr1(AfrTable t) => this with { AFR_Target1 = t };
|
||||
public EcuSession WithMisc(MiscValues m) => this with { Misc = m };
|
||||
|
||||
public EcuSession WithOneDimTable(int index, OneDimTable t)
|
||||
{
|
||||
var arr = (OneDimTable?[])OneDimTables.Clone();
|
||||
arr[index] = t;
|
||||
return this with { OneDimTables = arr };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user