using Logic.ProductionToProductMapper.Files.Fw; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using Logic.ProductionToProductMapper.Cordonel; using Xylem.Common.CommonCore.Configuration; 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.GenesisFile; using Xylem.Common.Hardware.WaterMeter.Genesis.Registers; using Xylem.Common.Hardware.WaterMeter.WaterMeterCore; using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts; using Xylem.Common.Logic.ProductionOrderCore.FW; using Xylem.Common.Logic.SoftwareAccessHelper; using Xylem.Common.Ui.GenesisToolBox.Properties; namespace Xylem.Common.Ui.GenesisToolBox { /// /// FW update form /// public partial class FrmFwUpdate : Form { #region Variables private readonly MeterBatch _meterBatch = new MeterBatch(); private GenesisMeter _currentGenesis; private const String StrConnecting = "Connecting to PCB"; private const String StrNotConnected = "NOT CONNECTED"; private const String StrCoreRevision = "System Core Revision: "; private const String StrPartPcbConnected = "Connected to PCB ID: "; private const String StrFileAppsLoaded = "ABC loaded"; private const String StrUpdatePathEmpty = "No update files in path"; private const String StrPackageFileLoaded = "ADF loaded"; private const String StrPackageFileInvalid = "ADF invalid"; private const String StrPackageFileToFileAppsMismatch = "ADF to ABC mismatch"; private const String StrBurnUpgrade = "Waiting for meter response"; private const String StrOverallProcess = "Overall Process"; private readonly DataTable _dataTable = new DataTable(); //data grid table header private const String StrAppName = "AppName"; private const String StrAppId = "AppId"; private const String StrMeterVersion = "MeterVersion"; private const String StrMeterCrc = "MeterCrc"; private const String StrFileVersion = "FileVersion"; private const String StrFileCrc = "FileCrc"; private const String StrFileSize = "FileSize [kB]"; private const String StrUpdate = "Download"; private const String StrErase = "Erase"; private const String StrStatus = "Status"; private readonly DataGridViewCellStyle _styleInstalled = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleNotInstalled = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleInvalidMeterCrc = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleUpdateRequired = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleDownloadSucceeded = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleDownloadFailed = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleDownloadOngoing = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleValidated = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleVerificationRequired = new DataGridViewCellStyle(); private readonly DataGridViewCellStyle _styleEraseRequired = new DataGridViewCellStyle(); private Boolean _updateGui = true; private MeterFwUpdate _meterFwUpdate; private String _lastFwUpdateState; private Int32 _lastSingleProgress; private DateTimeOffset _startTime; private Boolean _resetTimeMeasurement; private static String DefaultBinaryPath { get => Settings.Default.InitialBinaryPath; set { Settings.Default.InitialBinaryPath = value; Settings.Default.Save(); } } private static String DefaultPackageFile { get => Settings.Default.InitialPackageFile; set { Settings.Default.InitialPackageFile = value; Settings.Default.Save(); } } private Boolean _fileAppsSuccessfulWritten; private Boolean _tryConnectPcb; private Boolean _packageFileToFileAppsValidated; private const String StrUpdateErrorMessageManualControl = "FW UPDATE FAILED!\n\n" + "TIP1: Press [Update FW] button for next trial,\n " + "this keeps all downloaded files without new download\n" + "\nor\n" + "TIP2: Demarcate largest or failed file and press [Update FW],\n" + "this keeps all other downloaded files without new download.\n" + "Download of demarcated file separately!\n" + "\nor\n" + "TIP3: Press [Connect] and select large files separately!\n" + "This is a stepwise update, proceed until update is completed!\n"; private const String StrUpdateErrorMessage = "FW UPDATE FAILED!\n\n"; private FwSource fwSource = FwSource.File; private enum FwSource { File, Production, Db, } #endregion #region FormControls /// /// Ctor FW update /// public FrmFwUpdate() { InitializeComponent(); var cultureInfo = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentUICulture = cultureInfo; Thread.CurrentThread.CurrentCulture = cultureInfo; } /// /// Clear data table and set genesis to not connected /// private void Init() { ProcessViewControl(false); lblConnectPcb.Text = StrNotConnected; lblCoreRevision.Text = ""; lblConnectPcb.ForeColor = Color.Red; lblWaitingForMeterResponse.Visible = false; btnConnect.Enabled = true; btnUpdateFw.ForeColor = Color.DarkGreen; btnStopFwUpdate.ForeColor = Color.Red; SetControlDownloadsLocked(); btnStopFwUpdate.Enabled = false; btnOpenUpdateDirectory.Enabled = true; btnOpenPackageControlFile.Enabled = true; cbFilePartSize.Enabled = true; CheckManualControl(); if (_meterFwUpdate != null) { _meterFwUpdate.SingleFilePartsRetryEnable = cbxSingleFilePartsRetryEnable.Checked; _meterFwUpdate.ConsecutiveFilePartsRetryEnable = cbxConsecutiveFilePartsRetryEnable.Checked; } _dataTable.Rows.Clear(); } private void FrmFwUpdate_Load(Object sender, EventArgs e) { _styleInstalled.BackColor = Color.White; _styleInstalled.ForeColor = Color.Black; _styleNotInstalled.BackColor = Color.LightGray; _styleNotInstalled.ForeColor = Color.Black; _styleInvalidMeterCrc.BackColor = Color.White; _styleInvalidMeterCrc.ForeColor = Color.Purple; _styleUpdateRequired.BackColor = Color.White; _styleUpdateRequired.ForeColor = Color.Red; _styleEraseRequired.BackColor = Color.LightGray; _styleEraseRequired.ForeColor = Color.Black; _styleDownloadOngoing.BackColor = Color.GreenYellow; _styleDownloadOngoing.ForeColor = Color.Black; _styleValidated.BackColor = Color.White; _styleValidated.ForeColor = Color.Green; _styleDownloadSucceeded.BackColor = Color.LightGreen; _styleDownloadSucceeded.ForeColor = Color.Green; _styleDownloadFailed.BackColor = Color.LightPink; _styleDownloadFailed.ForeColor = Color.Red; _styleVerificationRequired.BackColor = Color.LightGoldenrodYellow; _styleVerificationRequired.ForeColor = Color.Green; _dataTable.Columns.Add(StrAppName, typeof(String)); _dataTable.Columns.Add(StrAppId, typeof(String)); _dataTable.Columns.Add(StrMeterVersion, typeof(String)); _dataTable.Columns.Add(StrMeterCrc, typeof(String)); _dataTable.Columns.Add(StrFileVersion, typeof(String)); _dataTable.Columns.Add(StrFileCrc, typeof(String)); _dataTable.Columns.Add(StrFileSize, typeof(String)); _dataTable.Columns.Add(StrUpdate, typeof(Boolean)); _dataTable.Columns.Add(StrErase, typeof(Boolean)); _dataTable.Columns.Add(StrStatus, typeof(String)); var version = Assembly.GetExecutingAssembly().GetName().Version; lblFwUpdateInfo.Text = $@"Version: {version.Major}.{version.Minor}.{version.Build}"; _resetTimeMeasurement = true; Init(); } private void FrmFwUpdate_FormClosing(Object sender, FormClosingEventArgs e) { _currentGenesis?.Logout(); _meterBatch?.RemoveAllMeters(); _meterBatch?.Dispose(); _meterFwUpdate?.Dispose(); _meterFwUpdate = null; Dispose(); } private void cbComSlot_SelectedIndexChanged(Object sender, EventArgs e) { _resetTimeMeasurement = true; Init(); } #endregion #region DataGridControls /// /// Build data grid and fill it with meter and file information, /// compare version and CRC of meter and file /// private void FillDataGridWithAllInfos() { _dataTable.Rows.Clear(); if (_currentGenesis == null) { return; } foreach (var meterApp in _currentGenesis.MeterAppListVersion) { var row = _dataTable.NewRow(); //application information read from configuration row[StrAppName] = meterApp.AppName; row[StrAppId] = MeterFwUpdate.ConvertAppIdToString(meterApp.AppId); _dataTable.Rows.Add(row); } //output data to data grid view gridViewApplic.DataSource = _dataTable.DefaultView; foreach (DataRow dataRow in _dataTable.Rows) { DisplayFileAppInfo(dataRow); DisplayMeterAppInfo(dataRow); } foreach (DataGridViewColumn column in gridViewApplic.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } //color the results of the compare UpdateInformationStyleSet(); } /// /// Set meter application information to data grid view /// /// private void DisplayMeterAppInfo(DataRow dataRow) { if (_currentGenesis == null) { return; } var meterStateAppInfo = new MeterAppStateInfo(); foreach (var meterApp in _currentGenesis.MeterAppListVersion) { var appId = dataRow[StrAppId].ToString(); if (appId != MeterFwUpdate.ConvertAppIdToString(meterApp.AppId)) { continue; } dataRow[StrUpdate] = meterApp.Update; dataRow[StrErase] = meterApp.Erase; dataRow[StrStatus] = meterStateAppInfo.GetTextFromState(meterApp.Status); dataRow[StrMeterVersion] = meterApp.StrVersion; dataRow[StrMeterCrc] = meterApp.IsInstalled ? MeterFwUpdate.ConvertCrcToString(meterApp.Crc) : ""; } } /// /// Set file application information to data grid view. /// /// private void DisplayFileAppInfo(DataRow dataRow) { if (_currentGenesis == null || _meterFwUpdate?.FileApps == null) { return; } foreach (var meterApp in _currentGenesis.MeterAppListVersion) { var appId = dataRow[StrAppId].ToString(); if (appId != MeterFwUpdate.ConvertAppIdToString(meterApp.AppId)) { continue; } foreach (var fileApp in _meterFwUpdate.FileApps) { if (meterApp.AppId != fileApp.AppId) { continue; } dataRow[StrFileVersion] = fileApp.StrVersion; dataRow[StrFileCrc] = MeterFwUpdate.ConvertCrcToString(fileApp.Crc); dataRow[StrFileSize] = $"{(Double)fileApp.BinData.Count / 1024:0.000}"; } } } /// /// Display the update information /// private void UpdateInformationStyleSet() { if (_meterFwUpdate == null) return; foreach (DataGridViewRow dataGridRow in gridViewApplic.Rows) { var testString = dataGridRow.Cells[StrStatus].Value.ToString(); //var meterAppState = MeterAppState.MeterAppNotInstalled; var meterAppStateInfo = new MeterAppStateInfo(); //if (testString == "" && dataGridRow.Cells[StrMeterVersion].Value.ToString() == "") //{ // //dataGridRow.Cells[StrStatus].Value = meterAppStateInfo.GetTextFromState(meterAppState); // //dataGridRow.Cells[StrStatus].Value = MeterAppStateInfo.GetTextFromState(meterAppState); //} var meterAppState = meterAppStateInfo.GetStateFromText(testString); //meterAppState = MeterAppStateInfo.GetStateFromText(testString); switch (meterAppState) { case MeterAppState.MeterAppUpToDate: dataGridRow.DefaultCellStyle = _styleValidated; break; case MeterAppState.MeterAppInstallationRequired: dataGridRow.DefaultCellStyle = _styleUpdateRequired; break; case MeterAppState.FileAppInvalid: dataGridRow.DefaultCellStyle = _styleDownloadOngoing; break; case MeterAppState.MeterAppVersionOutdated: dataGridRow.DefaultCellStyle = _styleUpdateRequired; break; case MeterAppState.MeterAppNotInstalled: dataGridRow.DefaultCellStyle = _styleNotInstalled; break; case MeterAppState.InvalidCrc: dataGridRow.DefaultCellStyle = _styleInvalidMeterCrc; break; case MeterAppState.MeterAppErasureRequired: dataGridRow.DefaultCellStyle = _styleEraseRequired; break; case MeterAppState.MeterAppDownloadSucceeded: dataGridRow.DefaultCellStyle = _styleDownloadSucceeded; break; case MeterAppState.MeterAppDownloadSuspicious: dataGridRow.DefaultCellStyle = _styleVerificationRequired; break; case MeterAppState.MeterAppSuccessfulErased: dataGridRow.DefaultCellStyle = _styleDownloadSucceeded; break; case MeterAppState.MeterAppSuccessfulUpdated: dataGridRow.DefaultCellStyle = _styleDownloadSucceeded; break; case MeterAppState.MeterAppDownloadFailed: dataGridRow.DefaultCellStyle = _styleDownloadFailed; break; case MeterAppState.MeterAppDownloadActive: dataGridRow.DefaultCellStyle = _styleDownloadOngoing; break; default: dataGridRow.DefaultCellStyle = _styleNotInstalled; break; } } //foreach (DataGridViewRow dataGridRow in gridViewApplic.Rows) //{ // var testString = dataGridRow.Cells[StrStatus].Value.ToString(); // if (testString == "" && dataGridRow.Cells[StrMeterVersion].Value.ToString() == "") // { // dataGridRow.Cells[StrStatus].Value = MeterFwUpdate.StrMeterAppNotInstalled; // testString = MeterFwUpdate.StrMeterAppNotInstalled; // } // switch (testString) // { // case MeterFwUpdate.StrMeterAppUpToDate: // dataGridRow.DefaultCellStyle = _styleValidated; // break; // case MeterFwUpdate.StrMeterAppInstallationRequired: // dataGridRow.DefaultCellStyle = _styleUpdateRequired; // break; // case MeterFwUpdate.StrFileAppInvalid: // dataGridRow.DefaultCellStyle = _styleDownloadOngoing; // break; // case MeterFwUpdate.StrMeterAppVersionOutdated: // dataGridRow.DefaultCellStyle = _styleUpdateRequired; // break; // case MeterFwUpdate.StrMeterAppNotInstalled: // dataGridRow.DefaultCellStyle = _styleNotInstalled; // break; // case MeterFwUpdate.StrInvalidCrc: // dataGridRow.DefaultCellStyle = _styleInvalidMeterCrc; // break; // case MeterFwUpdate.StrMeterAppErasureRequired: // dataGridRow.DefaultCellStyle = _styleEraseRequired; // break; // case MeterFwUpdate.StrMeterAppDownloadSucceeded: // dataGridRow.DefaultCellStyle = _styleDownloadSucceeded; // break; // case MeterFwUpdate.StrMeterAppDownloadSuspicious: // dataGridRow.DefaultCellStyle = _styleVerificationRequired; // break; // case MeterFwUpdate.StrMeterAppSuccessfulErased: // dataGridRow.DefaultCellStyle = _styleDownloadSucceeded; // break; // case MeterFwUpdate.StrMeterAppSuccessfulUpdated: // dataGridRow.DefaultCellStyle = _styleDownloadSucceeded; // break; // case MeterFwUpdate.StrMeterAppDownloadFailed: // dataGridRow.DefaultCellStyle = _styleDownloadFailed; // break; // case MeterFwUpdate.StrMeterAppDownloadActive: // dataGridRow.DefaultCellStyle = _styleDownloadOngoing; // break; // default: // dataGridRow.DefaultCellStyle = _styleInstalled; // break; // } //} } /// /// After changing the grid view cell and data row cell contents, the meter application lists /// have to be updated with the required action (erase or update or none of them) /// /// private void SetMeterAppEraseUpdateInfo(DataRow dataRow) { foreach (var meterApp in _currentGenesis.MeterAppListVersion) { var appId = dataRow[StrAppId].ToString(); if (appId != MeterFwUpdate.ConvertAppIdToString(meterApp.AppId)) { continue; } meterApp.Update = (Boolean)dataRow[StrUpdate]; meterApp.Erase = (Boolean)dataRow[StrErase]; } //force upgrade file generation on update cell click _meterFwUpdate?.AssignGenesis(_currentGenesis); } /// /// Overwrite cell click, because edit of cells is denied. This is needed for update and/or erase selection /// /// /// private void gridViewApplic_CellClick(Object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex <= 0 || !btnOpenUpdateDirectory.Enabled || !cbxManualControl.Checked) { return; } var dataRow = _dataTable.Rows[e.RowIndex]; if (gridViewApplic.Columns[e.ColumnIndex].Name == StrUpdate) { //deny update if update file invalid if (dataRow[StrFileVersion].ToString() == "") { dataRow[StrUpdate] = false; } else { //toggle selection dataRow[StrUpdate] = (Boolean)dataRow[StrUpdate] != true; } //remove erase selection if ((Boolean)dataRow[StrUpdate]) { dataRow[StrErase] = false; } } if (gridViewApplic.Columns[e.ColumnIndex].Name == StrErase) { //deny erase if meter file not installed or the essential applications //needed to keep the operation for the update procedure alive if (dataRow[StrMeterVersion].ToString() == "" || dataRow[StrAppName].ToString() == "SYSTEM" || dataRow[StrAppName].ToString() == "CONFIGEXCHANGE" || dataRow[StrAppName].ToString() == "IRDA") { dataRow[StrErase] = false; } else { //toggle selection dataRow[StrErase] = (Boolean)dataRow[StrErase] != true; } //remove update selection if ((Boolean)dataRow[StrErase]) { dataRow[StrUpdate] = false; } } //update information in meter application list SetMeterAppEraseUpdateInfo(dataRow); CheckUpdateEnabled(); } #endregion #region ActivationControls private void SetControlDownloadsUnlocked() { btnUpdateFw.Enabled = true; btnStopFwUpdate.Enabled = false; btnDownloadFiles.Enabled = true; if (cbxSingleFilePartsRetryEnable.Checked) { btnRetryFileParts.Enabled = CheckRetryPossible(); } btnVerifyFiles.Enabled = true; btnPrepareTrigger.Enabled = true; btnTriggerUpdate.Enabled = true; } private void SetControlDownloadsLocked() { btnUpdateFw.Enabled = false; btnStopFwUpdate.Enabled = false; btnDownloadFiles.Enabled = false; btnRetryFileParts.Enabled = false; btnVerifyFiles.Enabled = false; btnPrepareTrigger.Enabled = false; btnTriggerUpdate.Enabled = false; btnConnect.Enabled = true; } private void SetControlsDownloadIsOngoing() { cbFilePartSize.Enabled = false; cbAddRetryTimeout.Enabled = false; btnConnect.Enabled = false; btnOpenUpdateDirectory.Enabled = false; btnOpenPackageControlFile.Enabled = false; btnUpdateFw.Enabled = false; btnStopFwUpdate.Enabled = true; btnDownloadFiles.Enabled = false; btnRetryFileParts.Enabled = false; btnVerifyFiles.Enabled = false; btnPrepareTrigger.Enabled = false; btnTriggerUpdate.Enabled = false; } private void SetControlsDownloadIsFinished() { _currentGenesis.RequestProtocol.AdditionalRetryTimeoutMs = 0; cbFilePartSize.Enabled = true; cbAddRetryTimeout.Enabled = true; btnConnect.Enabled = true; btnOpenUpdateDirectory.Enabled = true; btnOpenPackageControlFile.Enabled = true; btnUpdateFw.Enabled = true; btnStopFwUpdate.Enabled = false; btnDownloadFiles.Enabled = true; if (cbxSingleFilePartsRetryEnable.Checked) { btnRetryFileParts.Enabled = CheckRetryPossible(); } btnVerifyFiles.Enabled = true; btnPrepareTrigger.Enabled = true; btnTriggerUpdate.Enabled = true; } #endregion #region BoardControls private void WaitForReboot() { if (_currentGenesis == null) { return; } lblActualProcess.Text = StrBurnUpgrade; lblOverall.Text = @"Update Applications and Restart Meter"; ProcessViewControl(true); //wait until meter update is completed and meter is re-booted const Double maxBootDelayMs = 10000.0; const Double loopDelayMs = 200.0; var bootDelayMs = 0.0; var text = ""; while (bootDelayMs < maxBootDelayMs && string.IsNullOrEmpty(text)) { SetTimeDisplay(); text = RegisterConverter.ConvertTo( _currentGenesis.ReadRegister(Register.Configexchange.PCBSerialNumber, 12)); barOverallProgressUpdate.Value = barOverallProgressUpdate.Value + 4 > 100 ? 0 : barOverallProgressUpdate.Value + 4; var bootProcess = (Int32)(bootDelayMs * 100.0 / maxBootDelayMs); barSingleProgressUpdate.Value = barSingleProgressUpdate.Value + bootProcess > 100 ? 0 : barSingleProgressUpdate.Value + bootProcess; Update(); bootDelayMs += loopDelayMs; Thread.Sleep((Int32)loopDelayMs); } ProcessViewControl(false); } private void Connect() { try { Init(); Int32 slotNr; if (string.IsNullOrEmpty(cbComSlot.SelectedItem.ToString()) || !int.TryParse(cbComSlot.SelectedItem.ToString(), out slotNr)) { return; } _currentGenesis?.DisposeMeter(); //dispose old meter _meterBatch.RemoveAllMeters(); _currentGenesis = null; Thread.Sleep(200); //assign new meter and assign meter to FW update file if this exists _currentGenesis = new GenesisMeter(); _currentGenesis.SetupFromConfigFile(slotNr); _meterBatch.AddMeter(_currentGenesis); _currentGenesis._configuration.UseRegisterWatchService = false; _currentGenesis._configuration.UseMinMaxCheck = false; Task.Factory.StartNew(() => { ViewProgressPcb(true); _meterBatch.MetersLogin(); if (!_currentGenesis.IsLoggedOn) { Thread.Sleep(2000); _meterBatch.MetersLogin(); } if (!_currentGenesis.IsLoggedOn) { return; } _meterFwUpdate?.AssignGenesis(_currentGenesis); Invoke(new Action(() => { lblConnectPcb.Text = StrPartPcbConnected + _currentGenesis.PcbId; lblCoreRevision.Text = StrCoreRevision + _currentGenesis.CoreRevision; lblConnectPcb.ForeColor = Color.Green; _meterFwUpdate?.CompareAllMeterAndFileApps(); FillDataGridWithAllInfos(); CheckUpdateEnabled(); _currentGenesis.Logout(); })); }).ContinueWith(delegate { ViewProgressPcb(false); }); } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion #region ProcessControls private void ViewProgressPcb(Boolean isActive) { if (_updateGui) { if (isActive) { Invoke(new Action(() => { _tryConnectPcb = true; ProcessViewControl(true); lblActualProcess.Text = StrConnecting; lblOverall.Text = StrOverallProcess; })); } else { Invoke(new Action(() => { _tryConnectPcb = false; ProcessViewControl(false); })); } } } /// /// View all process bars and labels /// private void ProcessViewControl(Boolean view) { if (view) { lblActualProcess.Visible = true; lblOverall.Visible = true; barOverallProgressUpdate.Visible = true; barSingleProgressUpdate.Visible = true; _lastFwUpdateState = ""; tmrProgressUpdate.Enabled = true; } else { lblActualProcess.Visible = false; lblOverall.Visible = false; barOverallProgressUpdate.Visible = false; barSingleProgressUpdate.Visible = false; tmrProgressUpdate.Enabled = false; _lastFwUpdateState = ""; lblWaitingForMeterResponse.Visible = false; lblActualProcess.Text = ""; lblOverall.Text = ""; } //common actions and settings lblActualProcess.Update(); lblOverall.Update(); barOverallProgressUpdate.Value = 0; barOverallProgressUpdate.Update(); barSingleProgressUpdate.Value = 0; barSingleProgressUpdate.Update(); Update(); } private void AutomaticUpdateControl(Boolean isActive) { if (isActive) { Invoke(new Action(() => { _lastFwUpdateState = ""; ProcessViewControl(true); tmrProgressUpdate.Enabled = true; })); } else { Invoke(new Action(() => { ProcessViewControl(false); FillDataGridWithAllInfos(); SetControlsDownloadIsFinished(); if (_fileAppsSuccessfulWritten) { WaitForReboot(); btnConnect_Click(this, null); } else { var requiredUpdates = _meterFwUpdate?.GetFailedFileApps(); var text = cbxManualControl.Checked ? StrUpdateErrorMessageManualControl : StrUpdateErrorMessage; if (requiredUpdates != null && requiredUpdates.Count > 0) { text += "\nFailed to update application:\n"; FileApplications lastFile = null; foreach (var file in requiredUpdates) { if (lastFile == null || lastFile.AppId != file.AppId) { text += $"{file.AppName}\n"; } lastFile = file; } } MessageBoxShow(text, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error); } })); } } private void DownloadFilesControl(Boolean isActive) { if (isActive) { Invoke(new Action(() => { _lastFwUpdateState = ""; ProcessViewControl(true); tmrProgressUpdate.Enabled = true; })); } else { Invoke(new Action(() => { ProcessViewControl(false); FillDataGridWithAllInfos(); SetControlsDownloadIsFinished(); if (!_fileAppsSuccessfulWritten) { var text = "DOWNLOAD FAILED!\n\n" + "If some files marked red:\n" + "Download these files by select \"Download\" and\n" + "then press \"Manual Download\" [Entire File Parts]!\n\n"; var requiredUpdates = _meterFwUpdate?.GetFailedFileApps(); if (requiredUpdates != null && requiredUpdates.Count > 0) { text += "\nFailed to update application:\n"; FileApplications lastFile = null; foreach (var file in requiredUpdates) { if (lastFile == null || lastFile.AppId != file.AppId) { text += $"{file.AppName}\n"; } lastFile = file; } } MessageBoxShow(text, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { const String text = "Download of selected files succeeded!\n\n" + "If some files marked red:\n" + "Download these files by select \"Download\" and\n" + "then press \"Manual Download\" [Entire File Parts]!\n\n" + "If all files are downloaded:\n" + "Select all green marked files \"Download\"," + "all red written \"Erasure required\" with \"Erase\" and\n" + "press [Trigger Upgrade] to finalize the update!"; MessageBoxShow(text, @"SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information); } })); } } private void TriggerUpdateControl(Boolean isActive) { if (isActive) { Invoke(new Action(() => { _lastFwUpdateState = ""; ProcessViewControl(true); tmrProgressUpdate.Enabled = true; })); } else { Invoke(new Action(() => { ProcessViewControl(false); FillDataGridWithAllInfos(); SetControlsDownloadIsFinished(); if (_fileAppsSuccessfulWritten) { const String text = "Trigger upgrade succeeded!\n\n" + "Press [Connect] for verification!"; MessageBoxShow(text, @"SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { const String text = "TRIGGER UPGRADE FAILED\n\n" + "FW installation may be successfully executed!\n\n" + "Press [Connect] for verification!"; MessageBoxShow(text, @"Verification Needed", MessageBoxButtons.OK, MessageBoxIcon.Information); } })); } } private void VerifyFilesControl(Boolean isActive) { if (isActive) { Invoke(new Action(() => { _lastFwUpdateState = ""; ProcessViewControl(true); tmrProgressUpdate.Enabled = true; })); } else { Invoke(new Action(() => { ProcessViewControl(false); FillDataGridWithAllInfos(); SetControlsDownloadIsFinished(); if (!_fileAppsSuccessfulWritten) { const String text = "VERIFICATION FAILED!\n\n" + "If some files marked red:\n" + "Download these files by select \"Download\" and\n" + "then press \"Manual Download\" [Entire File Parts]!"; MessageBoxShow(text, @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { const String text = "Verification of selected files succeeded!\n\n" + "If some files marked red:\n" + "Download these files by select \"Download\" and\n" + "then press \"Manual Download\" [Entire File Parts]!\n\n" + "If all files are verified green:\n" + "Select all green marked files \"Download\"," + "all red written \"Erasure required\" with \"Erase\" and\n" + "press [Trigger Upgrade] to finalize the update!"; MessageBoxShow(text, @"SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information); } })); } } #endregion #region Checks private void CheckManualControl() { if (cbxManualControl.Checked) { gbxManualDownload.Visible = true; gbxManualTriggerControl.Visible = true; gbxManualUploadAndVerification.Visible = true; gbxManualTimingControl.Visible = true; } else { gbxManualDownload.Visible = false; gbxManualTriggerControl.Visible = false; gbxManualUploadAndVerification.Visible = false; gbxManualTimingControl.Visible = false; } } private Boolean CheckUpdateEnabled() { SetControlDownloadsUnlocked(); return true; //this check has been placed here to force display update if (_meterFwUpdate != null && _currentGenesis != null && _packageFileToFileAppsValidated && (_currentGenesis.MeterAppListVersion.Any(f => f.Update) || _currentGenesis.MeterAppListVersion.Any(f => f.Erase))) { SetControlDownloadsUnlocked(); return true; } else { SetControlDownloadsLocked(); return false; } } private Boolean CheckRetryPossible() { return _meterFwUpdate != null && _meterFwUpdate.GetFailedFileApps().Count > 0; } private void CheckPackageFileAndFileApps() { try { _packageFileToFileAppsValidated = _meterFwUpdate.ValidateFileAppsWithPackageFile(); } catch (Exception e) { if (_meterFwUpdate.CoreRevisionMaximum == null) MessageBoxShow(@"Core Revision missing in ADF!", @"FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (_packageFileToFileAppsValidated) { lblPackageFileLoadedInfo.ForeColor = Color.Green; lblPackageFileLoadedInfo.Text = StrPackageFileLoaded; } else { lblPackageFileLoadedInfo.ForeColor = Color.Red; lblPackageFileLoadedInfo.Text = StrPackageFileToFileAppsMismatch; } } #endregion #region TimerControls private void tmrProgressUpdate_Tick(Object sender, EventArgs e) { //cbxManualControl.Visible = true; if (_tryConnectPcb) { barOverallProgressUpdate.Value = barOverallProgressUpdate.Value + 1 > 100 ? 0 : barOverallProgressUpdate.Value + 1; barSingleProgressUpdate.Value = barSingleProgressUpdate.Value + 4 > 100 ? 0 : barSingleProgressUpdate.Value + 4; lblOverall.Text = StrOverallProcess; } else { lblOverall.Text = _meterFwUpdate?.GetFwUpdateStateOperation(); lblActualProcess.Text = _meterFwUpdate?.GetActualOperation(); var overallProgress = (Int32)(_meterFwUpdate?.OverallProcessCtrPercent ?? 0); barOverallProgressUpdate.Value = overallProgress > 100 ? 100 : overallProgress; barOverallProgressUpdate.Update(); var singleProgress = (Int32)(_meterFwUpdate?.SingleFileProcessCtrPercent ?? 0); if (_meterFwUpdate?.GetFwUpdateStateOperation() != _lastFwUpdateState) { _lastFwUpdateState = _meterFwUpdate?.GetFwUpdateStateOperation(); FillDataGridWithAllInfos(); lblWaitingForMeterResponse.Visible = false; } else { //if the communication gets frozen lblWaitingForMeterResponse.Visible = _lastSingleProgress == singleProgress; } barSingleProgressUpdate.Value = singleProgress > 100 ? 100 : singleProgress; _lastSingleProgress = singleProgress; barSingleProgressUpdate.Update(); } SetTimeDisplay(); Update(); } private void SetTimeDisplay() { var time = DateTimeOffset.UtcNow; var timeSpan = time - _startTime; lblUpdateTime.Text = $@"{(UInt32)timeSpan.TotalMinutes}:{timeSpan.Seconds:00}"; } #endregion #region Buttons private void btnConnect_Click(Object sender, EventArgs e) { if (_resetTimeMeasurement) { _startTime = DateTimeOffset.UtcNow; _resetTimeMeasurement = false; } Connect(); //if (true) //{ // tbxBinaryPath.Text = "C:\\Users\\drabesch_ro\\Desktop\\Cordonel_NA_20200403_B104A\\binaries\\naproduct\\"; // tbxPackageFilePathName.Text = "C:\\Users\\drabesch_ro\\Desktop\\Cordonel_NA_20200403_B104A\\naproduct.txt"; // var packageFilePathName = tbxPackageFilePathName.Text; // if (_meterFwUpdate == null) _meterFwUpdate = new MeterFwUpdate(_currentGenesis); // if (_meterFwUpdate == null) return; // if (_meterFwUpdate.LoadPackageFile(packageFilePathName)) // { // CheckPackageFileAndFileApps(); // } // else // { // lblPackageFileLoadedInfo.ForeColor = Color.Red; // lblPackageFileLoadedInfo.Text = StrPackageFileInvalid; // } // CheckUpdateEnabled(); // _resetTimeMeasurement = true; // //reload last file path // dlgBinaryPath.SelectedPath = DefaultBinaryPath; // var binaryFilePath = tbxBinaryPath.Text; // //copy path to package file load // //if (String.IsNullOrEmpty(DefaultPackageFile)) // // dlgOpenPackageFile.InitialDirectory = binaryFilePath; // tbxBinaryPath.Text = binaryFilePath; // if (_meterFwUpdate == null) _meterFwUpdate = new MeterFwUpdate(_currentGenesis); // if (_meterFwUpdate == null) return; // if (_meterFwUpdate.LoadFileApps(binaryFilePath)) // { // lblFileAppsLoadedInfo.ForeColor = Color.Green; // lblFileAppsLoadedInfo.Text = StrFileAppsLoaded; // } // else // { // lblFileAppsLoadedInfo.ForeColor = Color.Red; // lblFileAppsLoadedInfo.Text = StrUpdatePathEmpty; // } // CheckPackageFileAndFileApps(); // if (_currentGenesis == null) return; // _meterFwUpdate?.CompareAllMeterAndFileApps(); // _meterFwUpdate?.AssignGenesis(_currentGenesis); // FillDataGridWithAllInfos(); // CheckUpdateEnabled(); // _resetTimeMeasurement = true; //} } private void btnOpenPackageControlFile_Click(Object sender, EventArgs e) { ////reload last path dlgOpenPackageFile.InitialDirectory = DefaultPackageFile; if (dlgOpenPackageFile.ShowDialog() != DialogResult.OK) { return; } var packageFilePathName = dlgOpenPackageFile.FileName; DefaultPackageFile = packageFilePathName; //copy path to binary file load //if (String.IsNullOrEmpty(DefaultBinaryPath)) // dlgBinaryPath.SelectedPath = Path.GetFullPath(packageFilePathName); tbxPackageFilePathName.Text = packageFilePathName; if (_meterFwUpdate == null) { _meterFwUpdate = new MeterFwUpdate(_currentGenesis); } if (_meterFwUpdate == null) { return; } if (_meterFwUpdate.LoadPackageFile(packageFilePathName)) { CheckPackageFileAndFileApps(); } else { lblPackageFileLoadedInfo.ForeColor = Color.Red; lblPackageFileLoadedInfo.Text = StrPackageFileInvalid; } CheckUpdateEnabled(); _resetTimeMeasurement = true; } private void btnOpenUpdateDirectory_Click(Object sender, EventArgs e) { //reload last file path dlgBinaryPath.SelectedPath = DefaultBinaryPath; if (dlgBinaryPath.ShowDialog() != DialogResult.OK) { return; } var binaryFilePath = dlgBinaryPath.SelectedPath; DefaultBinaryPath = binaryFilePath; //copy path to package file load //if (String.IsNullOrEmpty(DefaultPackageFile)) // dlgOpenPackageFile.InitialDirectory = binaryFilePath; tbxBinaryPath.Text = binaryFilePath; var meterFwUpdate = new MeterFwUpdate(_currentGenesis); if (meterFwUpdate.LoadFileApps(binaryFilePath)) { lblFileAppsLoadedInfo.ForeColor = Color.Green; lblFileAppsLoadedInfo.Text = StrFileAppsLoaded; } else { lblFileAppsLoadedInfo.ForeColor = Color.Red; lblFileAppsLoadedInfo.Text = StrUpdatePathEmpty; } PushFwFile(meterFwUpdate); } /// /// Upload selected update files and compare them with update files /// /// /// private void btnVerifyFiles_Click(Object sender, EventArgs e) { if (_currentGenesis == null || _meterFwUpdate?.FileApps == null) { return; } SetControlsDownloadIsOngoing(); VerifyFilesControl(true); Task.Factory.StartNew(() => { _fileAppsSuccessfulWritten = _meterFwUpdate.ManualVerifyFiles(); Thread.Sleep(1000); }).ContinueWith(delegate { VerifyFilesControl(false); }); } /// /// Download selected update files entirely /// /// /// private void btnDownloadFiles_Click(Object sender, EventArgs e) { if (_currentGenesis == null || _meterFwUpdate?.FileApps == null) { return; } Int32 fileSizePartKb; Int32 addRetryTimeoutMs; if (string.IsNullOrEmpty(cbFilePartSize.SelectedItem.ToString()) || !int.TryParse(cbFilePartSize.SelectedItem.ToString(), out fileSizePartKb)) { return; } _meterFwUpdate.MaxPartialFileDataSize = fileSizePartKb * 1024; if (string.IsNullOrEmpty(cbAddRetryTimeout.SelectedItem.ToString()) || !int.TryParse(cbAddRetryTimeout.SelectedItem.ToString(), out addRetryTimeoutMs)) { return; } _currentGenesis.RequestProtocol.AdditionalRetryTimeoutMs = addRetryTimeoutMs; SetControlsDownloadIsOngoing(); DownloadFilesControl(true); Task.Factory.StartNew(() => { _fileAppsSuccessfulWritten = _meterFwUpdate.ManualDownloadAllFileApps(); Thread.Sleep(1000); }).ContinueWith(delegate { DownloadFilesControl(false); }); } /// /// Download remaining files parts from previous download /// /// /// private void btnRetryFileParts_Click(Object sender, EventArgs e) { if (_currentGenesis == null || _meterFwUpdate?.FileApps == null) { return; } SetControlsDownloadIsOngoing(); DownloadFilesControl(true); Task.Factory.StartNew(() => { _fileAppsSuccessfulWritten = _meterFwUpdate.ManualDownloadRemainingFileAppsParts(); Thread.Sleep(1000); }).ContinueWith(delegate { DownloadFilesControl(false); }); } /// /// Preselect "Download" trigger marks on successfully downloaded files /// /// /// private void btnPrepareTrigger_Click(Object sender, EventArgs e) { if (_meterFwUpdate == null) { return; } _meterFwUpdate.PrepareTrigger(); FillDataGridWithAllInfos(); } /// /// Build update control file and trigger update of selected files /// /// /// private void btnTriggerUpdate_Click(Object sender, EventArgs e) { if (_currentGenesis == null || _meterFwUpdate?.FileApps == null) { return; } SetControlsDownloadIsOngoing(); TriggerUpdateControl(true); Task.Factory.StartNew(() => { _fileAppsSuccessfulWritten = _meterFwUpdate.ManualTriggerUpgrade(); Thread.Sleep(1000); }).ContinueWith(delegate { TriggerUpdateControl(false); }); } /// /// Automatic update of entire FW /// /// /// private void btnUpdateFw_Click(Object sender, EventArgs e) { if (_currentGenesis == null || _meterFwUpdate?.FileApps == null) { return; } SetControlsDownloadIsOngoing(); AutomaticUpdateControl(true); _startTime = DateTimeOffset.UtcNow; _resetTimeMeasurement = false; if (string.IsNullOrEmpty(cbFilePartSize.SelectedItem.ToString()) || !int.TryParse(cbFilePartSize.SelectedItem.ToString(), out var fileSizePartKb)) { return; } _meterFwUpdate.MaxPartialFileDataSize = fileSizePartKb * 1024; if (string.IsNullOrEmpty(cbAddRetryTimeout.SelectedItem.ToString()) || !int.TryParse(cbAddRetryTimeout.SelectedItem.ToString(), out var addRetryTimeoutMs)) { return; } _currentGenesis.RequestProtocol.AdditionalRetryTimeoutMs = addRetryTimeoutMs; Task.Factory.StartNew(() => { _fileAppsSuccessfulWritten = _meterFwUpdate.UpdateMeterFw(); Thread.Sleep(1000); }).ContinueWith(delegate { AutomaticUpdateControl(false); }); } private void btnStopFwUpdate_Click(Object sender, EventArgs e) { if (_meterFwUpdate != null) { _meterFwUpdate.StopUpdateProcess = true; } } private void btnResetAll_Click(Object sender, EventArgs e) { btnStopFwUpdate_Click(this, null); _meterFwUpdate?.ResetAll(); Init(); FillDataGridWithAllInfos(); CheckUpdateEnabled(); _currentGenesis.Logout(); } #endregion #region CheckBoxes /// /// File parts are consecutive, stop process at first failed part and retry from /// this part on all others behind /// /// /// private void cbxConsecutiveFilePartsRetryEnable_CheckedChanged(Object sender, EventArgs e) { if (_meterFwUpdate == null) { return; } _meterFwUpdate.ConsecutiveFilePartsRetryEnable = cbxConsecutiveFilePartsRetryEnable.Checked; cbxSingleFilePartsRetryEnable.Checked = false; } /// /// Failed file parts are somewhere in between succeeded parts and will be retried separately /// /// /// private void cbxSingleFilePartsRetryEnable_CheckedChanged(Object sender, EventArgs e) { if (_meterFwUpdate == null) { return; } _meterFwUpdate.SingleFilePartsRetryEnable = cbxSingleFilePartsRetryEnable.Checked; cbxConsecutiveFilePartsRetryEnable.Checked = false; } /// /// Activation of manual control buttons for individual update procedure /// /// /// private void cbxManualControl_CheckedChanged_1(Object sender, EventArgs e) { CheckManualControl(); _meterFwUpdate?.CompareAllMeterAndFileApps(); FillDataGridWithAllInfos(); CheckUpdateEnabled(); } #endregion #region ExternalCalls public Boolean Prepare(Int32 slot, String binaryPath, String packageInfoPath) { _updateGui = false; cbComSlot.SelectedItem = slot; Connect(); var retries = 40; while (_currentGenesis == null || !_currentGenesis.IsLoggedOn) { Thread.Sleep(1000); retries -= 1; if (retries <= 0) { return false; } } Thread.Sleep(10000); tbxBinaryPath.Text = binaryPath; if (_meterFwUpdate == null) { _meterFwUpdate = new MeterFwUpdate(_currentGenesis); } if (_meterFwUpdate == null) { return false; } if (_meterFwUpdate.LoadFileApps(binaryPath)) { lblFileAppsLoadedInfo.ForeColor = Color.Green; lblFileAppsLoadedInfo.Text = StrFileAppsLoaded; } else { lblFileAppsLoadedInfo.ForeColor = Color.Red; lblFileAppsLoadedInfo.Text = StrUpdatePathEmpty; } CheckPackageFileAndFileApps(); if (_currentGenesis == null) { return false; } _meterFwUpdate?.CompareAllMeterAndFileApps(); _meterFwUpdate?.AssignGenesis(_currentGenesis); FillDataGridWithAllInfos(); tbxPackageFilePathName.Text = packageInfoPath; if (_meterFwUpdate == null) { _meterFwUpdate = new MeterFwUpdate(_currentGenesis); } if (_meterFwUpdate == null) { return false; } if (_meterFwUpdate.LoadPackageFile(packageInfoPath)) { CheckPackageFileAndFileApps(); } else { lblPackageFileLoadedInfo.ForeColor = Color.Red; lblPackageFileLoadedInfo.Text = StrPackageFileInvalid; } if (CheckUpdateEnabled()) { btnUpdateFw_Click(null, EventArgs.Empty); //wait for response return e return true; } else { return false; } } public void StartUpdate() { } public MsgEventargs LastMsgEvent; public class MsgEventargs : EventArgs { public String Text; public String Caption; public MessageBoxButtons Buttons; public MessageBoxIcon Icon; } public event EventHandler OnMsgPopUp; private void MessageBoxShow(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon) { if (_updateGui) { MessageBox.Show(text, caption, buttons, icon); } else { LastMsgEvent = new MsgEventargs() { Text = text, Caption = caption, Buttons = buttons, Icon = icon }; OnMsgPopUp?.Invoke(this, LastMsgEvent); } } #endregion private void tabDb_Click(Object sender, EventArgs e) { } private void tabFwSources_SelectedIndexChanged(Object sender, EventArgs e) { if (tabFwSources.SelectedTab == tabLocalFile) { checkSelectionChanged(FwSource.File); } else if (tabFwSources.SelectedTab == tabProduction) { checkSelectionChanged(FwSource.File); } else if (tabFwSources.SelectedTab == tabDb) { checkSelectionChanged(FwSource.Db); cbxFilterFwDn.Items.Add("ALL"); cbxFilterFWType.Items.Add("ALL"); foreach (MeterSize suit in (MeterSize[])Enum.GetValues(typeof(MeterSize))) { cbxFilterFwDn.Items.Add(suit); } cbxFilterFwDn.SelectedIndex = 0; cbxFilterFWType.Items.Add(CordonelFWTypeEnum.EMEA_433); cbxFilterFWType.Items.Add(CordonelFWTypeEnum.EMEA_868); cbxFilterFWType.Items.Add(CordonelFWTypeEnum.NA); cbxFilterFWType.SelectedIndex = 0; btnGetFWFiles_Click(sender, e); } else { MessageBox.Show("No Tab selected!"); } //tabFwSources.SelectedTab = tabLocalFile; } private void checkSelectionChanged(FwSource newMode) { if (newMode == fwSource) { return; } fwSource = newMode; } private void PushFwFile(MeterFwUpdate meterFwUpdate) { _meterFwUpdate = meterFwUpdate; CheckPackageFileAndFileApps(); if (_currentGenesis == null) { return; } _meterFwUpdate?.CompareAllMeterAndFileApps(); _meterFwUpdate?.AssignGenesis(_currentGenesis); FillDataGridWithAllInfos(); CheckUpdateEnabled(); _resetTimeMeasurement = true; } private void btnGetFWFiles_Click(Object sender, EventArgs e) { var IsDevloper = chbFilterIsDeveloper.Checked; var url = $"http://sla12iis01/MeterProcessState/api/FileUpToDate/GetFwFiles?FileIsForDeveloperOnly={IsDevloper}"; if (cbxFilterFwDn.SelectedItem.ToString() != "ALL") { var MyMeterSize = ((MeterSize)cbxFilterFwDn.SelectedItem).GetHashCode(); url = url + $"&CordonelFwFile_Dn={MyMeterSize}"; } if (cbxFilterFWType.SelectedItem.ToString() != "ALL") { var FWTypeEnum = ((CordonelFWTypeEnum)cbxFilterFWType.SelectedItem).GetHashCode(); url = url + $"&CordonelFwFile_Type={FWTypeEnum}"; } url = url + $"&FileCategoryID=1"; var result = LocalWebRequest.GetRequest(url, 1000); var a = JsonConvert.DeserializeObject>(result); dgvFiles.DataSource = a.OrderByDescending(o => o.FileDate).ToList(); for (Int32 i = 0; i < dgvFiles.ColumnCount; i++) { dgvFiles.Columns[i].Visible = i < 5; } dgvFiles.AutoResizeColumns(); } private void dgvFiles_CellContentClick(Object sender, DataGridViewCellEventArgs e) { var parentFilId = (Int32)dgvFiles.Rows[e.RowIndex].Cells[1].Value; var url = $"{ServiceUrls.FileContentControllerUrl()}/GetFileParts?ParentFileId={parentFilId}&readContent=true"; var result = LocalWebRequest.GetRequest(url, 1000); var a = JsonConvert.DeserializeObject>(result); lblFwNameSelected.Text = dgvFiles.Rows[e.RowIndex].Cells[1].Value.ToString(); lblSelectedID.Text = parentFilId.ToString(); _meterFwUpdate = new MeterFwUpdate(_currentGenesis); var fileApps = new List(); foreach (var item in a) { if (item.FileName.ToLower().EndsWith(".bin")) { var fileApplication = new FileApplications(item.FileName) { BinData = new List(item.FileContent.ToList()) }; fileApps.Add(fileApplication); } else if (item.FileName.ToLower().EndsWith(".txt")) { //encode content String ControlFileContent = ""; System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); ControlFileContent = enc.GetString(item.FileContent.ToArray()); _meterFwUpdate.LoadPackageFileFromText(ControlFileContent); } } _meterFwUpdate.LoadFileApps(fileApps); _meterFwUpdate?.CompareAllMeterAndFileApps(); _meterFwUpdate?.AssignGenesis(_currentGenesis); FillDataGridWithAllInfos(); CheckPackageFileAndFileApps(); CheckUpdateEnabled(); _resetTimeMeasurement = true; } private void button1_Click(Object sender, EventArgs e) { if (_currentGenesis == null || !_currentGenesis.IsLoggedOn) { return; } else { _currentGenesis.SetLcdText(true, new Byte[] { 0x00, 0x00, 0x00, 0x00 }); } } private void btnFixBat_Click(Object sender, EventArgs e) { try { _currentGenesis.Login(); _currentGenesis.WriteRegister("GENESISFLOW_SealDisplay", (UInt32)0, true, false); _currentGenesis.ResetAlarm(GenesisMeter.Alarm.ALL); _currentGenesis.WriteRegister("POWERMON_WarnFromClamp", (UInt32)630720000, true, false); _currentGenesis.WriteRegister("POWERMON_BatteryQuantity", (UInt32)2, true, false); _currentGenesis.WriteRegister("POWERMON_StoreConfiguration", (UInt32)1, true, false); _currentGenesis.WriteRegister("GENESISFLOW_TriggerIdle", (UInt32)0, true, false); _currentGenesis.StoreAllApps(); _currentGenesis.Logout(); Thread.Sleep(15000); _currentGenesis.Login(); } catch (Exception) { throw; } } private void label2_Click(Object sender, EventArgs e) { } } }