Files
riojoy/src/RioJoy.Core/Protocol/RioReplies.cs
T
CydandClaude Fable 5 3b2af7b79a Phase 8A (1/2): de-Span the serial layer, swap JSON to Newtonsoft
Prepares RioJoy.Core for the net40 (Windows XP) target, which has no
System.Memory, ValueTask, or System.Text.Json:
- IRioTransport and the whole protocol/framing layer now use byte[] +
  Task (RioPacket.Payload, PacketParser/Builder, RioChecksum, replies,
  AnalogReport, RioHidReport). At 9600 baud Span bought nothing; the
  SerialPortTransport bridge copies disappear entirely.
- ConfigStore/OverlayTemplateStore switch to Newtonsoft 13 with the
  same conventions (indented, PascalCase, string enums, null-skipping);
  verified against the real STJ-written config.json and regions.json
  (load + round-trip). System.Memory and System.Text.Json packages
  dropped.

275 tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 20:36:19 -05:00

63 lines
2.0 KiB
C#

namespace RioJoy.Core.Protocol;
/// <summary>
/// The RIO firmware version from a <see cref="RioCommand.VersionReply"/>
/// (port of <c>VersionReply</c>, riovjoy2.cpp#L1484: payload is [major, minor]).
/// </summary>
public readonly struct VersionInfo
{
public byte Major { get; }
public byte Minor { get; }
public VersionInfo(byte major, byte minor)
{
Major = major;
Minor = minor;
}
/// <summary>Decode a <see cref="RioCommand.VersionReply"/> payload (2 bytes).</summary>
public static VersionInfo Parse(byte[] payload)
{
Require(payload, RioCommand.VersionReply);
return new VersionInfo(payload[0], payload[1]);
}
public override string ToString() => $"{Major}.{Minor}";
internal static void Require(byte[] payload, RioCommand command)
{
if (payload is null) throw new ArgumentNullException(nameof(payload));
int expected = RioCommandTable.PayloadLength(command);
if (payload.Length != expected)
throw new ArgumentException(
$"{command} payload must be {expected} bytes.", nameof(payload));
}
}
/// <summary>
/// A board/lamp status item from a <see cref="RioCommand.CheckReply"/>
/// (port of <c>CheckReply</c>, riovjoy2.cpp#L1303: payload is [statusType, number]).
/// The <see cref="Number"/> is a board number, lamp number, or counter depending
/// on <see cref="Type"/>.
/// </summary>
public readonly struct CheckStatus
{
public RioStatusType Type { get; }
public byte Number { get; }
public CheckStatus(RioStatusType type, byte number)
{
Type = type;
Number = number;
}
/// <summary>Decode a <see cref="RioCommand.CheckReply"/> payload (2 bytes).</summary>
public static CheckStatus Parse(byte[] payload)
{
VersionInfo.Require(payload, RioCommand.CheckReply);
return new CheckStatus((RioStatusType)payload[0], payload[1]);
}
public override string ToString() => $"{Type}:{Number}";
}