MeterFile: VerifyMeterFile for binary compare of given file with file in Genesis Meter

This commit is contained in:
Thomas Wiedebusch
2022-04-06 14:11:23 +02:00
parent 81e7e16653
commit 9f8d315b8f
6 changed files with 24 additions and 41 deletions
+1 -1
View File
@@ -155,7 +155,7 @@
</site>
<site name="MeterProcessState" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\drabesch_ro\Repo\lab\la_operations\laa_production\Common\Service\MeterProcessState" />
<virtualDirectory path="/" physicalPath="D:\Projekte\SENSUS_GitLab\laa_production\Common\Service\MeterProcessState" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:56011:localhost" />
@@ -1296,15 +1296,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
var versionString = fm.IsInstalled
? $"V: {fm.StrVersion} - CRC: 0x{fm.Crc:X4}" : "Not installed";
_logger.Info($"AppId: 0x{fm.AppId:X2} - {versionString} - AppName: {fm.AppName}");
if (fm.AppName.ToUpper() == "SENSUSRADIO" && fm.IsInstalled)
{
var radioFrequency = ReadRegister(Register.Sensusradio.FrequencyIndicator);
var tmpList = radioFrequency.ToList();
tmpList.Reverse();
var strRawResult = BitConverter.ToString(tmpList.ToArray());
RegionRadio = $"EMEA_{strRawResult}";
}
}
_logger.Info($"Meter size: {MeterSize}");
@@ -545,26 +545,30 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <summary>
/// Meter file verification against given data
/// Takes into account, that the read file is always integer dividable by 4 due to the chunk size
/// of the write and read access to the Genesis.
/// </summary>
/// <param name="fileName">file name as string</param>
/// <param name="dataBytes">data to store</param>
/// <returns>true: file found and verified</returns>
/// <remarks date="2019-Jun-20" author="Thomas Wiedebusch">
/// <remarks date="2022-Apr-06" author="Thomas Wiedebusch">
/// - Initial
/// </remarks>
/// <remarks date="2022-Apr-01" author="Thomas Wiedebusch">
/// - Add a NULL at the end of the file name.
/// </remarks>
public Boolean VerifyMeterFile(String fileName, Byte[] dataBytes)
{
//add file name delimiter
fileName += StringDelimiter;
var returnValue = true;
if (!OpenMeterFile(fileName, StrOpenFileReadOnlyMode))
return false;
//TODO THW implement
//read raw data from meter
return true;
if (!ReadMeterFile(fileName, out var binData, dataBytes.Length)) return true;
// compare the entire buffer which also includes the header of the file, remind the original
// buffer may be smaller due to the chunk size of the communication (always dividable by 4),
// meaning the receive buffer is always and integer of this chunk size!
if (dataBytes.Where((t, ctr) => t != binData[ctr]).Any())
{
returnValue = false;
}
return returnValue;
}
/// <summary>
@@ -887,6 +887,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
/// <remarks date="2022-Apr-01" author="Thomas Wiedebusch">
/// - Take the different size of original and receive buffer, which is an integer division by 4, into account.
/// </remarks>
/// <remarks date="2022-Apr-06" author="Thomas Wiedebusch">
/// - Exported file compare to <see cref="MeterFile"/>.
/// </remarks>
private Boolean UploadAndCompareLutFiles()
{
//counters for actual process information
@@ -911,31 +914,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
// logout and re-login to clear all ongoing processes and clear the Genesis buffers
ReestablishMeterFileSystem();
if (_meterFile.ReadMeterFile(fileToUpload, out var binData, SizeLutFile))
if (!_meterFile.VerifyMeterFile(fileToUpload, LutFile.BinData.ToArray()))
{
// compare the entire buffer which also includes the header of the file, remind the original
// buffer may be smaller due to the chunk size of the communication (always dividable by 4),
// meaning the receive buffer is always and integer of this chunk size!
if (LutFile.BinData.Where((t, ctr) => t != binData[ctr]).Any())
{
ErrorMessage = $"Meter LUT file is unequal to downloaded {fileToUpload}!";
returnValue = false;
_operationCtr--;
}
if (returnValue)
{
OnProcessUpdate?.Invoke(this,
new ProcessExecEventArgs($"LUT file {fileToUpload} of meter successfully compared!"));
}
}
else
{
ErrorMessage += $"Reading of {fileToUpload} failed!";
returnValue = false;
_operationCtr--;
OnProcessUpdate?.Invoke(this,
new ProcessExecEventArgs($"LUT file {fileToUpload} of meter successfully compared!"));
}
}
@@ -1 +1 @@
46bd00889699f5a20a4981a22f62b66368323855
7ac73abb7afd9e6ddc0520a1568581c7ed0afd36
@@ -1 +1 @@
0d85a5b3a7561b41163c20e5dc7713bcd0d65555
f64d563def603c89cafafa61a3219ba97e1e344c