tbf/TBF/Rig/RegisterReaders/iPerlASICReader/communication/C4/diagnosticLed/parserer/DiagnosticLedState2Data.cs

72 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using TBF.Rig.RegisterReaders.iPerlASICReader.communication.C4.diagnosticLed.utils;
namespace TBF.Rig.RegisterReaders.iPerlASICReader.communication.C4.diagnosticLed.parserer
{
/// <summary>
/// Diagnostic LED State #2 data frame.
///
/// <para>
/// State #2 extends the common diagnostic LED fields with information
/// about the LCD-displayed volume, the current meter operating state,
/// and whether the meter is in low-flow cutoff mode.
/// </para>
///
/// <para>
/// Frame format: TAB-separated ASCII hexadecimal fields, terminated by CRLF.
/// The checksum is an 8-bit sum of all previous ASCII bytes including
/// the TAB character before the checksum field.
/// </para>
///
/// <list type="table">
/// <listheader>
/// <term>Pos</term>
/// <description>Field description</description>
/// </listheader>
/// <item><term>0 xxxxxx</term><description>Signed 24-bit ADC value (twos complement)</description></item>
/// <item><term>1 aaaa</term><description>Unsigned 16-bit field strength (internal units)</description></item>
/// <item><term>2 yyyy</term><description>Signed 16-bit raw flow rate (¼ ml per bit)</description></item>
/// <item><term>3 vvvvvv</term><description>Unsigned 24-bit raw volume accumulation (¼ ml per bit)</description></item>
/// <item><term>4 cccc</term><description>Unsigned 16-bit millivolt delta on the field drive capacitor</description></item>
/// <item><term>5 gggggggg</term><description>Unsigned 32-bit volume displayed on the LCD</description></item>
/// <item><term>6 mm</term><description>Unsigned 8-bit meter state (see Table 17-23 in protocol documentation)</description></item>
/// <item><term>7 ff</term><description>Unsigned 8-bit boolean flag indicating low-flow cutoff
/// state (0 = false, 1 = true)</description></item>
/// <item><term>8 ss</term><description>Unsigned 8-bit checksum (sum of all previous ASCII bytes including
/// the TAB before the checksum field)</description></item>
/// </list>
/// </summary>
public sealed class DiagnosticLedState2Data : DiagnosticLedData
{
/// <summary>
/// Volume displayed on LCD (raw units).
/// </summary>
public uint LcdVolume { get; }
/// <summary>
/// Meter state (see Table 17-23).
/// </summary>
public byte MeterState { get; }
/// <summary>
/// True if meter is in low-flow cutoff.
/// </summary>
public bool IsLowFlowCutoff { get; }
public DiagnosticLedState2Data(string rawLine, string[] fields)
: base(rawLine)
{
// ---- Common fields (04) ----
Adc24 = DiagnosticHex.ParseInt24(fields[0]);
FieldStrength = DiagnosticHex.ParseUInt16(fields[1]);
RawFlow = DiagnosticHex.ParseInt16(fields[2]);
RawVolume = DiagnosticHex.ParseUInt24(fields[3]);
CapacitorMv = DiagnosticHex.ParseUInt16(fields[4]);
// ---- State #2 specific ----
LcdVolume = DiagnosticHex.ParseUInt32(fields[5]);
MeterState = DiagnosticHex.ParseByte(fields[6]);
IsLowFlowCutoff = DiagnosticHex.ParseByte(fields[7]) != 0;
}
}
}