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

187 lines
5.9 KiB
C#

namespace Common.Hardware.SIRT.Parameters
{
using Common.Hardware.Ports;
using System;
/// <summary>
/// P12 is the parameter of "Acknowledge or Answer" message and is placed at third position,
/// if telegram from SIRT-> PC begins with {0xFF, 0x12}.
/// This parameter gives more detailed information about the last command or request which
/// was send to SIRT.
/// Parameter 12 is given at third position of acknowledge- or answer telegram from SIRT.
/// </summary>
public class P12
{
private readonly byte[] bits;
public P12() => this.bits = new byte[8];
public P12(byte p12) => this.bits = p12.GetBitsLE();
public P12(byte[] bits) => this.bits = bits;
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>requested buffer is full or not available</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool BufFull
{
get => this.bits[0] == 1;
set => this.bits[0] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>operating system is busy</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool OsBusy
{
get => this.bits[1] == 1;
set => this.bits[1] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>wrong CRC recognized</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool WrongCRC
{
get => this.bits[2] == 1;
set => this.bits[2] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>command cannot be executed</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool CmdNotExecuted
{
get => this.bits[3] == 1;
set => this.bits[3] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>telegram or command byte unknown</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool CmdUnknown
{
get => this.bits[4] == 1;
set => this.bits[4] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>no such entry found</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool NoEntry
{
get => this.bits[5] == 1;
set => this.bits[5] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>unknown fixed byte</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>Ok</description>
/// </item>
/// </list>
/// </summary>
public bool ByteUnknown
{
get => this.bits[6] == 1;
set => this.bits[6] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>address was 0xFFFFFFFF</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>normal address</description>
/// </item>
/// </list>
/// </summary>
public bool WildCardAddr
{
get => this.bits[7] == 1;
set => this.bits[7] = (byte)(value ? 1 : 0);
}
public override string ToString()
=> $"{nameof(P12)}: {string.Join(string.Empty, this.bits)}"
+ (this.BufFull ? Environment.NewLine + nameof(this.BufFull) : default(string))
+ (this.OsBusy ? Environment.NewLine + nameof(this.OsBusy) : default(string))
+ (this.WrongCRC ? Environment.NewLine + nameof(this.WrongCRC) : default(string))
+ (this.CmdNotExecuted ? Environment.NewLine + nameof(this.CmdNotExecuted) : default(string))
+ (this.CmdUnknown ? Environment.NewLine + nameof(this.CmdUnknown) : default(string))
+ (this.NoEntry ? Environment.NewLine + nameof(this.NoEntry) : default(string))
+ (this.ByteUnknown ? Environment.NewLine + nameof(this.ByteUnknown) : default(string));
public static implicit operator byte(P12 p11)
=> p11.bits.GetByteLE();
public static implicit operator string(P12 p11)
=> p11.ToString();
public static implicit operator P12(byte _byte)
=> new P12(_byte.GetBitsLE());
}
}