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 { /// /// Update capability check for all necessary settings according to meter. /// public static class MeterFwUpdateCapability { /// /// 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. /// /// /// the current Genesis /// true if upgrade is allowed or the metrology version is up-to-date /// /// - Initial. /// /// /// - Removed upgrade permission 0 check. /// 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; } /// /// 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. /// /// /// containing the core version /// true if version is in range /// /// - Initial. /// /// /// - Core revision data type changed from string ti int32?. /// public static Boolean CheckCoreRevision(MeterFwUpdate meterFwUpdate, Int32? coreRevision) { if (coreRevision == null || meterFwUpdate == null ) return false; return meterFwUpdate.CheckCoreRevision(coreRevision); } } }