Files
laatzen/Common/Hardware/Common.Hardware.SIRT/Parameters/PAMStatus.cs
T

72 lines
1.8 KiB
C#

namespace Common.Hardware.SIRT.Parameters
{
using Common.Hardware.Ports;
using System.Text;
public class PAMStatus
{
private readonly byte[] bits;
public PAMStatus(byte _byte)
=> this.bits = _byte.GetBitsLE();
public bool CMD_UNKNOWN => this.bits[0] == 1;
public bool WRONG_AUTH => this.bits[1] == 1;
public bool EXPIRED_AUTH => this.bits[2] == 1;
public bool MIXED_TYPES => this.bits[3] == 1;
public bool OUT_OF_RANGE => this.bits[4] == 1;
public override string ToString()
{
var statusBuilder = new StringBuilder();
if (this.CMD_UNKNOWN)
{
statusBuilder.AppendLine(nameof(this.CMD_UNKNOWN));
}
if (this.WRONG_AUTH)
{
statusBuilder.AppendLine(nameof(this.WRONG_AUTH));
}
if (this.EXPIRED_AUTH)
{
statusBuilder.AppendLine(nameof(this.EXPIRED_AUTH));
}
if (this.MIXED_TYPES)
{
statusBuilder.AppendLine(nameof(this.MIXED_TYPES));
}
if (this.OUT_OF_RANGE)
{
statusBuilder.AppendLine(nameof(this.OUT_OF_RANGE));
}
if (statusBuilder.Length == 0)
{
statusBuilder.AppendLine(nameof(OK));
}
return statusBuilder.ToString().Trim('\n', '\r');
}
public static byte OK = 0;
public static byte EXPIREDAUTH = 4;
public static implicit operator byte(PAMStatus status)
=> status?.bits?.GetByteLE() ?? 0xFF;
public static implicit operator string(PAMStatus status)
=> status?.ToString();
}
}