Initial Commit
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
namespace TuneBoss.Core.Protocol;
|
||||
|
||||
/// <summary>
|
||||
/// Hardware/firmware generation, discriminated by App_Info_Version byte.
|
||||
/// </summary>
|
||||
public enum GenerationType
|
||||
{
|
||||
Gen1 = 245, // App_Info_Version 0xF5 — legacy, APP_MEMRD_SEQ for all table ops
|
||||
Gen2 = 1, // Dedicated read commands per table type; APP_UNLOCK
|
||||
Gen3 = 2, // Same as Gen2 but 2D_USER uses APP_MEMRD_2D_USER; APP_UNLOCK2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Per-generation command bytes and misc memory addresses resolved after
|
||||
/// reading App_Info_Version from the device.
|
||||
/// </summary>
|
||||
public sealed class GenerationConfig
|
||||
{
|
||||
// ── Table read commands ──────────────────────────────────────────────────
|
||||
public byte ReadCmd1D { get; init; }
|
||||
public byte ReadCmd2D { get; init; }
|
||||
public byte ReadCmd2DUser{ get; init; }
|
||||
public byte ReadCmdSubT { get; init; }
|
||||
public byte ReadCmdMisc { get; init; }
|
||||
|
||||
// ── Table write commands ─────────────────────────────────────────────────
|
||||
public byte WriteCmd1D { get; init; }
|
||||
public byte WriteCmd2D { get; init; }
|
||||
public byte WriteCmd2DUser{ get; init; }
|
||||
public byte WriteCmdSubT { get; init; }
|
||||
public byte WriteCmdMisc { get; init; }
|
||||
|
||||
// ── Unlock command ───────────────────────────────────────────────────────
|
||||
public byte UnlockCmd { get; init; }
|
||||
|
||||
// ── Misc memory addresses ────────────────────────────────────────────────
|
||||
public ushort RpmLimitAddr { get; init; }
|
||||
public ushort ShiftRpmLimitAddr { get; init; }
|
||||
public ushort MusicModeStartAddr { get; init; }
|
||||
public ushort ExtraPaddingAddr1 { get; init; }
|
||||
public ushort ExtraPaddingAddr2 { get; init; }
|
||||
public ushort ExtraPaddingAddr3 { get; init; }
|
||||
public ushort ExtraPaddingAddr4 { get; init; }
|
||||
public ushort ExtraPaddingAddr5 { get; init; }
|
||||
public ushort ExtraPaddingAddr6 { get; init; }
|
||||
|
||||
// ── Factory ─────────────────────────────────────────────────────────────
|
||||
public static GenerationConfig For(GenerationType gen) => gen switch
|
||||
{
|
||||
GenerationType.Gen1 => new GenerationConfig
|
||||
{
|
||||
ReadCmd1D = Commands.APP_MEMRD_SEQ,
|
||||
ReadCmd2D = Commands.APP_MEMRD_SEQ,
|
||||
ReadCmd2DUser = Commands.APP_MEMRD_SEQ,
|
||||
ReadCmdSubT = Commands.APP_MEMRD_SEQ,
|
||||
ReadCmdMisc = Commands.APP_MEMRD_SEQ,
|
||||
WriteCmd1D = Commands.APP_MEMWR_SEQ,
|
||||
WriteCmd2D = Commands.APP_MEMWR_SEQ,
|
||||
WriteCmd2DUser = Commands.APP_MEMWR_SEQ,
|
||||
WriteCmdSubT = Commands.APP_MEMWR_SEQ,
|
||||
WriteCmdMisc = Commands.APP_MEMWR_SEQ,
|
||||
UnlockCmd = Commands.APP_UNLOCK,
|
||||
RpmLimitAddr = 0x0840,
|
||||
ShiftRpmLimitAddr = 0x08A0,
|
||||
MusicModeStartAddr = 0x090E,
|
||||
ExtraPaddingAddr1 = 0x08BC,
|
||||
ExtraPaddingAddr2 = 0x08C8,
|
||||
ExtraPaddingAddr3 = 0x08D4,
|
||||
ExtraPaddingAddr4 = 0x08E0,
|
||||
ExtraPaddingAddr5 = 0x08FC,
|
||||
ExtraPaddingAddr6 = 0x0918,
|
||||
},
|
||||
|
||||
GenerationType.Gen2 => new GenerationConfig
|
||||
{
|
||||
ReadCmd1D = Commands.APP_MEMRD_1D,
|
||||
ReadCmd2D = Commands.APP_MEMRD_2D,
|
||||
ReadCmd2DUser = Commands.APP_MEMRD_2D,
|
||||
ReadCmdSubT = Commands.APP_MEMRD_SUBT,
|
||||
ReadCmdMisc = Commands.APP_MEMRD_MISC,
|
||||
WriteCmd1D = Commands.APP_MEMWR_1D,
|
||||
WriteCmd2D = Commands.APP_MEMWR_2D,
|
||||
WriteCmd2DUser = Commands.APP_MEMWR_2D,
|
||||
WriteCmdSubT = Commands.APP_MEMWR_SUBT,
|
||||
WriteCmdMisc = Commands.APP_MEMWR_MISC,
|
||||
UnlockCmd = Commands.APP_UNLOCK,
|
||||
RpmLimitAddr = 0x000C,
|
||||
ShiftRpmLimitAddr = 0x006C,
|
||||
MusicModeStartAddr = 0x00DA,
|
||||
ExtraPaddingAddr1 = 0x0088,
|
||||
ExtraPaddingAddr2 = 0x0094,
|
||||
ExtraPaddingAddr3 = 0x00A0,
|
||||
ExtraPaddingAddr4 = 0x00AC,
|
||||
ExtraPaddingAddr5 = 0x00C8,
|
||||
ExtraPaddingAddr6 = 0x00E4,
|
||||
},
|
||||
|
||||
GenerationType.Gen3 => new GenerationConfig
|
||||
{
|
||||
ReadCmd1D = Commands.APP_MEMRD_1D,
|
||||
ReadCmd2D = Commands.APP_MEMRD_2D,
|
||||
ReadCmd2DUser = Commands.APP_MEMRD_2D_USER, // ← key difference from Gen2
|
||||
ReadCmdSubT = Commands.APP_MEMRD_SUBT,
|
||||
ReadCmdMisc = Commands.APP_MEMRD_MISC,
|
||||
WriteCmd1D = Commands.APP_MEMWR_1D,
|
||||
WriteCmd2D = Commands.APP_MEMWR_2D,
|
||||
WriteCmd2DUser = Commands.APP_MEMWR_2D_USER, // ← key difference from Gen2
|
||||
WriteCmdSubT = Commands.APP_MEMWR_SUBT,
|
||||
WriteCmdMisc = Commands.APP_MEMWR_MISC,
|
||||
UnlockCmd = Commands.APP_UNLOCK2, // ← different unlock
|
||||
RpmLimitAddr = 0x000C,
|
||||
ShiftRpmLimitAddr = 0x006C,
|
||||
MusicModeStartAddr = 0x00DA,
|
||||
ExtraPaddingAddr1 = 0x0088,
|
||||
ExtraPaddingAddr2 = 0x0094,
|
||||
ExtraPaddingAddr3 = 0x00A0,
|
||||
ExtraPaddingAddr4 = 0x00AC,
|
||||
ExtraPaddingAddr5 = 0x00C8,
|
||||
ExtraPaddingAddr6 = 0x00E4,
|
||||
},
|
||||
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(gen), gen, "Unknown generation")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Resolves generation from the App_Info_Version byte on the wire.
|
||||
/// </summary>
|
||||
public static GenerationType ResolveGeneration(byte appInfoVersion) => appInfoVersion switch
|
||||
{
|
||||
245 => GenerationType.Gen1,
|
||||
1 => GenerationType.Gen2,
|
||||
2 => GenerationType.Gen3,
|
||||
_ => throw new InvalidOperationException($"Unknown App_Info_Version: {appInfoVersion}")
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user