namespace Common.Hardware.SIRT.Parameters
{
using System.Text;
///
/// 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:
///
public class P11
{
private readonly byte[] bits;
public P11() => this.bits = new byte[8];
public P11(byte p11) => this.bits = p11.GetBitsLE();
public P11(byte[] bits) => this.bits = bits;
///
///
/// -
/// true
/// RF-Module2 is source
///
/// -
/// false
/// RF-Module1 is source
///
///
/// only valid if both RF-Module programmed for Sensus RF
///
public bool SrcChannel
{
get => this.bits[0] == 1;
set => this.bits[0] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
/// both RF module data are valid
///
/// -
/// false
/// only one RF module data is valid
///
///
/// only valid if both RF-Module programmed for Sensus RF
///
public bool BothValid
{
get => this.bits[1] == 1;
set => this.bits[1] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
/// RF-Module1 data is invalid
///
/// -
/// false
/// RF-Module1 data is valid
///
///
/// i.e. radio checksum is wrong ...
///
public bool InvalidMod1
{
get => this.bits[2] == 1;
set => this.bits[2] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
/// RF-Module2 data is invalid
///
/// -
/// false
/// RF-Module2 data is valid
///
///
/// i.e. radio checksum is wrong ...
///
public bool InvalidMod2
{
get => this.bits[3] == 1;
set => this.bits[3] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
/// invalid -> module detects length > 128
///
/// -
/// false
/// all ok
///
///
///
public bool LenOverflow
{
get => this.bits[4] == 1;
set => this.bits[4] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
/// will look at PAM / RAC Pool
///
/// -
/// false
/// no attention for PAM / RAC
///
///
///
public bool Attention
{
get => this.bits[5] == 1;
set => this.bits[5] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
///
/// If .modeSensus = 0 wireless M-busMode -> T1 - Mode
/// If .modeSensus = 1 SensusRF -> receive at f2
///
///
/// -
/// false
///
/// If .modeSensus = 0 wireless M-busMode -> S1 - Mode
/// If .modeSensus = 1 SensusRF -> receive at f1
///
///
///
///
public bool ModeRF
{
get => this.bits[6] == 1;
set => this.bits[6] = (byte)(value ? 1 : 0);
}
///
///
/// -
/// true
/// Sensus RF Mode
///
/// -
/// false
/// wireless M-Bus Mode
///
///
///
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.GetByteLE();
public static implicit operator string(P11 p11)
=> p11.ToString();
public static implicit operator P11(byte _byte)
=> new P11(_byte.GetBitsLE());
}
}