tbf/TBF/Rig/RegisterReaders/AllyReader/Communication/AllyResponse.cs
Michal Buzik c71fe75446 Ally iPerl initial - reader,test method, unit test
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.
2026-08-18 10:01:02 +02:00

52 lines
1.5 KiB
C#

using System;
using System.Text;
namespace TBF.Rig.RegisterReaders.AllyReader.Communication
{
public sealed class AllyResponse
{
public byte Status { get; private set; }
public byte[] Payload { get; private set; }
public bool IsSuccess { get { return Status == AllyProtocol.CommandCompleted; } }
internal AllyResponse(byte status, byte[] payload)
{
Status = status;
Payload = payload ?? Array.Empty<byte>();
}
public string GetNullTerminatedAscii()
{
int length = Array.IndexOf(Payload, (byte)0x00);
if (length < 0)
length = Payload.Length;
return Encoding.ASCII.GetString(Payload, 0, length).Trim();
}
public byte GetByte()
{
if (Payload.Length != 1)
throw new FormatException("ALLY response does not contain one byte.");
return Payload[0];
}
public ushort GetUInt16LittleEndian()
{
if (Payload.Length != 2)
throw new FormatException("ALLY response does not contain a UInt16 value.");
return (ushort)(Payload[0] | (Payload[1] << 8));
}
public uint GetUInt32LittleEndian()
{
if (Payload.Length != 4)
throw new FormatException("ALLY response does not contain a UInt32 value.");
return (uint)(Payload[0]
| (Payload[1] << 8)
| (Payload[2] << 16)
| (Payload[3] << 24));
}
}
}