CUST: - FwUpdateSw: - start implementation of power correction - 3

This commit is contained in:
Thomas Wiedebusch
2024-05-13 17:53:30 +02:00
parent 7341e520c2
commit 49bdaf80fe
17 changed files with 1008 additions and 105 deletions
@@ -20,6 +20,7 @@ using Xylem.Common.CommonCore.ThreadWatcher;
using Xylem.Common.Cryptology.Security;
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile;
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
using Xylem.Common.Logic.ProductionOrderCore.FW;
@@ -1457,11 +1458,11 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
// for the decision of needed power correction.
if (_fwUpdatePackage.FwPackageInfo.Version != null && cordonelDeviceInfo.InstalledFwVersion != null
&& ((_fwUpdatePackage.FwPackageInfo.Region ==
"EMEA" && _fwUpdatePackage.FwPackageInfo.Version >= PowerCorrection.EmeaFwThresholdForPowCorr
&& cordonelDeviceInfo.InstalledFwVersion < PowerCorrection.EmeaFwThresholdForPowCorr)
"EMEA" && _fwUpdatePackage.FwPackageInfo.Version >= PowCorrConst.EmeaFwThresholdForPowCorr
&& cordonelDeviceInfo.InstalledFwVersion < PowCorrConst.EmeaFwThresholdForPowCorr)
|| (_fwUpdatePackage.FwPackageInfo.Region ==
"NA" && _fwUpdatePackage.FwPackageInfo.Version >= PowerCorrection.NaFNaFwThresholdForPowCorr
&& cordonelDeviceInfo.InstalledFwVersion < PowerCorrection.NaFNaFwThresholdForPowCorr)))
"NA" && _fwUpdatePackage.FwPackageInfo.Version >= PowCorrConst.NaFNaFwThresholdForPowCorr
&& cordonelDeviceInfo.InstalledFwVersion < PowCorrConst.NaFNaFwThresholdForPowCorr)))
{
fwUpdateCapability.PowerCorrectionNotNeededOrLoaded = GetPowerCorrectionsFromDb(cordonelDeviceInfo);
}
@@ -2488,9 +2489,12 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2021-Apr-14" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void DisableControlsExceptLanguageInvoked()
{
UiInvoker.ControlEnableInvoker(grpLanguageSelection, true);
UiInvoker.ControlEnableInvoker(grpLanguageSelection, false);
UiInvoker.ControlEnableInvoker(btnBuildFwUpdateSafe, false);
UiInvoker.ControlEnableInvoker(btnUploadSafeToDb, false);
@@ -2511,11 +2515,14 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2021-Apr-14" author="Thomas Wiedebusch">
/// - Avoid activation on unchecked license.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void EnableInputsInvoked()
{
if (_licenseUnchecked || _regUser == null || !_regUser.AccountActive)
return;
UiInvoker.ControlEnableInvoker(grpLanguageSelection, true);
UiInvoker.ControlEnableInvoker(grpLanguageSelection, false);
UiInvoker.ControlEnableInvoker(lblFwUpdateDutyDate, true);
UiInvoker.ControlEnableInvoker(tbxOrderNumber, true);
UiInvoker.ControlEnableInvoker(tbxOrderPosition, true);
@@ -3114,6 +3121,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2022-Dec-01" author="Thomas Wiedebusch">
/// - FW package information from DB used.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithFwPackageInfos()
{
grpLanguageSelection.Enabled = false;
@@ -3212,7 +3222,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
#endregion --------------------------------------- Data Grid FW Packages ---------------------------------------
@@ -3230,6 +3240,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2022-Jun-30" author="Thomas Wiedebusch">
/// - CHanged date time field to string with yyyy-MM-dd to make it sortable.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithFwUpdateSafesInfos()
{
grpLanguageSelection.Enabled = false;
@@ -3310,28 +3323,10 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
///// <summary>
///// Color the rows depending on the state
///// </summary>
///// <remarks date="2021-Oct-30" author="Thomas Wiedebusch">
///// - Initial.
///// </remarks>
//private void FwUpdateSafesInfosStyleSet()
//{
// Thread.CurrentThread.CurrentUICulture = _cultureInfo;
// Thread.CurrentThread.CurrentCulture = _cultureInfo;
// foreach (DataGridViewRow dataGridRow in gridViewFwUpdateSafeSelection.Rows)
// {
// dataGridRow.DefaultCellStyle = DateTimeServer.GetDateTimeOffsetFromDateString(
// dataGridRow.Cells[Resources.StrTableUserValidDate].Value.ToString()) >= DateTimeOffset.Now ?
// _styleValid : _styleInvalid;
// }
//}
#endregion --------------------------------------- Data Grid Update Safes --------------------------------------
#region ------------------------------------------ Data Grid Report Files -------------------------------------
@@ -3403,6 +3398,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2022-Jun-30" author="Thomas Wiedebusch">
/// - CHanged date time field to string with yyyy-MM-dd to make it sortable.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithReportsInfos()
{
grpLanguageSelection.Enabled = false;
@@ -3466,7 +3464,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
@@ -3707,6 +3705,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2023-Oct-08" author="Thomas Wiedebusch">
/// - Selector for register restore.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithPreBuildSummaryInfos()
{
grpLanguageSelection.Enabled = false;
@@ -3818,7 +3819,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
@@ -4150,6 +4151,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2023-Oct-08" author="Thomas Wiedebusch">
/// - Selector for register restore.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithCordonelInfos()
{
grpLanguageSelection.Enabled = false;
@@ -4238,7 +4242,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
#endregion --------------------------------------- Data Grid Cordonels ----------------------------------------
@@ -4402,6 +4406,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2021-Apr-12" author="Thomas Wiedebusch">
/// - Registration and valid date to date time.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithUpdateOperatorInfos()
{
grpLanguageSelection.Enabled = false;
@@ -4456,7 +4463,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
@@ -4622,6 +4629,9 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
/// <remarks date="2021-Jun-08" author="Thomas Wiedebusch">
/// - Initially sorted by name.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void FillDataGridWithCustomerInfos()
{
grpLanguageSelection.Enabled = false;
@@ -4668,7 +4678,7 @@ namespace Xylem.ServiceFwUpdate.Ui.FwUpdateBuilder
}
finally
{
grpLanguageSelection.Enabled = true;
grpLanguageSelection.Enabled = false;
}
}
@@ -19,6 +19,7 @@ using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications;
using Xylem.Common.Hardware.WaterMeter.Genesis.Applications.Const;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus;
@@ -740,6 +741,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// - Changed timer to System.Threading.Timer as System.Windows.Forms.Timer does not operate if called as DLL
/// from the FW-Update Loader and the FW-Update Loader uses System.Windows.Forms.Timer.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Culture info fixed to English.
/// </remarks>
public FrmServiceFwUpdateSw()
{
_logger = NLogHelper.CreateOrGetLogger("ServiceFwUpdateSw");
@@ -761,6 +765,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
radioBtnGermanLanguage.Checked = true;
}
// switch always to English
RadioBtnEnglishLanguage_Click(this, null);
SetDesktopLocation(0, 0);
lblFwUpdateInfo.Text = $@"Version: {_version.Major}.{_version.Minor}.{_version.Build}";
@@ -822,6 +829,9 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2021-Mar-02" author="Thomas Wiedebusch">
/// - Removed button settings.
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void ResetAllStatusLabels()
{
Thread.CurrentThread.CurrentUICulture = _cultureInfo;
@@ -832,6 +842,8 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
UiInvoker.ControlInvoker(lblConnectPcb, ColorProcessFailed, Resources.StrNotConnected);
UiInvoker.ControlViewInvoker(lblProductToInstall, false);
UiInvoker.ControlEnableInvoker(grpLanguageSelection, false);
InfoStatusUnknown(lblUpdateInformationStatus, Resources.StrUpdateInformationStatusUnspecified);
InfoStatusUnknown(lblCordonelUpdateCapability, Resources.StrCordonelUpdateCapabilityUnspecified);
InfoStatusUnknown(lblRegisterReadout, Resources.StrRegisterReadoutUnspecified);
@@ -1393,15 +1405,15 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <summary>
/// Correct power overestimation at FW change from
/// <see cref="PowerCorrection.EmeaFwThresholdForPowCorr"/>,
/// <see cref="PowerCorrection.NaFNaFwThresholdForPowCorr"/>.
/// <see cref="PowCorrConst.EmeaFwThresholdForPowCorr"/>,
/// <see cref="PowCorrConst.NaFNaFwThresholdForPowCorr"/>.
/// Precondition:
/// Meter registers have to be read in advance,
/// Meter files have to be read in advance.
/// </summary>
/// <param name="successExitState"></param>
/// <param name="errorExitState"></param>
/// <remarks date="2024-May-08..11" author="Thomas Wiedebusch">
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
private void CorrectPowerOverestimation(ProcessState successExitState,
@@ -1423,11 +1435,10 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
// Check if file "1\\powcorr" is in meter
if (_readMeterFiles.Any(f => f.Contains(MeterPowerCorrectionFile.StrMeterPowCorrFileName)))
{
// read the powCorrFile
// read the powCorrFile and build a string list of the file content
powCorrFile.ReadPowCorrMeterFile();
LogStringList(Resources.StrPowerCorrection, powCorrFile.PowCorrFileContent,
Resources.StrPowerCorrectionSucceeded);
InfoProcessSuccess(null, Resources.StrPowerCorrectionNotNeeded);
LogStringList(Resources.StrPowerCorrection, powCorrFile.FileContent,
Resources.StrPowerCorrectionNotNeeded);
_processState = successExitState;
return;
}
@@ -1436,40 +1447,54 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
// power calculation:
// Check required versus installed FW versions and threshold version for power correction
if ((_currentGenesis.Region == "EMEA" &&
_cordonelFirmwarePackage.FwPackageInfo.Version >= PowerCorrection.EmeaFwThresholdForPowCorr &&
_currentGenesis.InstalledFwVersion < PowerCorrection.EmeaFwThresholdForPowCorr) ||
_cordonelFirmwarePackage.FwPackageInfo.Version >= PowCorrConst.EmeaFwThresholdForPowCorr &&
_currentGenesis.InstalledFwVersion < PowCorrConst.EmeaFwThresholdForPowCorr) ||
(_currentGenesis.Region == "NA" &&
_cordonelFirmwarePackage.FwPackageInfo.Version >= PowerCorrection.NaFNaFwThresholdForPowCorr &&
_currentGenesis.InstalledFwVersion < PowerCorrection.NaFNaFwThresholdForPowCorr))
_cordonelFirmwarePackage.FwPackageInfo.Version >= PowCorrConst.NaFNaFwThresholdForPowCorr &&
_currentGenesis.InstalledFwVersion < PowCorrConst.NaFNaFwThresholdForPowCorr))
{
var applyAlgorithm1 = true;
// CASE 2.1: Missing power correction settings from FW update package
if (_fwUpdatePowerCorrection == null)
{
applyAlgorithm1 = false;
//do something
_fwUpdatePowerCorrection = new PowerCorrection();
}
// calculate the power correction
if (applyAlgorithm1)
{
}
else
{
}
// correct the total used seconds
// fill all infos to meter power correction file
_fwUpdatePowerCorrection.ActualFwVersion = _currentGenesis.InstalledFwVersion;
_fwUpdatePowerCorrection.RequiredFwVersion = (UInt32?)_cordonelFirmwarePackage.FwPackageInfo.Version;
powCorrFile.PowerCorrectionData = _fwUpdatePowerCorrection;
// store results to "1\\powcorr" in the meter
powCorrFile.WritePowCorrMeterFile();
// calculate the power correction
var powCorrCalc = new PowerCorrectionCalc(_currentGenesis, _fwUpdatePowerCorrection);
var retVal = powCorrCalc.PowerCorrEstimation();
if (retVal)
{
// pulse mode was switched off, skip power correction
if (_fwUpdatePowerCorrection.ProductionPulseMode == 0 &&
_fwUpdatePowerCorrection.ActualPulseMode == 0)
{
InfoProcessSuccess(null, Resources.StrPowerCorrectionNotNeeded);
_processState = successExitState;
return;
}
// correct the total used charge in meter including store configuration
retVal = powCorrCalc.CorrectPowerConsumption();
if (retVal)
{
// store results to "1\\powcorr" in the meter
powCorrFile.WritePowCorrMeterFile();
}
}
if (!retVal)
{
InfoProcessFailed(null, Resources.StrPowerCorrectionFailed);
_processState = errorExitState;
return;
}
}
else
{
@@ -1479,7 +1504,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
}
// log
LogStringList(Resources.StrPowerCorrection, powCorrFile.PowCorrFileContent,
LogStringList(Resources.StrPowerCorrection, powCorrFile.FileContent,
Resources.StrPowerCorrectionSucceeded);
_processState = successExitState;
}
@@ -1877,6 +1902,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
{
var xPosition = Location.X + Size.Width;
var yPosition = Location.Y;
if (_frmHistory == null)
return;
if (_frmHistory.Visible)
@@ -2694,9 +2720,12 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2021-Feb-25" author="Thomas Wiedebusch">
/// - Used UiInvoker
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void SetControlDownloadEnable()
{
UiInvoker.ControlEnableInvoker(grpLanguageSelection, true);
UiInvoker.ControlEnableInvoker(grpLanguageSelection, false);
UiInvoker.ControlEnableInvoker(btnStop, false);
UiInvoker.ControlEnableInvoker(btnReleaseDisplay, true);
UiInvoker.ControlEnableInvoker(btnPortScan, true);
@@ -2714,9 +2743,12 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
/// <remarks date="2023-Feb-22" author="Thomas Wiedebusch">
/// - Enable "release Display" if Cordonel is connected
/// </remarks>
/// <remarks date="2024-May-13" author="Thomas Wiedebusch">
/// - Disabled language selection, culture info fixed to english.
/// </remarks>
private void SetDisableDownloadAndEnableConnect()
{
UiInvoker.ControlEnableInvoker(grpLanguageSelection, true);
UiInvoker.ControlEnableInvoker(grpLanguageSelection, false);
UiInvoker.ControlEnableInvoker(btnStop, false);
// if the FwVersion is set, the password is valid and a login was performed in advance to read it
if (_currentGenesis != null
@@ -388,7 +388,7 @@
<value>True</value>
</data>
<data name="lblUpdateTime.Location" type="System.Drawing.Point, System.Drawing">
<value>416, 2</value>
<value>415, 2</value>
</data>
<data name="lblUpdateTime.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>3, 0, 3, 3</value>
@@ -421,7 +421,7 @@
<value>True</value>
</data>
<data name="label9.Location" type="System.Drawing.Point, System.Drawing">
<value>310, 2</value>
<value>309, 2</value>
</data>
<data name="label9.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>0, 0, 0, 3</value>
@@ -1038,6 +1038,9 @@
<data name="grpLanguageSelection.Text" xml:space="preserve">
<value>Language</value>
</data>
<data name="grpLanguageSelection.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="&gt;&gt;grpLanguageSelection.Name" xml:space="preserve">
<value>grpLanguageSelection</value>
</data>
@@ -1630,7 +1633,7 @@
<value>0</value>
</data>
<data name="tableLayoutPanel3.LayoutSettings" type="System.Windows.Forms.TableLayoutSettings, System.Windows.Forms">
<value>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TableLayoutSettings&gt;&lt;Controls&gt;&lt;Control Name="lblUpdateTime" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /&gt;&lt;Control Name="lblActualProcess" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /&gt;&lt;Control Name="lblWaitingForMeterResponse" Row="0" RowSpan="1" Column="3" ColumnSpan="1" /&gt;&lt;Control Name="label9" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;/Controls&gt;&lt;Columns Styles="Percent,72,48804,Percent,27,51196,Absolute,48,Absolute,411" /&gt;&lt;Rows Styles="Percent,100,Absolute,18" /&gt;&lt;/TableLayoutSettings&gt;</value>
<value>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;TableLayoutSettings&gt;&lt;Controls&gt;&lt;Control Name="lblUpdateTime" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /&gt;&lt;Control Name="lblActualProcess" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /&gt;&lt;Control Name="lblWaitingForMeterResponse" Row="0" RowSpan="1" Column="3" ColumnSpan="1" /&gt;&lt;Control Name="label9" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /&gt;&lt;/Controls&gt;&lt;Columns Styles="Percent,72,48804,Percent,27,51196,Absolute,48,Absolute,412" /&gt;&lt;Rows Styles="Percent,100,Absolute,18" /&gt;&lt;/TableLayoutSettings&gt;</value>
</data>
<data name="tableLayoutPanel2.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Bottom</value>