GTB: -FwUpdate, LUT Update and MeterFile ReadMeterFile modified
This commit is contained in:
@@ -34,10 +34,21 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
//wb open file for writing in binary mode, if file exists its contents will be overwritten,
|
||||
//if file does not exist it will be created
|
||||
private const String StrNewFileReadWriteMode = "wb";
|
||||
//Open for reading in binary mode. If the file does not exist, fopen( ) returns NULL
|
||||
//Open for reading in binary mode. If the file does not exist, FOpen returns NULL
|
||||
private const String StrOpenFileReadOnlyMode = "rb";
|
||||
//Open for both reading and writing in binary mode. If the file does not exist, fopen( ) returns NULL
|
||||
//Open for both reading and writing in binary mode. If the file does not exist, FOpen returns NULL
|
||||
private const String StrOpenFileReadWriteMode = "rb+";
|
||||
|
||||
/// <summary>
|
||||
/// FSeek for start of file
|
||||
/// </summary>
|
||||
public const Int32 FSeekStartOfFile = 0;
|
||||
|
||||
/// <summary>
|
||||
/// FSeek for end of file
|
||||
/// </summary>
|
||||
public const Int32 FSeekEndOfFile = 2;
|
||||
|
||||
private String _fileName;
|
||||
private Int32 _overallBytesCtr;
|
||||
|
||||
@@ -270,12 +281,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
_currentGenesis.ReadRegister(Register.Configexchange.FileWrite));
|
||||
returnedFileOffset = ReadFilePointerOffset();
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// //read DUMMY to overcome FW malfunction
|
||||
// _currentGenesis.ReadRegister(Register.System.MonotonicSeconds);
|
||||
//}
|
||||
|
||||
|
||||
//set timeout back to default value
|
||||
_currentGenesis.TransmitProtocol.SetDefaultResponseTimeout();
|
||||
CommunicationConfig.RequestRetries = CommunicationConfig.DefaultRequestRetries;
|
||||
@@ -300,7 +306,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// </summary>
|
||||
/// <param name="fileName">file name as string</param>
|
||||
/// <param name="readBackData">empty list of data</param>
|
||||
/// <param name="readBackCount">size to read</param>
|
||||
/// <returns>file content as byte array</returns>
|
||||
/// <remarks date="2019-Jun-20" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
@@ -333,7 +338,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// <remarks date="2022-Apr-01" author="Thomas Wiedebusch">
|
||||
/// - Add a NULL at the end of the file name.
|
||||
/// </remarks>
|
||||
public Boolean ReadMeterFile(String fileName, out List<Byte> readBackData, Int32 readBackCount)
|
||||
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
|
||||
/// - Read data according to file size searched with FSeek.
|
||||
/// </remarks>
|
||||
public Boolean ReadMeterFile(String fileName, out List<Byte> readBackData)
|
||||
{
|
||||
//set processing counter
|
||||
ProcessedBytesCtr = 0;
|
||||
@@ -343,8 +351,12 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
fileName += StringDelimiter;
|
||||
|
||||
readBackData = new List<Byte>();
|
||||
var returnValue = OpenMeterFile(fileName, StrOpenFileReadOnlyMode);
|
||||
|
||||
// Get the current file size
|
||||
var returnValue = GetFileSize(fileName, out var readBackCount);
|
||||
|
||||
returnValue &= OpenMeterFile(fileName, StrOpenFileReadOnlyMode);
|
||||
|
||||
if (returnValue)
|
||||
{
|
||||
//set register write retries to 0 to avoid doubling of records
|
||||
@@ -524,11 +536,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
_currentGenesis.ReadRegister(Register.Configexchange.FileWrite));
|
||||
returnedFileOffset = ReadFilePointerOffset();
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// //read DUMMY to overcome FW malfunction
|
||||
// _currentGenesis.ReadRegister(Register.System.MonotonicSeconds);
|
||||
//}
|
||||
|
||||
//set timeout back to default value
|
||||
_currentGenesis.TransmitProtocol.SetDefaultResponseTimeout();
|
||||
@@ -543,6 +550,34 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses FSeek to get the file size.
|
||||
/// </summary>
|
||||
/// <param name="fileName">file name as string</param>
|
||||
/// <param name="fileSize">file size of the given file</param>
|
||||
/// <returns>true: file found </returns>
|
||||
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
/// </remarks>
|
||||
public Boolean GetFileSize(String fileName, out Int32 fileSize)
|
||||
{
|
||||
fileSize = 0;
|
||||
var returnValue = OpenMeterFile(fileName, StrOpenFileReadOnlyMode);
|
||||
|
||||
if (returnValue)
|
||||
{
|
||||
returnValue &= SetFilePointerOffset(fSeekPara: FSeekEndOfFile);
|
||||
|
||||
if (returnValue)
|
||||
{
|
||||
fileSize = ReadFilePointerOffset();
|
||||
}
|
||||
}
|
||||
|
||||
returnValue &= CloseMeterFile();
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <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
|
||||
@@ -561,15 +596,23 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
{
|
||||
var returnValue = true;
|
||||
|
||||
if (!ReadMeterFile(fileName, out var binData, dataBytes.Length)) return false;
|
||||
if (!ReadMeterFile(fileName, out var binData)|| binData == null || binData.Count == 0)
|
||||
return false;
|
||||
|
||||
// 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())
|
||||
for (var ctr = 0; ctr < dataBytes.Length; ctr++)
|
||||
{
|
||||
returnValue = false;
|
||||
if (binData[ctr] != dataBytes[ctr])
|
||||
{
|
||||
returnValue = false;
|
||||
}
|
||||
}
|
||||
//if (dataBytes.Where((t, ctr) => t != binData[ctr]).Any())
|
||||
//{
|
||||
// returnValue = false;
|
||||
//}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
@@ -639,9 +682,11 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FSeek implementation of genesis meter
|
||||
/// FSeek implementation of genesis meter. FOpen has to be executed in advance to get
|
||||
/// the file pointer.
|
||||
/// </summary>
|
||||
/// <param name="filePointerOffset"></param>
|
||||
/// <param name="fSeekPara">positioning to file start or end</param>
|
||||
/// <returns></returns>
|
||||
/// <remarks date="2019-Jun-20" author="Thomas Wiedebusch">
|
||||
/// - Initial
|
||||
@@ -656,10 +701,17 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
/// - Retries changed for and back,
|
||||
/// - Timeout changed for and back.
|
||||
/// </remarks>
|
||||
private Boolean SetFilePointerOffset(Int32 filePointerOffset)
|
||||
/// <remarks date="2023-Jan-02" author="Thomas Wiedebusch">
|
||||
/// - Extended FSeek for file end positioning.
|
||||
/// </remarks>
|
||||
private Boolean SetFilePointerOffset(Int32 filePointerOffset = 0, Int32 fSeekPara = FSeekStartOfFile)
|
||||
{
|
||||
Boolean returnValue;
|
||||
var retryCtr = 0;
|
||||
if (FSeekEndOfFile == fSeekPara)
|
||||
{
|
||||
filePointerOffset = 0;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
@@ -680,7 +732,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
returnValue &= _currentGenesis.WriteRegister(Register.Configexchange.SetFilePointerOffset,
|
||||
filePointerOffset, false);
|
||||
returnValue &= _currentGenesis.WriteRegister(Register.Configexchange.SetFilePointerOffset,
|
||||
0, false);
|
||||
fSeekPara, false);
|
||||
|
||||
//function call returns 0 if FSeek successfully set
|
||||
returnValue &= 0 == RegisterConverter.ConvertTo<UInt32>(_currentGenesis.ReadRegister(
|
||||
|
||||
@@ -743,7 +743,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
||||
|
||||
var returnValue = true;
|
||||
|
||||
//write LUT files and retry if not successful
|
||||
//read config file and retry if not successful
|
||||
do
|
||||
{
|
||||
_actualOperation = Resources.StrUploadConfigFile;
|
||||
@@ -751,7 +751,7 @@ 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(StrConfigMeterFileName, out ConfigFile.BinData, 5000))
|
||||
if (!_meterFile.ReadMeterFile(StrConfigMeterFileName, out ConfigFile.BinData))
|
||||
{
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user