CUST: - FwUpdateSw: - start implementation of power correction - 3
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts
|
||||
{
|
||||
/// <summary>
|
||||
/// Power correction constants
|
||||
/// </summary>
|
||||
public static class PowCorrConst
|
||||
{
|
||||
/// <summary>
|
||||
/// Threshold for power correction EMEA version
|
||||
/// </summary>
|
||||
public const UInt32 EmeaFwThresholdForPowCorr = 0x1300;
|
||||
/// <summary>
|
||||
/// Threshold for power correction NA version
|
||||
/// </summary>
|
||||
public const UInt32 NaFNaFwThresholdForPowCorr = 0x2006;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum region radio current NA
|
||||
/// </summary>
|
||||
public const Double MinNaCurrent_uA = 119;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum region radio current sensus radio RF mode EMEA
|
||||
/// </summary>
|
||||
public const Double MinEmeaRadioRfModeCurrent_uA = 136;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum region radio current sensus radio TFX mode EMEA
|
||||
/// </summary>
|
||||
public const Double MinEmeaRadioTfxModeCurrent_uA = 155;
|
||||
|
||||
/// <summary>
|
||||
/// Fixed current in production if production values are not logged in DB
|
||||
/// and dispatched as 0 or null.
|
||||
/// </summary>
|
||||
public const Double FixProductionCurrent_uA = 160;
|
||||
|
||||
/// <summary>
|
||||
/// Fixed region radio current NA
|
||||
/// </summary>
|
||||
public const Double FixNaCurrent_uA = 132;
|
||||
|
||||
/// <summary>
|
||||
/// Fixed region radio current sensus radio RF mode EMEA
|
||||
/// </summary>
|
||||
public const Double PulseReportLengthEstimate_uA = 45.453;
|
||||
|
||||
/// <summary>
|
||||
/// Fixed region radio current sensus radio RF mode EMEA
|
||||
/// </summary>
|
||||
public const Double FixEmeaRadioRfModeCurrent_uA = 153;
|
||||
|
||||
/// <summary>
|
||||
/// Fixed region radio current sensus radio TFX mode EMEA
|
||||
/// </summary>
|
||||
public const Double FixEmeaRadioTfxModeCurrent_uA = 174;
|
||||
|
||||
/// <summary>
|
||||
/// Pulse report length for pulse mode 1 to 4 even distribution 0
|
||||
/// </summary>
|
||||
public const UInt32 PulseReportLengthMode1To4Even0 = 8;
|
||||
|
||||
/// <summary>
|
||||
/// Pulse report length for pulse mode 1 to 4 even distribution 1
|
||||
/// </summary>
|
||||
public const UInt32 PulseReportLengthMode1To4Even1 = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Pulse report length for pulse mode 5 to 6 even distribution 0
|
||||
/// </summary>
|
||||
public const UInt32 PulseReportLengthMode5To6Even0 = 6;
|
||||
|
||||
/// <summary>
|
||||
/// Pulse report length for pulse mode 5 to 6 even distribution 1
|
||||
/// </summary>
|
||||
public const UInt32 PulseReportLengthMode5To6Even1 = 8;
|
||||
|
||||
/// <summary>
|
||||
/// TFX mode mask of sensus radio system state
|
||||
/// </summary>
|
||||
public const Byte SensusRadioSystemStateTfXModeMask = 0x20;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,8 @@
|
||||
<Compile Include="..\..\..\..\.shared\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Consts\PowCorrConst.cs" />
|
||||
<Compile Include="PowerCorrectionCalc.cs" />
|
||||
<Compile Include="PowerCorrection.cs" />
|
||||
<Compile Include="Consts\ErrorState.cs" />
|
||||
<Compile Include="Consts\LedMode.cs" />
|
||||
|
||||
@@ -57,20 +57,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
public Boolean ProductionPulseEvenDistribution { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Threshold for power correction EMEA version
|
||||
/// </summary>
|
||||
public const UInt32 EmeaFwThresholdForPowCorr = 0x1300;
|
||||
/// <summary>
|
||||
/// Threshold for power correction NA version
|
||||
/// </summary>
|
||||
public const UInt32 NaFNaFwThresholdForPowCorr = 0x2006;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maintenance readout
|
||||
|
||||
/// <summary>
|
||||
@@ -108,11 +94,21 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// </summary>
|
||||
public Byte ActualPulseMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse sequence counter during maintenance
|
||||
/// </summary>
|
||||
public Byte ActualPulseSequenceCounter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Pulse distribution during maintenance
|
||||
/// </summary>
|
||||
public Boolean ActualPulseEvenDistribution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Detected pulse adapter during maintenance
|
||||
/// </summary>
|
||||
public Boolean PulseAdapterAutoDetected { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maintenance calculation
|
||||
@@ -130,13 +126,18 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// <summary>
|
||||
/// Total used seconds after EOL and before maintenance
|
||||
/// </summary>
|
||||
public UInt32 AfterProductionTotalUsedSeconds_s { get; set; }
|
||||
public UInt32 PostProductionTotalUsedSeconds_s { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Overestimated total used charge before maintenance
|
||||
/// </summary>
|
||||
public UInt64 OverestimatedTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Based on fixed estimation total used charge before maintenance
|
||||
/// </summary>
|
||||
public UInt64 FixedEstimateTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Lowest threshold for total used charge calculated during maintenance
|
||||
/// </summary>
|
||||
@@ -145,17 +146,19 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// <summary>
|
||||
/// Corrected total used charge during maintenance
|
||||
/// </summary>
|
||||
public UInt64 CorrectedTotalUsedCharge_uAs { get; set; }
|
||||
public UInt64? CorrectedTotalUsedCharge_uAs { get; set; }
|
||||
|
||||
#endregion
|
||||
#region File header
|
||||
/// <summary>
|
||||
/// Size of power correction file
|
||||
/// </summary>
|
||||
public UInt32 MeterPowerCorrectionFileSize { get; set; }
|
||||
public UInt16 MeterPowerCorrectionFileSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CRC of power correction file
|
||||
/// </summary>
|
||||
public UInt32 MeterPowerCorrectionCRC { get; set; }
|
||||
public UInt16 MeterPowerCorrectionCRC { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
/// <summary>
|
||||
/// Read of required registers and calculation of power correction
|
||||
/// </summary>
|
||||
public class PowerCorrectionCalc
|
||||
{
|
||||
private readonly GenesisMeter _currentGenesis;
|
||||
private readonly PowerCorrection _powCorr;
|
||||
|
||||
/// <summary>
|
||||
/// Ctor
|
||||
/// </summary>
|
||||
/// <param name="currentGenesis"></param>
|
||||
/// <param name="powCorr"></param>
|
||||
/// <returns>true if successful</returns>
|
||||
public PowerCorrectionCalc(GenesisMeter currentGenesis, PowerCorrection powCorr)
|
||||
{
|
||||
_currentGenesis = currentGenesis;
|
||||
_powCorr = powCorr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the values for power correction
|
||||
/// </summary>
|
||||
/// <returns>true if successful</returns>
|
||||
public Boolean PowerCorrEstimation()
|
||||
{
|
||||
if (_currentGenesis == null || _powCorr == null)
|
||||
return false;
|
||||
|
||||
var logOnReminder = _currentGenesis.IsLoggedOn;
|
||||
var retVal = _currentGenesis.ReLogin();
|
||||
if (retVal)
|
||||
{
|
||||
_powCorr.CorrectedTotalUsedCharge_uAs = null;
|
||||
// read registers
|
||||
_powCorr.ActualPulseSequenceCounter = RegisterConverter.ByteArrayToValue<Byte>(
|
||||
_currentGenesis.ReadRegister("IRDA_PulseSequence"));
|
||||
_powCorr.ActualPulseMode = RegisterConverter.ByteArrayToValue<Byte>(
|
||||
_currentGenesis.ReadRegister("METROLOGYASST_PulseMode"));
|
||||
_powCorr.ActualTotalUsedCharge_uAs = RegisterConverter.ByteArrayToValue<UInt64>(
|
||||
_currentGenesis.ReadRegister("POWERMON_TotalUsedCharge"));
|
||||
_powCorr.ActualTotalUsedSeconds_s = RegisterConverter.ByteArrayToValue<UInt32>(
|
||||
_currentGenesis.ReadRegister("POWERMON_TotalUsedSeconds"));
|
||||
_powCorr.ActualRadioSystemState = RegisterConverter.ByteArrayToValue<Byte>(
|
||||
_currentGenesis.ReadRegister("SENSUSRADIO_SystemState"));
|
||||
_powCorr.ActualPulseEvenDistribution = RegisterConverter.ByteArrayToValue<Boolean>(
|
||||
_currentGenesis.ReadRegister("METROLOGYASST_PulseEvenDistribution"));
|
||||
|
||||
// get actual time from PC
|
||||
_powCorr.ActualDateTimeUtc = DateTime.UtcNow;
|
||||
|
||||
// skip if all pulse modes indicate that a pulse adapter never has been installed
|
||||
if (_powCorr.ActualPulseMode == 0 && _powCorr.ProductionPulseMode == 0)
|
||||
return true;
|
||||
|
||||
// calculate pulse report length
|
||||
if (_powCorr.ActualPulseMode >= 1 && _powCorr.ActualPulseMode <= 4)
|
||||
{
|
||||
_powCorr.PulseReportLength = PowCorrConst.PulseReportLengthMode1To4Even0;
|
||||
if (_powCorr.ActualPulseEvenDistribution)
|
||||
_powCorr.PulseReportLength = PowCorrConst.PulseReportLengthMode1To4Even1;
|
||||
}
|
||||
else if (_powCorr.ActualPulseMode >= 5 && _powCorr.ActualPulseMode <= 6)
|
||||
{
|
||||
_powCorr.PulseReportLength = PowCorrConst.PulseReportLengthMode5To6Even0;
|
||||
if (_powCorr.ActualPulseEvenDistribution)
|
||||
_powCorr.PulseReportLength = PowCorrConst.PulseReportLengthMode5To6Even1;
|
||||
}
|
||||
|
||||
// calculate overestimation
|
||||
if (_powCorr.ActualPulseMode >= 1 && _powCorr.ActualPulseMode <= 6)
|
||||
{
|
||||
if (_powCorr.ProductionTotalUsedSeconds_s > _powCorr.ActualTotalUsedSeconds_s)
|
||||
_powCorr.PostProductionTotalUsedSeconds_s = _powCorr.ActualTotalUsedSeconds_s;
|
||||
else
|
||||
_powCorr.PostProductionTotalUsedSeconds_s = _powCorr.ActualTotalUsedSeconds_s -
|
||||
_powCorr.ProductionTotalUsedSeconds_s;
|
||||
_powCorr.OverestimatedTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.PulseReportLength * PowCorrConst.PulseReportLengthEstimate_uA *
|
||||
_powCorr.PostProductionTotalUsedSeconds_s);
|
||||
|
||||
Byte radioSystemState = 0;
|
||||
if (_powCorr.ActualRadioSystemState != null)
|
||||
{
|
||||
radioSystemState = (Byte)_powCorr.ActualRadioSystemState;
|
||||
}
|
||||
|
||||
if (_currentGenesis.Region == "NA")
|
||||
{
|
||||
_powCorr.MinimumTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.ActualTotalUsedSeconds_s * PowCorrConst.MinNaCurrent_uA);
|
||||
_powCorr.FixedEstimateTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.ActualTotalUsedSeconds_s * PowCorrConst.FixNaCurrent_uA);
|
||||
}
|
||||
else if (_currentGenesis.Region == "EMEA" &&
|
||||
(radioSystemState & PowCorrConst.SensusRadioSystemStateTfXModeMask) ==
|
||||
PowCorrConst.SensusRadioSystemStateTfXModeMask)
|
||||
{
|
||||
_powCorr.MinimumTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.ActualTotalUsedSeconds_s * PowCorrConst.MinEmeaRadioTfxModeCurrent_uA);
|
||||
_powCorr.FixedEstimateTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.ActualTotalUsedSeconds_s * PowCorrConst.FixEmeaRadioTfxModeCurrent_uA);
|
||||
}
|
||||
else if (_currentGenesis.Region == "EMEA" &&
|
||||
(radioSystemState & PowCorrConst.SensusRadioSystemStateTfXModeMask) !=
|
||||
PowCorrConst.SensusRadioSystemStateTfXModeMask)
|
||||
{
|
||||
_powCorr.MinimumTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.ActualTotalUsedSeconds_s * PowCorrConst.MinEmeaRadioRfModeCurrent_uA);
|
||||
_powCorr.FixedEstimateTotalUsedCharge_uAs =
|
||||
(UInt64)(_powCorr.ActualTotalUsedSeconds_s * PowCorrConst.FixEmeaRadioRfModeCurrent_uA);
|
||||
}
|
||||
|
||||
if (_powCorr.OverestimatedTotalUsedCharge_uAs > _powCorr.ActualTotalUsedCharge_uAs)
|
||||
_powCorr.CorrectedTotalUsedCharge_uAs = 0;
|
||||
else
|
||||
_powCorr.CorrectedTotalUsedCharge_uAs = _powCorr.ActualTotalUsedCharge_uAs -
|
||||
_powCorr.OverestimatedTotalUsedCharge_uAs;
|
||||
}
|
||||
}
|
||||
|
||||
if (!logOnReminder)
|
||||
_currentGenesis.Logout();
|
||||
return retVal;
|
||||
}
|
||||
/// <summary>
|
||||
/// Calculate the values for power correction
|
||||
/// </summary>
|
||||
/// <returns>true if successful</returns>
|
||||
public Boolean CorrectPowerConsumption()
|
||||
{
|
||||
if (_currentGenesis == null || _powCorr == null || _powCorr.CorrectedTotalUsedCharge_uAs == null)
|
||||
return false;
|
||||
|
||||
// check which value should be applied and set the CorrectedTotalUsedCharge_uAs
|
||||
if (_powCorr.ProductionPulseAdapterIsInstalled)
|
||||
{
|
||||
// avoid undershot below smallest value
|
||||
if (_powCorr.CorrectedTotalUsedCharge_uAs < _powCorr.MinimumTotalUsedCharge_uAs)
|
||||
_powCorr.CorrectedTotalUsedCharge_uAs = _powCorr.MinimumTotalUsedCharge_uAs;
|
||||
}
|
||||
else // retrofitted
|
||||
{
|
||||
// correct to smaller value and mark corrected = actual to log that correction not needed
|
||||
_powCorr.CorrectedTotalUsedCharge_uAs =
|
||||
_powCorr.ActualTotalUsedCharge_uAs > _powCorr.FixedEstimateTotalUsedCharge_uAs ?
|
||||
_powCorr.FixedEstimateTotalUsedCharge_uAs : _powCorr.ActualTotalUsedCharge_uAs;
|
||||
}
|
||||
|
||||
if (_powCorr.ActualTotalUsedCharge_uAs == _powCorr.CorrectedTotalUsedCharge_uAs)
|
||||
return true;
|
||||
|
||||
// save corrected power consumption data to meter
|
||||
var logOnReminder = _currentGenesis.IsLoggedOn;
|
||||
var retVal = _currentGenesis.ReLogin();
|
||||
if (retVal)
|
||||
{
|
||||
var retriesLeft = 2;
|
||||
do
|
||||
{
|
||||
// write the new calculated value
|
||||
retVal = _currentGenesis.WriteRegister(Register.Powermon.BatteryDrainedLoad,
|
||||
RegisterConverter.ValueToByteArray(_powCorr.CorrectedTotalUsedCharge_uAs));
|
||||
if (!retVal)
|
||||
continue;
|
||||
|
||||
// store configuration
|
||||
retVal = _currentGenesis.WriteRegister(Register.Powermon.StoreConfiguration, 1);
|
||||
if (!retVal)
|
||||
continue;
|
||||
|
||||
var readResult = _currentGenesis.ReadRegister(Register.Powermon.StoreConfiguration);
|
||||
retVal = readResult != null && readResult.ToList().All(array => array == 0x00);
|
||||
} while (!retVal && retriesLeft-- > 0);
|
||||
}
|
||||
|
||||
if (!logOnReminder)
|
||||
_currentGenesis.Logout();
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Properties;
|
||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||
using Xylem.Common.Utils.Crc16Ccitt;
|
||||
|
||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
{
|
||||
@@ -17,24 +21,78 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
|
||||
private readonly GenesisMeter _currentGenesis;
|
||||
private readonly MeterFile _meterFile;
|
||||
private const Int32 MeterPwrCorrFileLengthIndex = 0;
|
||||
private const Int32 MeterPwrCorrFileLengthSize = 2;
|
||||
private const Int32 MeterPwrCorrFileCrcIndex = MeterPwrCorrFileLengthIndex + MeterPwrCorrFileLengthSize;
|
||||
private const Int32 MeterPwrCorrFileCrcSize= 2;
|
||||
private const Int32 MeterPwrCorrFileDataIndex = MeterPwrCorrFileCrcIndex + MeterPwrCorrFileCrcSize;
|
||||
|
||||
private List<Byte>_meterBinData = new List<Byte>{0x5A};
|
||||
// position of data in binary data of meter powcorr file
|
||||
// file information
|
||||
private const Int32 FileLengthIdx = 0;
|
||||
private const Int32 FileLengthSize = sizeof(UInt16);
|
||||
|
||||
private const Int32 FileCrcIdx = FileLengthIdx + FileLengthSize;
|
||||
private const Int32 FileCrcSize = sizeof(UInt16);
|
||||
|
||||
private const Int32 FileDataIdx = FileCrcIdx + FileCrcSize;
|
||||
private const Int32 FileHeaderSize = FileLengthSize + FileCrcSize;
|
||||
|
||||
// common data size
|
||||
private const Int32 ChargeSize = sizeof(UInt64);
|
||||
private const Int32 TimeSize = sizeof(UInt32);
|
||||
private const Int32 FwVersionSize = sizeof(UInt32);
|
||||
private const Int32 RadioStateSize = sizeof(Byte);
|
||||
private const Int32 PulseAdaptInstalledSize = sizeof(Boolean);
|
||||
private const Int32 PulseModeSize = sizeof(Byte);
|
||||
private const Int32 PulseSequenceCtrSize = sizeof(Byte);
|
||||
private const Int32 PulseEvenDistributionSize = sizeof(Boolean);
|
||||
|
||||
// production data
|
||||
private const Int32 ProdTimeIdx = FileDataIdx;
|
||||
private const Int32 ProdChargeIdx = ProdTimeIdx + TimeSize;
|
||||
private const Int32 ProdRadioStateIdx = ProdChargeIdx + ChargeSize;
|
||||
private const Int32 ProdPulseAdaptInstalledIdx = ProdRadioStateIdx + RadioStateSize;
|
||||
private const Int32 ProdPulseModeIdx = ProdPulseAdaptInstalledIdx + PulseAdaptInstalledSize;
|
||||
private const Int32 ProdPulseSequenceCtrIdx = ProdPulseModeIdx + PulseModeSize;
|
||||
private const Int32 ProdPulseEvenDistributionIdx = ProdPulseSequenceCtrIdx + PulseSequenceCtrSize;
|
||||
|
||||
// field data
|
||||
private const Int32 FieldFwVersionIdx = ProdPulseEvenDistributionIdx + PulseEvenDistributionSize;
|
||||
private const Int32 FieldTimeIdx = FieldFwVersionIdx + FwVersionSize;
|
||||
private const Int32 FieldChargeIdx = FieldTimeIdx + TimeSize;
|
||||
private const Int32 FieldRadioStateIdx = FieldChargeIdx + ChargeSize;
|
||||
private const Int32 FieldPulseAdaptInstalledIdx = FieldRadioStateIdx + RadioStateSize;
|
||||
private const Int32 FieldPulseModeIdx = FieldPulseAdaptInstalledIdx + PulseAdaptInstalledSize;
|
||||
private const Int32 FieldPulseSequenceCtrIdx = FieldPulseModeIdx + PulseModeSize;
|
||||
private const Int32 FieldPulseEvenDistributionIdx = FieldPulseSequenceCtrIdx + PulseSequenceCtrSize;
|
||||
|
||||
private const Int32 FieldPulseAdapterAutoDetectedIdx = FieldPulseEvenDistributionIdx + PulseEvenDistributionSize;
|
||||
private const Int32 FieldPulseAdapterAutoDetectedSize = sizeof(Boolean);
|
||||
// calculated
|
||||
private const Int32 RequiredFwVersionIdx = FieldPulseAdapterAutoDetectedIdx + FieldPulseAdapterAutoDetectedSize;
|
||||
private const Int32 CalcPulseReportLengthIdx = RequiredFwVersionIdx + FwVersionSize;
|
||||
private const Int32 CalcPulseReportLengthSize = sizeof(UInt32);
|
||||
|
||||
private const Int32 CalcPostProdChargeIdx = CalcPulseReportLengthIdx + CalcPulseReportLengthSize;
|
||||
private const Int32 CalcOverestimatedChargeIdx = CalcPostProdChargeIdx + ChargeSize;
|
||||
private const Int32 CalcFixedEstimatedChargeIdx = CalcOverestimatedChargeIdx + ChargeSize;
|
||||
private const Int32 CalcMinimumChargeIdx = CalcFixedEstimatedChargeIdx + ChargeSize;
|
||||
private const Int32 CalcCorrectedChargeIdx = CalcMinimumChargeIdx + ChargeSize;
|
||||
|
||||
// estimate file size
|
||||
private const Int32 FileSize = CalcCorrectedChargeIdx + ChargeSize;
|
||||
|
||||
// raw data
|
||||
private Byte[] _meterBinData = new Byte[FileSize];
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Content of power correction file
|
||||
/// Content of power correction meter file
|
||||
/// </summary>
|
||||
public List<String>PowCorrFileContent = new List<String>();
|
||||
public List<String> FileContent = new List<String>();
|
||||
|
||||
/// <summary>
|
||||
/// Power correction data.
|
||||
/// </summary>
|
||||
public PowerCorrection PowerCorrectionData { get; set; }
|
||||
public PowerCorrection PowerCorrectionData
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ctor
|
||||
@@ -61,38 +119,163 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
if (_currentGenesis == null || _meterFile == null)
|
||||
return false;
|
||||
|
||||
var loginReminder = _currentGenesis.IsLoggedOn;
|
||||
var retVal = _currentGenesis.ReLogin();
|
||||
if (retVal)
|
||||
try
|
||||
{
|
||||
PowCorrFileContent.Clear();
|
||||
retVal = _meterFile.ReadMeterFile(StrMeterPowCorrFileName, out _meterBinData);
|
||||
|
||||
// Build a string list of recorded data
|
||||
var loginReminder = _currentGenesis.IsLoggedOn;
|
||||
var retVal = _currentGenesis.ReLogin();
|
||||
if (retVal)
|
||||
{
|
||||
retVal = BuildStringListOfPowCorrFileContent();
|
||||
FileContent.Clear();
|
||||
retVal = _meterFile.ReadMeterFile(StrMeterPowCorrFileName, out var meterBinDataList);
|
||||
_meterBinData = meterBinDataList.ToArray();
|
||||
// Build a string list of recorded data
|
||||
if (retVal)
|
||||
{
|
||||
retVal = BuildStringListOfPowCorrFileContent();
|
||||
}
|
||||
}
|
||||
|
||||
if (!loginReminder)
|
||||
_currentGenesis.Logout();
|
||||
return retVal;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loginReminder) _currentGenesis.Logout();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a string list of logged power correction file content.
|
||||
/// </summary>
|
||||
/// <returns>true: file found</returns>
|
||||
/// <remarks date="2024-May-08" author="Thomas Wiedebusch">
|
||||
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public Boolean BuildStringListOfPowCorrFileContent()
|
||||
private Boolean BuildStringListOfPowCorrFileContent()
|
||||
{
|
||||
if (_meterBinData == null || _meterBinData.Count == 0)
|
||||
if (_meterBinData == null || _meterBinData.Length == 0)
|
||||
return false;
|
||||
|
||||
String str;
|
||||
FileContent.Clear();
|
||||
FileContent.Add(Resources.StrPowCorrFileInfo);
|
||||
FileContent.Add(Resources.StrPowCorrFactoryValues);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy byte arrays
|
||||
/// </summary>
|
||||
/// <param name="destination"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="startIdx"></param>
|
||||
/// <param name="size"></param>
|
||||
/// <returns></returns>
|
||||
private Boolean CopyByteArray(Byte[] destination, Byte[] source, Int32 startIdx, Int32 size)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var c = 0; c < size; c++)
|
||||
{
|
||||
destination[startIdx + c] = source[c];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Build the binary data as preparation before sending those to the meter file.
|
||||
/// </summary>
|
||||
/// <returns>true: success</returns>
|
||||
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
private Boolean BuildBinData()
|
||||
{
|
||||
if (PowerCorrectionData == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (_meterBinData == null)
|
||||
_meterBinData = new Byte[FileSize];
|
||||
|
||||
var pc = PowerCorrectionData;
|
||||
|
||||
// production
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionTotalUsedSeconds_s),
|
||||
ProdTimeIdx, TimeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionTotalUsedCharge_uAs),
|
||||
ProdChargeIdx, ChargeSize);
|
||||
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionRadioSystemState),
|
||||
ProdRadioStateIdx, RadioStateSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionPulseAdapterIsInstalled),
|
||||
ProdPulseAdaptInstalledIdx, PulseAdaptInstalledSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionPulseMode),
|
||||
ProdPulseModeIdx, PulseModeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionPulseSequenceCounter),
|
||||
ProdPulseSequenceCtrIdx, PulseSequenceCtrSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ProductionPulseEvenDistribution),
|
||||
ProdPulseEvenDistributionIdx, PulseEvenDistributionSize);
|
||||
|
||||
// field
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualFwVersion),
|
||||
FieldFwVersionIdx, FwVersionSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualTotalUsedSeconds_s),
|
||||
FieldTimeIdx, TimeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualTotalUsedCharge_uAs),
|
||||
FieldChargeIdx, ChargeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualRadioSystemState),
|
||||
FieldRadioStateIdx, RadioStateSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualPulseAdapterIsInstalled),
|
||||
FieldPulseAdaptInstalledIdx, PulseAdaptInstalledSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualPulseMode),
|
||||
FieldPulseModeIdx, PulseModeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualPulseSequenceCounter),
|
||||
FieldPulseSequenceCtrIdx, PulseSequenceCtrSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualPulseEvenDistribution),
|
||||
FieldPulseEvenDistributionIdx, PulseEvenDistributionSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.PulseAdapterAutoDetected),
|
||||
FieldPulseAdapterAutoDetectedIdx, FieldPulseAdapterAutoDetectedSize);
|
||||
|
||||
// calculations
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.RequiredFwVersion),
|
||||
RequiredFwVersionIdx, FwVersionSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.PulseReportLength),
|
||||
CalcPulseReportLengthIdx, CalcPulseReportLengthSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.PostProductionTotalUsedSeconds_s),
|
||||
CalcPostProdChargeIdx, ChargeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.OverestimatedTotalUsedCharge_uAs),
|
||||
CalcOverestimatedChargeIdx, ChargeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.FixedEstimateTotalUsedCharge_uAs),
|
||||
CalcFixedEstimatedChargeIdx, ChargeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.MinimumTotalUsedCharge_uAs),
|
||||
CalcMinimumChargeIdx, ChargeSize);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.CorrectedTotalUsedCharge_uAs),
|
||||
CalcCorrectedChargeIdx, ChargeSize);
|
||||
|
||||
// add file information
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(FileSize), FileLengthIdx, FileLengthSize);
|
||||
var crc = Crc16Ccitt.CalculateReversedLsb8408(_meterBinData);
|
||||
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(crc), FileCrcIdx, FileCrcSize);
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write the meter power correction file.
|
||||
/// </summary>
|
||||
@@ -104,6 +287,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
{
|
||||
if (_currentGenesis == null || _meterFile == null)
|
||||
return false;
|
||||
if (!BuildBinData())
|
||||
return false;
|
||||
BuildStringListOfPowCorrFileContent();
|
||||
|
||||
var loginReminder = _currentGenesis.IsLoggedOn;
|
||||
var retVal = _currentGenesis.ReLogin();
|
||||
@@ -113,7 +299,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
retVal = _meterFile.WriteMeterFile(StrMeterPowCorrFileName, _meterBinData.ToArray());
|
||||
}
|
||||
|
||||
if (!loginReminder) _currentGenesis.Logout();
|
||||
if (!loginReminder)
|
||||
_currentGenesis.Logout();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
+144
@@ -222,6 +222,150 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Field data.
|
||||
/// </summary>
|
||||
public static string StrPowCorrActualValues {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrActualValues", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Total used charge [uA/s].
|
||||
/// </summary>
|
||||
public static string StrPowCorrCharge_uA_per_s {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrCharge_uA_per_s", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Corrected charge [uA/s].
|
||||
/// </summary>
|
||||
public static string StrPowCorrCorrectedCharge_uAs {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrCorrectedCharge_uAs", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Date and time [UTC].
|
||||
/// </summary>
|
||||
public static string StrPowCorrDateTime {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrDateTime", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Factory data.
|
||||
/// </summary>
|
||||
public static string StrPowCorrFactoryValues {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrFactoryValues", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Powercorrection file info.
|
||||
/// </summary>
|
||||
public static string StrPowCorrFileInfo {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrFileInfo", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Fixed estimate charge [uAs].
|
||||
/// </summary>
|
||||
public static string StrPowCorrFixedEstimateCharge_uAs {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrFixedEstimateCharge_uAs", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to FW version.
|
||||
/// </summary>
|
||||
public static string StrPowCorrFwVersion {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrFwVersion", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Overestimated charge [uA/s].
|
||||
/// </summary>
|
||||
public static string StrPowCorrOverestimate_uAs {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrOverestimate_uAs", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Overestimate minimal limit [uA/s].
|
||||
/// </summary>
|
||||
public static string StrPowCorrOverestimateLimit {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrOverestimateLimit", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pulse adapter installed.
|
||||
/// </summary>
|
||||
public static string StrPowCorrPulseAdapterInstallationState {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrPulseAdapterInstallationState", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pulse even distribution.
|
||||
/// </summary>
|
||||
public static string StrPowCorrPulseEvenDistribution {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrPulseEvenDistribution", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pulse mode.
|
||||
/// </summary>
|
||||
public static string StrPowCorrPulseMode {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrPulseMode", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pulse sequence counter.
|
||||
/// </summary>
|
||||
public static string StrPowCorrPulseSequenceCounter {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrPulseSequenceCounter", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Radio system state.
|
||||
/// </summary>
|
||||
public static string StrPowCorrRadioSystemState {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrRadioSystemState", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Total used seconds [s since 01.01.2000 00:00:00 UTC].
|
||||
/// </summary>
|
||||
public static string StrPowCorrTime_s {
|
||||
get {
|
||||
return ResourceManager.GetString("StrPowCorrTime_s", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Download.
|
||||
/// </summary>
|
||||
|
||||
@@ -189,4 +189,52 @@
|
||||
<data name="StrEraseTstFile" xml:space="preserve">
|
||||
<value>Lösche Testdatei</value>
|
||||
</data>
|
||||
<data name="StrPowCorrActualValues" xml:space="preserve">
|
||||
<value>Field data</value>
|
||||
</data>
|
||||
<data name="StrPowCorrCharge_uA_per_s" xml:space="preserve">
|
||||
<value>Verbrauchte Ladung [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrCorrectedCharge_uAs" xml:space="preserve">
|
||||
<value>Korrigierter Ladungsverbrauch [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrDateTime" xml:space="preserve">
|
||||
<value>Datum und Zeit [UTC]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFactoryValues" xml:space="preserve">
|
||||
<value>Fabrikationsdaten</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFileInfo" xml:space="preserve">
|
||||
<value>Dateiinformation Verbrauchskorrektur</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFixedEstimateCharge_uAs" xml:space="preserve">
|
||||
<value>Konstantladungsverbrauch [uAs]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFwVersion" xml:space="preserve">
|
||||
<value>FW Version</value>
|
||||
</data>
|
||||
<data name="StrPowCorrOverestimateLimit" xml:space="preserve">
|
||||
<value>Ladungsverbrauchsgrenze [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrOverestimate_uAs" xml:space="preserve">
|
||||
<value>Zu hoher Ladungsverbrauch [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseAdapterInstallationState" xml:space="preserve">
|
||||
<value>Pulsadapterinstallationsstatus</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseEvenDistribution" xml:space="preserve">
|
||||
<value>Pulsverteilung</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseMode" xml:space="preserve">
|
||||
<value>Pulsmodus</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseSequenceCounter" xml:space="preserve">
|
||||
<value>Pulssequenzzähler</value>
|
||||
</data>
|
||||
<data name="StrPowCorrRadioSystemState" xml:space="preserve">
|
||||
<value>Funksystemstatus</value>
|
||||
</data>
|
||||
<data name="StrPowCorrTime_s" xml:space="preserve">
|
||||
<value>Laufzeit [s seit 01.01.2000 00:00:00 UTC]</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -189,4 +189,52 @@
|
||||
<data name="StrEraseTstFile" xml:space="preserve">
|
||||
<value>Erase test file</value>
|
||||
</data>
|
||||
<data name="StrPowCorrActualValues" xml:space="preserve">
|
||||
<value>Field data</value>
|
||||
</data>
|
||||
<data name="StrPowCorrCharge_uA_per_s" xml:space="preserve">
|
||||
<value>Total used charge [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrCorrectedCharge_uAs" xml:space="preserve">
|
||||
<value>Corrected charge [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrDateTime" xml:space="preserve">
|
||||
<value>Date and time [UTC]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFactoryValues" xml:space="preserve">
|
||||
<value>Factory data</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFileInfo" xml:space="preserve">
|
||||
<value>Powercorrection file info</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFixedEstimateCharge_uAs" xml:space="preserve">
|
||||
<value>Fixed estimate charge [uAs]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrFwVersion" xml:space="preserve">
|
||||
<value>FW version</value>
|
||||
</data>
|
||||
<data name="StrPowCorrOverestimateLimit" xml:space="preserve">
|
||||
<value>Overestimate minimal limit [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrOverestimate_uAs" xml:space="preserve">
|
||||
<value>Overestimated charge [uA/s]</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseAdapterInstallationState" xml:space="preserve">
|
||||
<value>Pulse adapter installed</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseEvenDistribution" xml:space="preserve">
|
||||
<value>Pulse even distribution</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseMode" xml:space="preserve">
|
||||
<value>Pulse mode</value>
|
||||
</data>
|
||||
<data name="StrPowCorrPulseSequenceCounter" xml:space="preserve">
|
||||
<value>Pulse sequence counter</value>
|
||||
</data>
|
||||
<data name="StrPowCorrRadioSystemState" xml:space="preserve">
|
||||
<value>Radio system state</value>
|
||||
</data>
|
||||
<data name="StrPowCorrTime_s" xml:space="preserve">
|
||||
<value>Total used seconds [s since 01.01.2000 00:00:00 UTC]</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user