|
|
|
@@ -26,7 +26,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
|
|
// Template of FLEXNETVERSION has to be modified for version, version string and CRC
|
|
|
|
|
private static readonly Byte[] TemplateUpg18File =
|
|
|
|
|
private static readonly Byte[] TemplateUpgradeFile =
|
|
|
|
|
{
|
|
|
|
|
0x41, 0x50, 0x50, 0x3E, 0x83, 0xBA, 0x47, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
|
0x04, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00,
|
|
|
|
@@ -39,7 +39,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// upgrade file for FLEXNETVERSION
|
|
|
|
|
private Byte[] _upg18File;
|
|
|
|
|
private Byte[] _upgradeFile;
|
|
|
|
|
|
|
|
|
|
// FLEXNETVERSION application Id
|
|
|
|
|
private const Byte FlexnetVersionAppId = 0x18;
|
|
|
|
@@ -54,7 +54,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
public event EventHandler<ProcessExecEventArgs> OnProcessUpdate;
|
|
|
|
|
|
|
|
|
|
//disk and name of lookup file
|
|
|
|
|
private const String StrFlexnetUpgradeFileName = "1\\upg18";
|
|
|
|
|
private static readonly String StrFlexnetUpgradeFileName = $"1\\upg{FlexnetVersionAppId:X2}";
|
|
|
|
|
|
|
|
|
|
//update reties for files
|
|
|
|
|
private const Int32 FileWriteRetries = 1;
|
|
|
|
@@ -83,9 +83,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
private MeterResetPsuState _meterResetPsuState;
|
|
|
|
|
private MeterResetPsuState _backupMeterResetPsuState;
|
|
|
|
|
|
|
|
|
|
// Look up table file
|
|
|
|
|
public MeterLutFile LutFile;
|
|
|
|
|
|
|
|
|
|
// number of operations for over all access
|
|
|
|
|
private const Int32 NumberOfOperations = 11;
|
|
|
|
|
private Int32 _operationCtr;
|
|
|
|
@@ -291,7 +288,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public void ResetAll()
|
|
|
|
|
{
|
|
|
|
|
LutFile = null;
|
|
|
|
|
//remove the update stop action
|
|
|
|
|
StopUpdateProcess = false;
|
|
|
|
|
|
|
|
|
@@ -509,8 +505,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// generate the upgrade file based on the template
|
|
|
|
|
_upg18File = new Byte[TemplateUpg18File.Length];
|
|
|
|
|
Buffer.BlockCopy(TemplateUpg18File, 0, _upg18File, 0, _upg18File.Length);
|
|
|
|
|
_upgradeFile = new Byte[TemplateUpgradeFile.Length];
|
|
|
|
|
Buffer.BlockCopy(TemplateUpgradeFile, 0, _upgradeFile, 0, _upgradeFile.Length);
|
|
|
|
|
|
|
|
|
|
// rebuild numerical version out of the string because the FLEXNETVERSION version cannot be used
|
|
|
|
|
// as it does lose the "B" information on conversion which is represented with the mask 0x80.
|
|
|
|
@@ -537,21 +533,21 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
strVersion = "R";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_upg18File[MeterFwUpdate.FileAppVersionIndex] = (Byte)(hexVersion & 0xFF);
|
|
|
|
|
_upg18File[MeterFwUpdate.FileAppVersionIndex + 1] = (Byte)((hexVersion & 0xFF00) >> 8);
|
|
|
|
|
_upgradeFile[MeterFwUpdate.FileAppVersionIndex] = (Byte)(hexVersion & 0xFF);
|
|
|
|
|
_upgradeFile[MeterFwUpdate.FileAppVersionIndex + 1] = (Byte)((hexVersion & 0xFF00) >> 8);
|
|
|
|
|
|
|
|
|
|
// build the version string and copy it to the upgrade file
|
|
|
|
|
strVersion += $"{charVersion[0]}.{charVersion[1]}.{charVersion[2]}{charVersion[3]}";
|
|
|
|
|
var upg18Idx = FlexVersionStringIndex;
|
|
|
|
|
foreach (var t in strVersion)
|
|
|
|
|
{
|
|
|
|
|
_upg18File[upg18Idx] = Convert.ToByte(t);
|
|
|
|
|
_upgradeFile[upg18Idx] = Convert.ToByte(t);
|
|
|
|
|
upg18Idx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// take the payload starting with version index
|
|
|
|
|
var payload = new Byte[_upg18File.Length - MeterFwUpdate.FileAppVersionIndex];
|
|
|
|
|
Buffer.BlockCopy(_upg18File, MeterFwUpdate.FileAppVersionIndex, payload, 0, payload.Length);
|
|
|
|
|
var payload = new Byte[_upgradeFile.Length - MeterFwUpdate.FileAppVersionIndex];
|
|
|
|
|
Buffer.BlockCopy(_upgradeFile, MeterFwUpdate.FileAppVersionIndex, payload, 0, payload.Length);
|
|
|
|
|
var calculatedCrc = Crc16Ccitt.CalculateMsb1021(payload);
|
|
|
|
|
|
|
|
|
|
// avoid replacement wit invalid generated FLEXNETVERSION
|
|
|
|
@@ -561,8 +557,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// replace the CRC
|
|
|
|
|
_upg18File[MeterFwUpdate.FileAppCrcIndex] = (Byte)(calculatedCrc & 0xFF);
|
|
|
|
|
_upg18File[MeterFwUpdate.FileAppCrcIndex + 1] = (Byte)((calculatedCrc & 0xFF00) >> 8);
|
|
|
|
|
_upgradeFile[MeterFwUpdate.FileAppCrcIndex] = (Byte)(calculatedCrc & 0xFF);
|
|
|
|
|
_upgradeFile[MeterFwUpdate.FileAppCrcIndex + 1] = (Byte)((calculatedCrc & 0xFF00) >> 8);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@@ -577,7 +573,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
private Boolean DownloadUpgradeFile()
|
|
|
|
|
{
|
|
|
|
|
//initiate upgrade by writing the upgrade control file
|
|
|
|
|
if (_upg18File == null || _upg18File.Length != TemplateUpg18File.Length ||
|
|
|
|
|
if (_upgradeFile == null || _upgradeFile.Length != TemplateUpgradeFile.Length ||
|
|
|
|
|
!_meterFile.UnlockEraseWriteMeterFile(StrFlexnetUpgradeFileName))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
@@ -590,7 +586,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
//write file and retry if not successful
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
returnValue = _meterFile.WriteMeterFile(StrFlexnetUpgradeFileName, _upg18File);
|
|
|
|
|
returnValue = _meterFile.WriteMeterFile(StrFlexnetUpgradeFileName, _upgradeFile);
|
|
|
|
|
|
|
|
|
|
if (!returnValue)
|
|
|
|
|
{
|
|
|
|
@@ -598,7 +594,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
|
|
|
|
|
}
|
|
|
|
|
} while (!returnValue && retryCtr++ < FileWriteRetries && !StopUpdateProcess);
|
|
|
|
|
|
|
|
|
|
_upg18File = null;
|
|
|
|
|
_upgradeFile = null;
|
|
|
|
|
return !StopUpdateProcess && returnValue;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|