- Register Reader Poseidon works - Smart Form - wrong functionality - refactoring
95 lines
4.3 KiB
C#
95 lines
4.3 KiB
C#
using System;
|
|
|
|
namespace NfcC7_DLL.NfcHandler.Protocols
|
|
{
|
|
public class WaterMetrologyDataC2
|
|
{
|
|
public string DutInfo { get; set; }
|
|
public DateTime Dt { get; set; }
|
|
public int AdcSample { get; set; }
|
|
public short LastField { get; set; }
|
|
public short FlowRate { get; set; }
|
|
public uint Accumulator { get; set; }
|
|
public ushort FlipPeriod { get; set; }
|
|
public ushort VinfStart { get; set; }
|
|
public ushort VinfEnd { get; set; }
|
|
public short ElectrodeDelta { get; set; }
|
|
public ushort Impedance { get; set; }
|
|
public byte FieldDriveTime { get; set; }
|
|
public bool IsInLowFlow { get; set; }
|
|
public bool IsInEmptyPipe { get; set; }
|
|
public bool FastHPFC { get; set; }
|
|
public bool FieldPolarity { get; set; }
|
|
public bool ImpedancePolarity { get; set; }
|
|
|
|
public double CalcFlowmLps
|
|
{
|
|
get { return FlowRate / 4.0; } // FlowRate is in 1/4 mL/s
|
|
}
|
|
public double CalcFlowGPM
|
|
{
|
|
get { return CalcFlowmLps * 0.015850323141489; } // mL/s to gal/min conversion
|
|
}
|
|
public double CalcAccGal
|
|
{
|
|
get { return (Accumulator / 4.0) * 0.000264172; } // Accumulator is in 1/4 mL, convert to gallons
|
|
}
|
|
|
|
public static WaterMetrologyDataC2 Parse(string base64Data, DateTime dt, string dutinfo)
|
|
{
|
|
byte[] data = Convert.FromBase64String(base64Data);
|
|
return Parse(data, dt, dutinfo);
|
|
}
|
|
|
|
public static WaterMetrologyDataC2 Parse(byte[] data, DateTime dt, string dutinfo)
|
|
{
|
|
if (data.Length < 24)
|
|
{
|
|
throw new ArgumentException("Invalid data length for WaterMetrologyData C2.");
|
|
}
|
|
|
|
|
|
WaterMetrologyDataC2 result = new WaterMetrologyDataC2();
|
|
|
|
result.DutInfo = dutinfo;
|
|
result.Dt = dt;
|
|
result.AdcSample = BitConverter.ToInt32(data, 0);
|
|
result.LastField = BitConverter.ToInt16(data, 4);
|
|
result.FlowRate = BitConverter.ToInt16(data, 6);
|
|
result.Accumulator = BitConverter.ToUInt32(data, 8);
|
|
result.FlipPeriod = BitConverter.ToUInt16(data, 12);
|
|
result.VinfStart = BitConverter.ToUInt16(data, 14);
|
|
result.VinfEnd = BitConverter.ToUInt16(data, 16);
|
|
result.ElectrodeDelta = BitConverter.ToInt16(data, 18);
|
|
result.Impedance = BitConverter.ToUInt16(data, 20);
|
|
result.FieldDriveTime = data[22];
|
|
|
|
byte flags = data[23];
|
|
result.IsInLowFlow = (flags & 0x01) != 0;
|
|
result.IsInEmptyPipe = (flags & 0x02) != 0;
|
|
result.FastHPFC = (flags & 0x04) != 0; // Fast High Pass Filter Constant in bit 2
|
|
result.FieldPolarity = (flags & 0x08) != 0; // Field Polarity in bit 3
|
|
result.ImpedancePolarity = (flags & 0x10) != 0; // Impedance Polarity in bit 4
|
|
return result;
|
|
}
|
|
|
|
//public override string ToString()
|
|
//{
|
|
// return $"ADC Sample: {AdcSample}, Last Field: {LastField}, Flow Rate: {FlowRate}, Accumulator: {Accumulator}, " +
|
|
// $"Flip Period Ticks: {FlipPeriodTicks}, Vinf Start: {VinfStart}, Vinf End: {VinfEnd}, Electrode Delta: {ElectrodeDelta}, " +
|
|
// $"Impedance: {Impedance}, Field Drive Time: {FieldDriveTime}, Is Low Flow: {IsInLowFlow}, Is Empty Pipe: {IsInEmptyPipe}, " +
|
|
// $"Fast High Pass Filter: {FastHighPassFilterConstant}, Field Polarity: {FieldPolarity}, Impedance Polarity: {ImpedancePolarity}";
|
|
//}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"DutInfo: {DutInfo}, Dt: {Dt}, ADC Sample: {AdcSample}, Last Field: {LastField}, Flow Rate: {FlowRate}, Accumulator: {Accumulator}, " +
|
|
$"Flip Period: {FlipPeriod}, Vinf Start: {VinfStart}, Vinf End: {VinfEnd}, Electrode Delta: {ElectrodeDelta}, " +
|
|
$"Impedance: {Impedance}, Field Drive Time: {FieldDriveTime}, Is Low Flow: {IsInLowFlow}, Is Empty Pipe: {IsInEmptyPipe}, " +
|
|
$"Fast HPFC: {FastHPFC}, Field Polarity: {FieldPolarity}, Impedance Polarity: {ImpedancePolarity}, " +
|
|
$"Calc Flow mL/s: {CalcFlowmLps:F2}, Calc Flow GPM: {CalcFlowGPM:F2}, Calc Acc Gal: {CalcAccGal:F2}";
|
|
}
|
|
|
|
}
|
|
}
|