GTB: - Power correction readout to low level tools

This commit is contained in:
Thomas Wiedebusch 2024-05-15 08:33:31 +02:00
parent 7fd095ee40
commit 5bd0108540
8 changed files with 124 additions and 59 deletions

View File

@ -194,6 +194,14 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// </summary>
private Boolean _enableRawDataLogging;
/// <summary>
/// Detected pulse adapter communication on request port
/// </summary>
public Boolean PulseAdapterAutoDetected
{
set;
get;
}
/// <summary>
/// Enable use of registers that are not valid (last version not match the current app)

View File

@ -70,12 +70,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
public DateTime? ActualDateTimeUtc { get; set; }
/// <summary>
/// Total used seconds before maintenance
/// Total used seconds of entire runtime
/// </summary>
public UInt32 ActualTotalUsedSeconds_s { get; set; }
/// <summary>
/// Total used charge of batteries before maintenance
/// Total used charge of batteries of entire runtime
/// </summary>
public UInt64 ActualTotalUsedCharge_uAs { get; set; }
@ -104,11 +104,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// </summary>
public Boolean ActualPulseEvenDistribution { get; set; }
/// <summary>
/// Detected pulse adapter during maintenance
/// </summary>
public Boolean PulseAdapterAutoDetected { get; set; }
/// <summary>
/// Mark pulse adapter as installed on any detected or sequence counted
/// </summary>

View File

@ -65,7 +65,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
// skip if indicated that a pulse adapter never has been installed
_powCorr.PulseAdapterMarkedAsInstalled =
_powCorr.ProductionPulseAdapterIsInstalled ||
_powCorr.PulseAdapterAutoDetected ||
_powCorr.ActualPulseAdapterIsInstalled ||
_powCorr.ActualPulseSequenceCounter != _powCorr.ProductionPulseSequenceCounter;
if (!_powCorr.PulseAdapterMarkedAsInstalled)

View File

@ -64,10 +64,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
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 RequiredFwVersionIdx = FieldPulseEvenDistributionIdx + PulseEvenDistributionSize;
private const Int32 CalcPulseReportLengthIdx = RequiredFwVersionIdx + FwVersionSize;
private const Int32 CalcPulseReportLengthSize = sizeof(UInt32);
@ -226,7 +224,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
if (CopyByteArray(value_u8a = new Byte[PulseAdaptInstalledSize], bin, PulseAdaptInstalledSize, 0,
FieldPulseAdaptInstalledIdx))
fc.Add(Resources.StrPowCorrPulseAdapterInstallationState +
fc.Add(Resources.StrPowCorrPulseAdapterAutoDetected +
$": {RegisterConverter.ConvertToText(value_u8a, typeof(Boolean))}");
if (CopyByteArray(value_u8a = new Byte[PulseModeSize], bin, PulseModeSize, 0, FieldPulseModeIdx))
@ -243,11 +241,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
fc.Add(Resources.StrPowCorrPulseEvenDistribution +
$": {RegisterConverter.ConvertToText(value_u8a, typeof(Boolean))}");
if (CopyByteArray(value_u8a = new Byte[PulseEvenDistributionSize], bin, FieldPulseAdapterAutoDetectedSize,
0, FieldPulseAdapterAutoDetectedIdx))
fc.Add(Resources.StrPowCorrPulseAdapterAutoDetected +
$": {RegisterConverter.ConvertToText(value_u8a, typeof(Boolean))}");
fc.Add(Resources.StrPowCorrOldFwVersion + $": {_currentGenesis.FwVersion}");
if (CopyByteArray(value_u8a = new Byte[FwVersionSize], bin, FwVersionSize, 0, RequiredFwVersionIdx))
@ -379,9 +372,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.ActualPulseEvenDistribution),
PulseEvenDistributionSize, FieldPulseEvenDistributionIdx);
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.PulseAdapterAutoDetected),
FieldPulseAdapterAutoDetectedSize, FieldPulseAdapterAutoDetectedIdx);
// calculations
CopyByteArray(_meterBinData, RegisterConverter.ValueToByteArray(pc.RequiredFwVersion),
FwVersionSize, RequiredFwVersionIdx);

View File

@ -1 +1 @@
bf6bb8fceb3db5a9977dadc407cf576684bf7127
8fbe991b217e7692af4817ad205b768685aa5a72

View File

