common/Hardware/WaterMeter/Genesis/GenesisFile/MeterFwUpdateCapability.cs
2026-04-23 17:50:07 +02:00

67 lines
3.3 KiB
C#

using System;
using System.Linq;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore.Consts;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile
{
/// <summary>
/// Update capability check for all necessary settings according to meter.
/// </summary>
public static class MeterFwUpdateCapability
{
/// <summary>
/// Checks if the metrology upgrade is allowed or the version is already installed.
/// The application description file "ADF" has to be read in advance as this contains the "GENSISFLOW" version.
/// </summary>
/// <param name="meterFwUpdate"></param>
/// <param name="currentGenesis">the current Genesis</param>
/// <returns>true if upgrade is allowed or the metrology version is up-to-date</returns>
/// <remarks date="2021-Jan-14" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2021-Jan-27" author="Thomas Wiedebusch">
/// - Removed upgrade permission 0 check.
/// </remarks>
public static Boolean CheckMetrology(MeterFwUpdate meterFwUpdate, IGenesisMeter currentGenesis)
{
if (meterFwUpdate == null || currentGenesis == null) return false;
// if the update is allowed, a version check is not needed
if (currentGenesis.MetrologyUpgradePermission == MetrologyDefinition.MetrologyUpgradePermitted) return true;
// extract the metrology version and CRC from the Genesis meter.
var installedMetrology =
currentGenesis.MeterAppListVersion.FirstOrDefault(im => im.AppName == MetrologyDefinition.MetrologyName);
// extract version and CRC from the ADF, ATTENTION the AppName is not det here, so check for AppId!
var requiredMetrology = meterFwUpdate.FileApps.FirstOrDefault(rm => installedMetrology != null &&
rm.AppId == installedMetrology.AppId);
// if the installed version equals the required version the update is allowed
return requiredMetrology != null && installedMetrology != null &&
installedMetrology.Version == requiredMetrology.Version &&
installedMetrology.Crc == requiredMetrology.Crc;
}
/// <summary>
/// Checks if the core version is in range of required minimum to maximum version.
/// The package file has to be read in advance as this contains the min/max.
/// </summary>
/// <param name="meterFwUpdate"></param>
/// <param name="coreRevision">containing the core version</param>
/// <returns>true if version is in range</returns>
/// <remarks date="2020-Dec-08" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2022-Dec-05" author="Thomas Wiedebusch">
/// - Core revision data type changed from string ti int32?.
/// </remarks>
public static Boolean CheckCoreRevision(MeterFwUpdate meterFwUpdate, Int32? coreRevision)
{
if (coreRevision == null || meterFwUpdate == null ) return false;
return meterFwUpdate.CheckCoreRevision(coreRevision);
}
}
}