Add AllyReader and AllyCalibration support with tests: Introduce new register readers, calibration methods, and comprehensive unit tests for integration and functionality validation. Update project files accordingly.
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace TBF.Rig.RegisterReaders.AllyReader.Communication
|
|
{
|
|
public sealed class AllyFrameParser
|
|
{
|
|
public AllyResponse ParseResponse(byte[] data)
|
|
{
|
|
if (data == null)
|
|
throw new ArgumentNullException(nameof(data));
|
|
if (data.Length < 5)
|
|
throw new FormatException("ALLY response is too short.");
|
|
if (data[0] != AllyProtocol.Start)
|
|
throw new FormatException("ALLY response has an invalid start byte.");
|
|
if (data[1] != AllyProtocol.Read)
|
|
throw new FormatException("ALLY frame is not a response.");
|
|
if (data[2] != data.Length)
|
|
throw new FormatException("ALLY response length does not match its length field.");
|
|
if (data[data.Length - 1] != AllyProtocol.End)
|
|
throw new FormatException("ALLY response has an invalid end byte.");
|
|
|
|
byte[] payload = new byte[data.Length - 5];
|
|
if (payload.Length > 0)
|
|
Buffer.BlockCopy(data, 4, payload, 0, payload.Length);
|
|
|
|
return new AllyResponse(data[3], payload);
|
|
}
|
|
}
|
|
}
|