@ -81,6 +81,7 @@
this.label3 = new System.Windows.Forms.Label();
this.tbxFileToEraseDrive = new System.Windows.Forms.TextBox();
this.btnEraseFile = new System.Windows.Forms.Button();
this.btnReadPowCorr = new System.Windows.Forms.Button();
this.grpSetup.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox1.SuspendLayout();
@ -489,6 +490,7 @@
//
// groupBox2
//
this.groupBox2.Controls.Add(this.btnReadPowCorr);
this.groupBox2.Controls.Add(this.btnUploadPWFile);
this.groupBox2.Controls.Add(this.ddlLocation);
this.groupBox2.Controls.Add(this.btnReadBatAndLog);
@ -508,7 +510,7 @@
this.btnUploadPWFile.Name = "btnUploadPWFile";
this.btnUploadPWFile.Size = new System.Drawing.Size(116, 25);
this.btnUploadPWFile.TabIndex = 42;
this.btnUploadPWFile.Text = "Upload PWD";
this.btnUploadPWFile.Text = "Upload Pwd File";
this.btnUploadPWFile.UseVisualStyleBackColor = true;
this.btnUploadPWFile.Click += new System.EventHandler(this.btnUploadPWFile_Click);
//
@ -617,6 +619,16 @@
this.btnEraseFile.UseVisualStyleBackColor = true;
this.btnEraseFile.Click += new System.EventHandler(this.btnEraseFile_Click);
//
// btnReadPowCorr
//
this.btnReadPowCorr.Location = new System.Drawing.Point(10, 175);
this.btnReadPowCorr.Name = "btnReadPowCorr";
this.btnReadPowCorr.Size = new System.Drawing.Size(116, 25);
this.btnReadPowCorr.TabIndex = 43;
this.btnReadPowCorr.Text = "Read Power Corr";
this.btnReadPowCorr.UseVisualStyleBackColor = true;
this.btnReadPowCorr.Click += new System.EventHandler(this.btnReadPowCorr_Click);
//
// FrmLowLevelTools
//
this.AccessibleRole = System.Windows.Forms.AccessibleRole.Sound;
@ -714,5 +726,6 @@
private System.Windows.Forms.ComboBox ddlLocation;
private System.Windows.Forms.Button btnReadBatAndLog;
private System.Windows.Forms.Button btnUploadPWFile;
private System.Windows.Forms.Button btnReadPowCorr;
}
}

View File

