laatzen/Common/Hardware/Common.Hardware.SIRT/Parameters/PAMStatus.cs
2026-02-04 15:09:53 +01:00

102 lines
2.6 KiB
C#

using System.Text;
namespace Common.Hardware.SIRT.Parameters
{
public class PAMStatus
{
private readonly byte[] bits;
public PAMStatus(byte _byte)
{
this.IsValid = _byte <= 31;
this.bits = _byte.GetBits();
}
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 bool IsValid { get; }
public override string ToString()
{
if (this.bits.GetByte() == 0)
{
return nameof(OK);
}
else if (this.OUT_OF_RANGE)
{
return nameof(this.OUT_OF_RANGE);
}
else if (this.MIXED_TYPES)
{
return nameof(this.MIXED_TYPES);
}
else if (this.CMD_UNKNOWN)
{
return nameof(this.CMD_UNKNOWN);
}
else if (this.EXPIRED_AUTH)
{
return nameof(this.EXPIRED_AUTH);
}
else if (this.WRONG_AUTH)
{
return nameof(this.WRONG_AUTH);
}
else
{
return string.Join(string.Empty, this.bits);
}
}
public string ToString(bool extended)
{
var stringBuilder = new StringBuilder();
if (this.bits.GetByte() == 0)
{
stringBuilder.AppendLine(nameof(OK));
}
if (this.OUT_OF_RANGE)
{
stringBuilder.AppendLine(nameof(this.OUT_OF_RANGE));
}
if (this.MIXED_TYPES)
{
stringBuilder.AppendLine(nameof(this.MIXED_TYPES));
}
if (this.CMD_UNKNOWN)
{
stringBuilder.AppendLine(nameof(this.CMD_UNKNOWN));
}
if (this.EXPIRED_AUTH)
{
stringBuilder.AppendLine(nameof(this.EXPIRED_AUTH));
}
if (this.WRONG_AUTH)
{
stringBuilder.AppendLine(nameof(this.WRONG_AUTH));
}
return stringBuilder.ToString().Trim();
}
public static byte OK = 0;
public static byte EXPIREDAUTH = 4;
public static implicit operator byte(PAMStatus status)
=> status?.bits?.GetByte() ?? 0xFF;
public static implicit operator string(PAMStatus status)
=> status?.ToString();
}
}