Files
laatzen/Common/CommonConsole/RFTelegrams/RSSI.cs
T
2025-09-23 15:37:09 +02:00

43 lines
1.1 KiB
C#

namespace Xylem.Common.Production.ProductionUiCordonel.ProductionProcesses.RFTelegrams
{
public class RSSI
{
public RSSI(byte value, int mhz)
{
this.Value = value;
if (mhz == 433)
{
this.Dbm = value * 0.5 - 140;
this.Percent = value * 0.7333 - 57.6667;
}
else if (mhz == 868)
{
this.Dbm = value * 0.5 - 131.3;
this.Percent = value * 0.66 - 40.316;
}
if (this.Percent > 100)
{
this.Percent = 100;
}
else if (this.Percent < 0)
{
this.Percent = 0;
}
}
public byte Value { get; }
public double Dbm { get; }
public double Percent { get; }
public override string ToString() => $"{this.Dbm}dBm ({this.Percent:0.0}%)";
public static implicit operator byte(RSSI rssi) => rssi?.Value ?? 0;
public static implicit operator string(RSSI rssi) => rssi?.ToString();
}
}