@ -40,6 +40,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
private const String StrBurnUpgrade = "Waiting for meter response";
private MeterFile _meterFile;
private MeterPowerCorrectionFile _meterPowCorrFile;
//private String _lastFwUpdateState;
//private Int32 _lastSingleProgress;
@ -153,6 +154,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// </summary>
private void DisableToolButtons()
{
btnReadPowCorr.Enabled = false;
btnPulseModeOff.Enabled = false;
btnClearDisplay.Enabled = false;
btnSetDateTime.Enabled = false;
@ -176,6 +178,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// </summary>
private void EnableToolButtons()
{
btnReadPowCorr.Enabled = true;
btnPulseModeOff.Enabled = true;
btnClearDisplay.Enabled = true;
btnSetDateTime.Enabled = true;
@ -831,7 +834,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
LogText($"Count: {count}", logFileName);
LogText($"Extra data size: {extraDataSize}", logFileName);
//avoid access beyond the buffer and check for data to display
if (ctr + 5 + extraDataSize < data.Count && extraDataSize > 0)
@ -840,12 +843,12 @@ namespace Xylem.Common.Ui.GenesisToolBox
LogText($"Extra data: {ByteArrayStyle.ByteStyler.ToString(extraData.ToArray())}", logFileName);
if (status == 261)
{
rawDic.Add(new Tuple<string,string>(fileName, ByteArrayStyle.ByteStyler.ToString(extraData.ToArray())));
rawDic.Add(new Tuple<string, string>(fileName, ByteArrayStyle.ByteStyler.ToString(extraData.ToArray())));
}
}
LogText("", logFileName);
ctr += (5 + extraDataSize);
@ -876,9 +879,9 @@ namespace Xylem.Common.Ui.GenesisToolBox
sb.AppendLine($"{dt};{rawBat.Item2}");
}
File.AppendAllLines(logFileName+ "BAT.CSV", new[] { sb.ToString() });
File.AppendAllLines(logFileName + "BAT.CSV", new[] { sb.ToString() });
}).ContinueWith(delegate
{
//add a blank line to separate next operation
@ -1299,10 +1302,56 @@ namespace Xylem.Common.Ui.GenesisToolBox
});
}
/// <summary>
/// Read power correction information.
/// </summary>
/// <remarks date="2024-May-15" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
private void btnReadPowCorr_Click(Object sender, EventArgs e)
{
if (_currentGenesis == null)
{
return;
}
if (_meterPowCorrFile == null)
{
_meterPowCorrFile = new MeterPowerCorrectionFile(_currentGenesis);
}
//reset timer
_startTime = DateTimeOffset.UtcNow;
LowLevelActionControl(true);
var msg = @"Upload power correction file from meter";
LogText(msg);
lblOverall.Text = msg;
lblActualProcess.Text = @"Read power correction file";
Task.Factory.StartNew(() =>
{
_currentGenesis.ReLogin();
_meterPowCorrFile.ReadPowCorrMeterFile();
foreach (var line in _meterPowCorrFile.FileContent)
{
LogText(line);
}
}).ContinueWith(delegate
{
//add a blank line to separate next operation
LogText("");
_currentGenesis.Logout();
LowLevelActionControl(false);
});
}
/// <summary>
/// Read config file from meter and store it to disk.
/// </summary>
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
/// <remarks date="2024-Jan-?" author="Roland Drabesch">
/// - Initial
/// </remarks>
private void btnUploadPWFile_Click(Object sender, EventArgs e)
@ -1323,10 +1372,10 @@ namespace Xylem.Common.Ui.GenesisToolBox
LowLevelActionControl(true);
var msg = @"Upload configuration file from meter";
var msg = @"Upload password file from meter";
LogText(msg);
lblOverall.Text = msg;
lblActualProcess.Text = @"Read config file";
lblActualProcess.Text = @"Read password file";
var rawData = new List<Byte>();
@ -1440,7 +1489,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
/// <summary>
/// Read engineering log files from meter and analyzes the contents.
/// Cpllect life time information and production status.
/// </summary>
/// <remarks date="2023-Jan-04" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial
@ -1498,32 +1547,37 @@ namespace Xylem.Common.Ui.GenesisToolBox
ReadLogFiles(filename);
var resp = LocalWebRequest.GetRequest($"http://10.49.40.25/MeterProcessState/api/FinalCheck/GetKitronProductionResults?PcbID={_currentGenesis.PcbId}", 8000);
LogText(resp, filename);
var sbRegister = new StringBuilder();
var Ledmode = RegisterConverter.ByteArrayToValue<UInt16>(_currentGenesis.ReadRegister("GENESISFLOW_LedMode"));
var SampleRate = RegisterConverter.ByteArrayToValue<UInt16>(_currentGenesis.ReadRegister("GENESISFLOW_SampleRate"));
sbRegister.AppendLine($"LedMode is {Ledmode}");
sbRegister.AppendLine($"SampelRate is {SampleRate}");
if (Ledmode != 0)
try
{
_currentGenesis.WriteRegister("GENESISFLOW_LedMode", 0);
sbRegister.AppendLine($"Change Led mode to Customermode (0)");
var resp = LocalWebRequest.GetRequest($"http://10.49.40.25/MeterProcessState/api/FinalCheck/GetKitronProductionResults?PcbID={_currentGenesis.PcbId}", 8000);
LogText(resp, filename);
var sbRegister = new StringBuilder();
var Ledmode = RegisterConverter.ByteArrayToValue<UInt16>(_currentGenesis.ReadRegister("GENESISFLOW_LedMode"));
var SampleRate = RegisterConverter.ByteArrayToValue<UInt16>(_currentGenesis.ReadRegister("GENESISFLOW_SampleRate"));
sbRegister.AppendLine($"LedMode is {Ledmode}");
sbRegister.AppendLine($"SampelRate is {SampleRate}");
if (Ledmode != 0)
{
_currentGenesis.WriteRegister("GENESISFLOW_LedMode", 0);
sbRegister.AppendLine($"Change Led mode to Customermode (0)");
}
if (SampleRate != 2)
{
_currentGenesis.WriteRegister("GENESISFLOW_SampleRate", 2);
sbRegister.AppendLine($"Change SampleRate mode to Customermode (2)");
}
}
if (SampleRate != 2)
catch (Exception exception)
{
_currentGenesis.WriteRegister("GENESISFLOW_SampleRate", 2);
sbRegister.AppendLine($"Change SampleRate mode to Customermode (2)");
_currentGenesis.WriteLog(exception.Message);
}
}

View File

@ -1460,12 +1460,16 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
_fwUpdatePowerCorrection = new PowerCorrection();
}
// fill all infos to meter power correction file
// fill all currently known infos to power correction
_fwUpdatePowerCorrection.ActualPulseAdapterIsInstalled = _currentGenesis.PulseAdapterAutoDetected;
_fwUpdatePowerCorrection.ActualFwVersion = _currentGenesis.InstalledFwVersion;
_fwUpdatePowerCorrection.RequiredFwVersion = (UInt32?)_cordonelFirmwarePackage.FwPackageInfo.Version;
// preset meter power correction file
powCorrFile.PowerCorrectionData = _fwUpdatePowerCorrection;
// calculate the power correction
// estimate the power correction values which includes the pulse adapter installation marker and
// the readout of Cordonel registers to get the actual status
var powCorrCalc = new PowerCorrectionCalc(_currentGenesis, _fwUpdatePowerCorrection);
var retVal = powCorrCalc.PowerCorrEstimation();
if (retVal)
@ -1488,21 +1492,22 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
}
}
// one step of the power correction execution failed
if (!retVal)
{
InfoProcessFailed(null, Resources.StrPowerCorrectionFailed);
_processState = errorExitState;
return;
}
}
else
}// check for region and required FW version threshold
else // power correction mustn't be performed as the jump in version is not given
{
InfoProcessSuccess(null, Resources.StrPowerCorrectionNotNeeded);
_processState = successExitState;
return;
}
// log
// log result of successfully executed power correction
LogStringList(Resources.StrPowerCorrection, powCorrFile.FileContent,
Resources.StrPowerCorrectionSucceeded);
_processState = successExitState;