Refactor `NfcHanler` namespace to `NfcHandler` and enhance code consistency.
93 lines
4.0 KiB
C#
93 lines
4.0 KiB
C#
namespace NfcC7_DLL.NfcHandler.Protocols
|
|
{
|
|
public class WaterMetrologyDataC7 : WaterMetrologyDataC2
|
|
{
|
|
// New fields for C7
|
|
public int LastFieldmilliGauss { get; set; }
|
|
public int ImpedanceI { get; set; } // In-phase impedance
|
|
public int ImpedanceQ { get; set; } // Out-of-phase impedance
|
|
public int NoiseMetric { get; set; }
|
|
public short LearningLockout { get; set; }
|
|
public short ReverseBuffer { get; set; }
|
|
public int ConditionedAdc { get; set; }
|
|
public uint Totalalizer { 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 bool MagTamperState { get; set; }
|
|
public bool IsLearningActive { get; set; }
|
|
public bool AdcShiftsUpdated { get; set; }
|
|
|
|
|
|
public static WaterMetrologyDataC7 Parse(string base64Data, DateTime dt, string dutinfo)
|
|
{
|
|
byte[] data = Convert.FromBase64String(base64Data);
|
|
return Parse(data, dt, dutinfo);
|
|
}
|
|
|
|
public static WaterMetrologyDataC7 Parse(byte[] data, DateTime dt, string dutinfo)
|
|
{
|
|
|
|
// You may want to check for the minimum length required for C7
|
|
if (data.Length < 48) /* minimum required length for C7 */
|
|
{
|
|
throw new ArgumentException("Invalid data length for WaterMetrologyData C7.");
|
|
}
|
|
|
|
var result = new WaterMetrologyDataC7();
|
|
|
|
// Parse base C2 fields
|
|
var c2 = WaterMetrologyDataC2.Parse(data, dt, dutinfo);
|
|
|
|
//Copy base fields
|
|
result.DutInfo = c2.DutInfo;
|
|
result.Dt = c2.Dt;
|
|
result.AdcSample = c2.AdcSample;
|
|
result.LastField = c2.LastField;
|
|
result.FlowRate = c2.FlowRate;
|
|
result.Accumulator = c2.Accumulator;
|
|
result.FlipPeriod = c2.FlipPeriod;
|
|
result.VinfStart = c2.VinfStart;
|
|
result.VinfEnd = c2.VinfEnd;
|
|
result.ElectrodeDelta = c2.ElectrodeDelta;
|
|
result.Impedance = c2.Impedance;
|
|
result.FieldDriveTime = c2.FieldDriveTime;
|
|
|
|
|
|
result.IsInLowFlow = c2.IsInLowFlow;
|
|
result.IsInEmptyPipe = c2.IsInEmptyPipe;
|
|
result.FieldPolarity = c2.FieldPolarity;
|
|
result.ImpedancePolarity = c2.ImpedancePolarity;
|
|
|
|
|
|
// Parse new C7 fields (replace ENUM_OptPack0xC7.FIELD_MILLI_GAUSS etc. with actual offsets)
|
|
byte flags = data[23];
|
|
result.MagTamperState = (flags & 0x60) != 0; // bits 5 and 6 represent MagTamperState
|
|
result.IsLearningActive = (flags & 0x80) != 0; // bit 7 represents IsLearningActive
|
|
|
|
byte flagTwo = data[24];
|
|
|
|
result.AdcShiftsUpdated = (flagTwo & 0x01) != 0; // bit 0 represents AdcShiftsUpdated
|
|
|
|
result.LastFieldmilliGauss = BitConverter.ToInt32(data, 25);
|
|
result.ImpedanceI = BitConverter.ToInt32(data, 29); // in phase
|
|
result.ImpedanceQ = BitConverter.ToInt32(data, 33); // out of phase
|
|
result.NoiseMetric = BitConverter.ToInt32(data, 37); //
|
|
result.LearningLockout = BitConverter.ToInt16(data, 41);
|
|
result.ReverseBuffer = BitConverter.ToInt16(data, 43);
|
|
result.ConditionedAdc = BitConverter.ToInt32(data, 45);
|
|
result.Totalalizer = BitConverter.ToUInt32(data, 49);
|
|
|
|
return result;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"C7: LastFieldmilliGauss={LastFieldmilliGauss}, ImpedanceI={ImpedanceI}, ImpedanceQ={ImpedanceQ}, NoiseMetric={NoiseMetric}, LearningLockout={LearningLockout}, ReverseBuffer={ReverseBuffer}, ConditionedAdc={ConditionedAdc}, Totalalizer={Totalalizer}, MagTamperState={MagTamperState}, IsLearningActive={IsLearningActive}, AdcShiftsUpdated={AdcShiftsUpdated}" + base.ToString();
|
|
}
|
|
}
|
|
}
|