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>
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using RioJoy.Core.Protocol;
|
|
using Xunit;
|
|
|
|
namespace RioJoy.Core.Tests.Protocol;
|
|
|
|
public class PacketBuilderTests
|
|
{
|
|
[Fact]
|
|
public void AnalogRequest_HasCommandAndChecksumOnly()
|
|
{
|
|
// 0x82, checksum = 0x82 & 0x7F = 0x02
|
|
Assert.Equal(new byte[] { 0x82, 0x02 }, PacketBuilder.AnalogRequest());
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetRequest_EncodesTarget()
|
|
{
|
|
// 0x83, payload [0x00], checksum = 0x03
|
|
Assert.Equal(new byte[] { 0x83, 0x00, 0x03 }, PacketBuilder.ResetRequest(RioResetTarget.All));
|
|
// 0x83, payload [0x01], checksum = 0x04
|
|
Assert.Equal(new byte[] { 0x83, 0x01, 0x04 }, PacketBuilder.ResetRequest(RioResetTarget.Throttle));
|
|
}
|
|
|
|
[Fact]
|
|
public void LampRequest_EncodesLampAndState()
|
|
{
|
|
// 0x84, payload [0x05, 0x3C], checksum = (0x04 + 0x05 + 0x3C) & 0x7F = 0x45
|
|
Assert.Equal(new byte[] { 0x84, 0x05, 0x3C, 0x45 }, PacketBuilder.LampRequest(5, 0x3C));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ValidatesPayloadLength()
|
|
{
|
|
Assert.Throws<ArgumentException>(() => PacketBuilder.Build(RioCommand.LampRequest, new byte[] { 0x01 }));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_AppendsCorrectChecksum_ForFullPayload()
|
|
{
|
|
var payload = new byte[] { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0 };
|
|
byte[] packet = PacketBuilder.Build(RioCommand.AnalogReply, payload);
|
|
|
|
Assert.Equal((byte)RioCommand.AnalogReply, packet[0]);
|
|
Assert.Equal(payload, packet.Skip(1).Take(packet.Length - 2).ToArray());
|
|
Assert.Equal(RioChecksum.Compute(packet, 0, packet.Length - 1), packet[packet.Length - 1]);
|
|
}
|
|
}
|