719 lines
24 KiB
C#
719 lines
24 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Logic.ProductionToProductMapper.Cordonel;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Consts;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile.Properties;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts;
|
|
using Xylem.Common.Utils.Crc16Ccitt;
|
|
using Xylem.Common.Utils.ProcessExec;
|
|
using Xylem.Common.Utils.ProcessExec.EventArguments;
|
|
|
|
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
{
|
|
/// <summary>
|
|
/// Meter lookup table for metrology update procedure
|
|
/// </summary>
|
|
public class MeterLutUpdate : IProcessState
|
|
{
|
|
#region Variables
|
|
|
|
/// <summary>
|
|
/// Port scan result event for message dispatcher to caller
|
|
/// </summary>
|
|
public event EventHandler<ProcessExecEventArgs> OnProcessUpdate;
|
|
|
|
//disk and name of lookup file
|
|
private const String StrLutMeterFileName = "1\\mettbl";
|
|
|
|
//disk and name of lookup file
|
|
private const String StrLutBackupMeterFileName = "1\\mettbl_b";
|
|
|
|
// identifier for Genesis lookup table
|
|
private const String StrLutFileId = "GEN_LUT\0";
|
|
private const Int32 IndexLutFileId = 0;
|
|
private const UInt32 LengthLutFileId = 8;
|
|
|
|
// data length, calculated from version field to the end of the data section
|
|
private const Int32 IndexDataLength = 8;
|
|
private const Int32 LengthDataLength = 4;
|
|
|
|
// CCITT-CRC-16 , calculated from version field to the end of the data section
|
|
private const Int32 IndexCrc = 12;
|
|
private const UInt32 LengthCrc = 2;
|
|
|
|
// version
|
|
private const Int32 IndexVersion = 14;
|
|
private const Int32 LengthVersion = 2;
|
|
|
|
// meter size as enumeration
|
|
private const Int32 IndexMeterSize = 16;
|
|
|
|
// header size of file
|
|
private const UInt32 LutFileHeaderLength =
|
|
LengthLutFileId + LengthDataLength + LengthCrc + LengthVersion;
|
|
|
|
// data size of file
|
|
private const Int32 LutFileDataLength = 730;
|
|
|
|
// LUT file entire file size
|
|
private const UInt32 SizeLutFile = LutFileHeaderLength + LutFileDataLength;
|
|
|
|
|
|
// process display message
|
|
private const String StrProcessLut = "Processing metrology lookup table";
|
|
|
|
//trigger update retries
|
|
private const Int32 RegisterWriteRetries = 0;
|
|
|
|
//update reties for files
|
|
private const Int32 FileWriteRetries = 0;
|
|
|
|
//retry of entire update procedure
|
|
private const Int32 UpdateProcedureRetries = 0;
|
|
|
|
//threshold to increase the file write timing
|
|
private const Int32 IncreaseTimeoutUpdateProcedureRetries = 4;
|
|
|
|
private Int32 _updateProcedureRetryCtr;
|
|
|
|
private GenesisMeter _genesisMeter;
|
|
private MeterFile _meterFile;
|
|
|
|
// Text for caller to inform about actual process being carried out
|
|
private String _actualOperation;
|
|
private LutUpdateState _lutUpdateState;
|
|
|
|
// Look up table file
|
|
public MeterLutFile LutFile;
|
|
|
|
// actual processed file
|
|
private String _actualFileName;
|
|
|
|
// list of names of installed meter files on drive 1
|
|
private List<String> _meterFilesDrive1;
|
|
|
|
// number of operations for over all access
|
|
private const Int32 NumberOfOperations = 11;
|
|
private Int32 _operationCtr;
|
|
|
|
|
|
// error message for display of error reason
|
|
public String ErrorMessage;
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
/// <summary>
|
|
/// Process update event
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <remarks date="2020-Dec-10" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public virtual void ProcessUpdate_Event(Object sender, ProcessExecEventArgs e)
|
|
{
|
|
// copy text from overall messages to actual, because this is from sub-routine
|
|
OnProcessUpdate?.Invoke(this, new ProcessExecEventArgs(StrProcessLut,
|
|
OverallProcessCtrPercent, _actualOperation, e.OverallProcessPercent));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Information
|
|
|
|
/// <summary>
|
|
/// Process counter in percent
|
|
/// </summary>
|
|
/// <remarks date="2022-Mar-03" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Double OverallProcessCtrPercent => 100.0 * _operationCtr / NumberOfOperations;
|
|
|
|
/// <summary>
|
|
/// Single file process counter in percent
|
|
/// </summary>
|
|
/// <remarks date="2019-Jun-24" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Double SingleFileProcessCtrPercent => _meterFile?.ProcessCtrPercent ?? 0;
|
|
|
|
#endregion
|
|
|
|
#region CtorAssignment
|
|
|
|
/// <summary>
|
|
/// Ctor
|
|
/// </summary>
|
|
/// <param name="genesisMeter"></param>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public MeterLutUpdate(GenesisMeter genesisMeter)
|
|
{
|
|
if (genesisMeter == null) return;
|
|
AssignGenesis(genesisMeter);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Assign new genesis
|
|
/// </summary>
|
|
/// <param name="genesisMeter"></param>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public void AssignGenesis(GenesisMeter genesisMeter)
|
|
{
|
|
_genesisMeter = genesisMeter;
|
|
_actualOperation = "";
|
|
_lutUpdateState = LutUpdateState.Idle;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dispose
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
if (_meterFile == null) return;
|
|
_meterFile.OnProcessUpdate -= ProcessUpdate_Event;
|
|
_meterFile = null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ProcessInformation
|
|
|
|
/// <summary>
|
|
/// Returns the actual file in process for update
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2019-Jun-20" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public String GetActualOperation()
|
|
{
|
|
return _actualOperation;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the LUT Update state
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Feb-25" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public String GetLutUpdateStateOperation()
|
|
{
|
|
return _lutUpdateState == LutUpdateState.Idle ? "" : "Processing...";
|
|
}
|
|
#endregion
|
|
|
|
#region Actions
|
|
|
|
/// <summary>
|
|
/// Try to re-establish the file system, therefor logout to close all open files
|
|
/// and login again.
|
|
/// </summary>
|
|
/// <remarks date="2019-Jun-21" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
/// <remarks date="2019-Jun-28" author="Thomas Wiedebusch">
|
|
/// - Enable auto-logon added
|
|
/// </remarks>
|
|
/// <remarks date="2019-Jul-03" author="Thomas Wiedebusch">
|
|
/// - Removed auto-logon
|
|
/// </remarks>
|
|
public void ReestablishMeterFileSystem()
|
|
{
|
|
_genesisMeter?.Logout();
|
|
_genesisMeter?.ReLogin();
|
|
}
|
|
|
|
private Boolean _stopUpdateProcess;
|
|
|
|
/// <summary>
|
|
/// Stop the update process
|
|
/// </summary>
|
|
public Boolean StopUpdateProcess
|
|
{
|
|
get => _stopUpdateProcess;
|
|
set
|
|
{
|
|
_stopUpdateProcess = value;
|
|
if (_meterFile != null)
|
|
{
|
|
_meterFile.StopProcess = value;
|
|
}
|
|
|
|
_lutUpdateState = LutUpdateState.UpdateFailed;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update meter lookup table
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Boolean UpdateMeterLut()
|
|
{
|
|
if (!UpdatePreparation())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
_operationCtr = 0;
|
|
_actualOperation = "";
|
|
ErrorMessage = "";
|
|
_lutUpdateState = LutUpdateState.StartInitial;
|
|
while (_lutUpdateState != LutUpdateState.Idle && !StopUpdateProcess)
|
|
{
|
|
LutUpdateStateMachine();
|
|
}
|
|
|
|
return ExitPreparation(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Upload lookup table file and compare with the loaded from file system
|
|
/// </summary>
|
|
/// <remarks date="2019-Jun-29" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Boolean VerifyLutFile()
|
|
{
|
|
if (!UpdatePreparation())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return ExitPreparation(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset lookup table update process and all lists and counters
|
|
/// </summary>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public void ResetAll()
|
|
{
|
|
LutFile = null;
|
|
//remove the update stop action
|
|
StopUpdateProcess = false;
|
|
|
|
//reset all counters
|
|
_updateProcedureRetryCtr = 0;
|
|
|
|
//set state machine for automatic FW update
|
|
_lutUpdateState = LutUpdateState.Idle;
|
|
_actualOperation = "";
|
|
_operationCtr = 0;
|
|
|
|
//logout/login/auto-login
|
|
ReestablishMeterFileSystem();
|
|
_genesisMeter?.Logout();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Common update preparation and check
|
|
/// </summary>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Boolean UpdatePreparation()
|
|
{
|
|
_actualOperation = "Update preparation";
|
|
_lutUpdateState = LutUpdateState.Idle;
|
|
|
|
_meterFile = new MeterFile(_genesisMeter);
|
|
if (_meterFile != null) _meterFile.OnProcessUpdate += ProcessUpdate_Event;
|
|
_genesisMeter?.ReLogin();
|
|
_genesisMeter?.SetProcessState(DisplayCodes.FwUpdateActive, false);
|
|
|
|
if (_genesisMeter == null || !_genesisMeter.IsLoggedOn)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//set default timeout for file write operation
|
|
_meterFile.SetDefaultFileWriteTimeout();
|
|
|
|
//remove the update stop action
|
|
StopUpdateProcess = false;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Common exit routine
|
|
/// </summary>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Boolean ExitPreparation(Boolean returnValue)
|
|
{
|
|
if (_meterFile != null) _meterFile.OnProcessUpdate -= ProcessUpdate_Event;
|
|
_meterFile = null;
|
|
ReestablishMeterFileSystem();
|
|
_genesisMeter?.Logout();
|
|
if (!StopUpdateProcess)
|
|
{
|
|
return returnValue;
|
|
}
|
|
|
|
_actualOperation = Resources.StrWaiting;
|
|
return false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region StateMachine
|
|
|
|
/// <summary>
|
|
/// State machine for metrology lookup table update process
|
|
/// </summary>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
private void LutUpdateStateMachine()
|
|
{
|
|
switch (_lutUpdateState)
|
|
{
|
|
case LutUpdateState.Idle:
|
|
break;
|
|
|
|
case LutUpdateState.StartInitial:
|
|
_updateProcedureRetryCtr = 0;
|
|
_lutUpdateState = LutUpdateState.PrepareLutDownload;
|
|
break;
|
|
|
|
case LutUpdateState.PrepareLutDownload:
|
|
_lutUpdateState = PrepareLutDownload() ? LutUpdateState.DownloadLutFile : LutUpdateState.StepFailed;
|
|
break;
|
|
|
|
case LutUpdateState.DownloadLutFile:
|
|
_lutUpdateState = DownloadLutFile() ? LutUpdateState.Idle : LutUpdateState.StepFailed;
|
|
break;
|
|
|
|
case LutUpdateState.StepFailed:
|
|
|
|
_lutUpdateState = _updateProcedureRetryCtr++ < UpdateProcedureRetries
|
|
? LutUpdateState.RepeatLutUpdate
|
|
: LutUpdateState.UpdateFailed;
|
|
break;
|
|
|
|
case LutUpdateState.RepeatLutUpdate:
|
|
_lutUpdateState = LutUpdateState.DownloadLutFile;
|
|
if (_updateProcedureRetryCtr >= IncreaseTimeoutUpdateProcedureRetries)
|
|
{
|
|
_meterFile?.SetExtremeFileWriteTimeout();
|
|
}
|
|
|
|
break;
|
|
|
|
case LutUpdateState.UpdateFailed:
|
|
StopUpdateProcess = true;
|
|
_lutUpdateState = LutUpdateState.Idle;
|
|
break;
|
|
|
|
case LutUpdateState.UploadLutFile:
|
|
break;
|
|
|
|
case LutUpdateState.CompareLutFile:
|
|
break;
|
|
|
|
case LutUpdateState.EraseLutFile:
|
|
break;
|
|
|
|
default:
|
|
_lutUpdateState = LutUpdateState.Idle;
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region LutFile
|
|
/// <summary>
|
|
/// Check the content of the metrology lookup table file
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Feb-25" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
private Boolean ValidateLutFile()
|
|
{
|
|
// check if LUT file contains data
|
|
if (LutFile?.BinData == null || LutFile.BinData.Count < SizeLutFile)
|
|
{
|
|
ErrorMessage += "File size mismatch!";
|
|
return false;
|
|
}
|
|
|
|
LutFile.IsValid = false;
|
|
// extract the identifier and check, if this is a LUT file
|
|
LutFile.StrLutFileId =
|
|
Encoding.UTF8.GetString(LutFile.BinData.ToArray(), IndexLutFileId, IndexDataLength);
|
|
if (LutFile.StrLutFileId != StrLutFileId) return false;
|
|
|
|
LutFile.MeterSize = (MeterSize)LutFile.BinData[IndexMeterSize];
|
|
LutFile.FileCrc = (UInt16)(LutFile.BinData[IndexCrc] + (LutFile.BinData[IndexCrc + 1] << 8));
|
|
LutFile.Version = (UInt16)(LutFile.BinData[IndexVersion] + (LutFile.BinData[IndexVersion + 1] << 8));
|
|
LutFile.DataLength = (UInt32)(LutFile.BinData[IndexDataLength]
|
|
+ (LutFile.BinData[IndexDataLength + 1] << 8)
|
|
+ (LutFile.BinData[IndexDataLength + 2] << 16)
|
|
+ (LutFile.BinData[IndexDataLength + 3] << 24));
|
|
// calculate CRC and compare this with the file CRC
|
|
var entireFile = new List<Byte>();
|
|
entireFile.AddRange(LutFile.BinData);
|
|
var payload = new List<Byte>();
|
|
payload.AddRange(entireFile.GetRange(IndexVersion, LutFileDataLength + LengthVersion));
|
|
var calculatedCrc = Crc16Ccitt.CalculateMsb1021(payload.ToArray());
|
|
if (calculatedCrc != LutFile.FileCrc)
|
|
{
|
|
ErrorMessage += "CRC Mismatch!";
|
|
return false;
|
|
}
|
|
|
|
LutFile.CalculatedCrc = calculatedCrc;
|
|
LutFile.IsValid = true;
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Download the CRC, the meter size and store calibration as preparation for the lookup table
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
private Boolean PrepareLutDownload()
|
|
{
|
|
var returnValue = true;
|
|
|
|
var retryCtr = 0;
|
|
if (LutFile == null || _genesisMeter == null || _meterFile == null) return false;
|
|
//set extended timeout for trigger upgrade response delay
|
|
_genesisMeter.TransmitProtocol.SetResponseTimeout(5000);
|
|
do
|
|
{
|
|
_actualOperation = "Write meter size";
|
|
_operationCtr++;
|
|
if (!_genesisMeter.WriteRegister(Register.Genesisflow.MeterSize, (Byte)LutFile.MeterSize))
|
|
{
|
|
ErrorMessage = "Meter size could not be set!\n";
|
|
_operationCtr--;
|
|
returnValue = false;
|
|
}
|
|
else
|
|
{
|
|
_operationCtr++;
|
|
_actualOperation = "Write Lut CRC to meter";
|
|
if (!_genesisMeter.WriteRegister<UInt32>(Register.Genesisflow.LookupFileCrc, LutFile.FileCrc))
|
|
{
|
|
ErrorMessage += "Meter LUT CRC could not be set!\n";
|
|
_operationCtr--;
|
|
returnValue = false;
|
|
}
|
|
else
|
|
{
|
|
_operationCtr++;
|
|
_actualOperation = "Store calibration to meter";
|
|
if (!_genesisMeter.WriteRegister(Register.Genesisflow.StoreCalibration, 1))
|
|
{
|
|
ErrorMessage += "Meter store calibration failed!\n";
|
|
_operationCtr--;
|
|
returnValue = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!returnValue)
|
|
{
|
|
ReestablishMeterFileSystem();
|
|
}
|
|
} while (!returnValue && retryCtr++ < RegisterWriteRetries && !StopUpdateProcess);
|
|
|
|
//set timeout back to default value
|
|
_genesisMeter.TransmitProtocol.SetDefaultResponseTimeout();
|
|
|
|
return returnValue && !StopUpdateProcess;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Erase file and check if done!
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Mar-03" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
private Boolean EraseFile(String fileDriveName)
|
|
{
|
|
var returnValue = _meterFile.UnlockEraseWriteMeterFile(fileDriveName);
|
|
//erase returns always TRUE, even if the erasure failed! Check with catalogue
|
|
_meterFile.EraseMeterFile(fileDriveName);
|
|
_meterFilesDrive1.Clear();
|
|
if (_meterFile.ReadMeterFileCatalog(out var meterFilesDrive1, MeterFile.StrMeterDrive1,
|
|
MeterFile.WildcardAll.ToString()))
|
|
{
|
|
_meterFilesDrive1.AddRange(meterFilesDrive1);
|
|
if (_meterFilesDrive1.Contains(fileDriveName))
|
|
{
|
|
returnValue = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
returnValue = false;
|
|
}
|
|
return returnValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Download the metrology lookup table files and read the catalog of drive 1
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Feb-16" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
private Boolean DownloadLutFile()
|
|
{
|
|
|
|
//counters for actual process information
|
|
var retryCtr = 0;
|
|
if (LutFile == null) return false;
|
|
|
|
//set extended timeout for trigger upgrade response delay
|
|
_genesisMeter.TransmitProtocol.SetResponseTimeout(5000);
|
|
var returnValue = true;
|
|
//write file portion and retry if not successful
|
|
do
|
|
{
|
|
// read all files which are already installed
|
|
_actualOperation = "Read installed meter files drive 1";
|
|
_operationCtr++;
|
|
if (_meterFilesDrive1 == null)
|
|
{
|
|
_meterFilesDrive1 = new List<String>();
|
|
}
|
|
_meterFilesDrive1.Clear();
|
|
if (_meterFile.ReadMeterFileCatalog(out var meterFilesDrive1, MeterFile.StrMeterDrive1,
|
|
MeterFile.WildcardAll.ToString()))
|
|
{
|
|
_meterFilesDrive1.AddRange(meterFilesDrive1);
|
|
}
|
|
|
|
// erase file
|
|
_operationCtr++;
|
|
_actualFileName = StrLutMeterFileName;
|
|
_actualOperation = $"Erase {_actualFileName}";
|
|
if (!EraseFile(_actualFileName))
|
|
{
|
|
ErrorMessage += $"LUT file {_actualFileName} not erased!\n";
|
|
returnValue = false;
|
|
}
|
|
|
|
_operationCtr++;
|
|
_actualOperation = $"Write {_actualFileName}";
|
|
if (!_meterFile.WriteMeterFile(_actualFileName, LutFile.BinData.ToArray()))
|
|
{
|
|
ErrorMessage += $"Writing of {_actualFileName} failed!\n";
|
|
returnValue = false;
|
|
}
|
|
|
|
// erase file
|
|
_operationCtr++;
|
|
_actualFileName = StrLutBackupMeterFileName;
|
|
_actualOperation = $"Erase {_actualFileName}";
|
|
if (!EraseFile(_actualFileName))
|
|
{
|
|
ErrorMessage += $"LUT file {_actualFileName} not erased!\n";
|
|
returnValue = false;
|
|
}
|
|
|
|
_operationCtr++;
|
|
_actualOperation = $"Write {_actualFileName}";
|
|
if (!_meterFile.WriteMeterFile(_actualFileName, LutFile.BinData.ToArray()))
|
|
{
|
|
ErrorMessage += $"Writing of {_actualFileName} failed!\n";
|
|
returnValue = false;
|
|
}
|
|
|
|
|
|
_operationCtr++;
|
|
_actualOperation = $"Write {_actualFileName}";
|
|
if (!_meterFile.WriteMeterFile(_actualFileName, LutFile.BinData.ToArray()))
|
|
{
|
|
ErrorMessage += $"Writing of {_actualFileName} failed!\n";
|
|
returnValue = false;
|
|
}
|
|
|
|
_operationCtr++;
|
|
_actualOperation = "Read installed meter files drive 1";
|
|
_meterFilesDrive1.Clear();
|
|
if (!_meterFile.ReadMeterFileCatalog(out meterFilesDrive1, MeterFile.StrMeterDrive1,
|
|
MeterFile.WildcardAll.ToString()))
|
|
{
|
|
returnValue = false;
|
|
}
|
|
else
|
|
{
|
|
_meterFilesDrive1.AddRange(meterFilesDrive1);
|
|
if (!_meterFilesDrive1.Contains(StrLutMeterFileName))
|
|
{
|
|
ErrorMessage += $"LUT file {StrLutMeterFileName} not installed!\n";
|
|
returnValue = false;
|
|
}
|
|
|
|
if (!_meterFilesDrive1.Contains(StrLutBackupMeterFileName))
|
|
{
|
|
ErrorMessage += $"LUT file {StrLutBackupMeterFileName} not installed!\n";
|
|
returnValue = false;
|
|
}
|
|
}
|
|
|
|
if (!returnValue)
|
|
{
|
|
ReestablishMeterFileSystem();
|
|
}
|
|
} while (!returnValue && retryCtr++ < FileWriteRetries && !StopUpdateProcess);
|
|
|
|
//set timeout back to default value
|
|
_genesisMeter.TransmitProtocol.SetDefaultResponseTimeout();
|
|
|
|
return !StopUpdateProcess && returnValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load file from memory
|
|
/// </summary>
|
|
/// <param name="filePathName">to binary files</param>
|
|
/// <returns></returns>
|
|
/// <remarks date="2022-Feb-15" author="Thomas Wiedebusch">
|
|
/// - Initial
|
|
/// </remarks>
|
|
public Boolean LoadLutFile(String filePathName)
|
|
{
|
|
if (!File.Exists(filePathName))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
LutFile = null;
|
|
LutFile = new MeterLutFile(filePathName)
|
|
{
|
|
BinData = new List<Byte>(File.ReadAllBytes(filePathName))
|
|
};
|
|
|
|
// validate the file
|
|
return ValidateLutFile();
|
|
}
|
|
#endregion
|
|
}
|
|
} |