common/Hardware/Common.Hardware.SIRT/Parameters/P11.cs
2026-04-23 17:50:07 +02:00

201 lines
6.9 KiB
C#

namespace Common.Hardware.SIRT.Parameters
{
using System.Text;
/// <summary>
/// Parameter P11 is given at third position of "Telegram from Air" telegram and give more detailed information about the
/// received packets from radio section of SIRT.The bits of Parameter 11 are decoded as following, where Bit 0 is the least
/// significant bit:
/// </summary>
public class P11
{
private readonly byte[] bits;
public P11() => this.bits = new byte[8];
public P11(byte p11) => this.bits = p11.GetBits();
public P11(byte[] bits) => this.bits = bits;
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>RF-Module2 is source</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>RF-Module1 is source</description>
/// </item>
/// </list>
/// <para>only valid if both RF-Module programmed for Sensus RF</para>
/// </summary>
public bool SrcChannel
{
get => this.bits[0] == 1;
set => this.bits[0] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>both RF module data are valid</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>only one RF module data is valid</description>
/// </item>
/// </list>
/// <para>only valid if both RF-Module programmed for Sensus RF</para>
/// </summary>
public bool BothValid
{
get => this.bits[1] == 1;
set => this.bits[1] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>RF-Module1 data is invalid</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>RF-Module1 data is valid</description>
/// </item>
/// </list>
/// <para>i.e. radio checksum is wrong ...</para>
/// </summary>
public bool InvalidMod1
{
get => this.bits[2] == 1;
set => this.bits[2] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>RF-Module2 data is invalid</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>RF-Module2 data is valid</description>
/// </item>
/// </list>
/// <para>i.e. radio checksum is wrong ...</para>
/// </summary>
public bool InvalidMod2
{
get => this.bits[3] == 1;
set => this.bits[3] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>invalid -> module detects length > 128</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>all ok</description>
/// </item>
/// </list>
/// </summary>
public bool LenOverflow
{
get => this.bits[4] == 1;
set => this.bits[4] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>will look at PAM / RAC Pool</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>no attention for PAM / RAC</description>
/// </item>
/// </list>
/// </summary>
public bool Attention
{
get => this.bits[5] == 1;
set => this.bits[5] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>
/// <para>If .modeSensus = 0 wireless M-busMode -> T1 - Mode</para>
/// <para>If .modeSensus = 1 SensusRF -> receive at f2</para>
/// </description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>
/// <para>If .modeSensus = 0 wireless M-busMode -> S1 - Mode</para>
/// <para>If .modeSensus = 1 SensusRF -> receive at f1</para>
/// </description>
/// </item>
/// </list>
/// </summary>
public bool ModeRF
{
get => this.bits[6] == 1;
set => this.bits[6] = (byte)(value ? 1 : 0);
}
/// <summary>
/// <list>
/// <item>
/// <term>true</term>
/// <description>Sensus RF Mode</description>
/// </item>
/// <item>
/// <term>false</term>
/// <description>wireless M-Bus Mode</description>
/// </item>
/// </list>
/// </summary>
public bool ModeSensus
{
get => this.bits[7] == 1;
set => this.bits[7] = (byte)(value ? 1 : 0);
}
public override string ToString()
{
var infoBuilder = new StringBuilder();
infoBuilder.AppendLine(string.Join(string.Empty, this.bits));
infoBuilder.AppendLine(this.SrcChannel ? "Source RF modul 2" : "Source RF modul 1");
infoBuilder.AppendLine(this.BothValid ? "Both RF modules data are valid" : "One RF module data is valid");
infoBuilder.AppendLine(this.InvalidMod1 ? "RF modul 1 data is invalid" : "RF modul 1 data is valid");
infoBuilder.AppendLine(this.InvalidMod2 ? "RF modul 2 data is invalid" : "RF modul 2 data is valid");
infoBuilder.AppendLine(this.LenOverflow ? "Length overflow (> 128)" : "Data length is valid");
infoBuilder.AppendLine(this.Attention ? "Will look in PAM/RAC pool" : "No attention of PAM/RAC pool");
infoBuilder.AppendLine(this.ModeSensus ? "Mode Sensus RF" : "Mode MBus");
infoBuilder.AppendLine(this.ModeRF ? (!this.ModeSensus ? "T1 mode" : "Receive at F2")
: (!this.ModeSensus ? "S1 mode" : "Receive at F1"));
return infoBuilder.ToString().Trim();
}
public static implicit operator byte(P11 p11)
=> p11.bits.GetByte();
public static implicit operator string(P11 p11)
=> p11.ToString();
public static implicit operator P11(byte _byte)
=> new P11(_byte.GetBits());
}
}