149 lines
5.7 KiB
C#
149 lines
5.7 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Sequences;
|
|
|
|
namespace TBF.BenchControl.Various.ErrorFlags
|
|
{
|
|
public class Errors : ComponentBase, GenericDevices.IErrorFlags
|
|
{
|
|
/// TODO: Implement support for sharing one camera by multiple ROI-s
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(Errors));
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0}({1})", this.GetType().Namespace.Substring(17), Cfg.ToString(1));
|
|
}
|
|
|
|
///
|
|
/// Cfg
|
|
///
|
|
readonly ErrorsCfg errorsCfg;
|
|
public ErrorFlagsMode Mode { get { return errorsCfg.TestParams.Mode; } }
|
|
|
|
|
|
public int GetErrorFlags(Test test, double testTime)
|
|
{
|
|
/// Any E# is 'true' on error, 'false' when OK
|
|
|
|
if (Mode != ErrorFlagsMode.Info && Mode != ErrorFlagsMode.On) return 0; /// return 0 when Mode == ErrorFlagsMode.Off
|
|
|
|
/// Max. and min. flow
|
|
bool E1 = ProcessData.RefFlowStat.Min < test.Qfrom
|
|
|| ProcessData.RefFlowStat.Max > test.Qto;
|
|
|
|
/// Max. and min. up and down water temperature
|
|
bool E2 = ProcessData.TempUpStat.Min < test.TempLimLo
|
|
|| ProcessData.TempUpStat.Max > test.TempLimHi
|
|
|| ProcessData.TempDownStat.Min < test.TempLimLo
|
|
|| ProcessData.TempDownStat.Max > test.TempLimHi;
|
|
|
|
/// Max. flow deviation
|
|
bool E3 = ProcessData.RefFlowStat.Min < ProcessData.RefFlowStat.Average * (1.0f - errorsCfg.TestParams.Delta_Q_pct / 100.0f)
|
|
|| ProcessData.RefFlowStat.Max > ProcessData.RefFlowStat.Average * (1.0f + errorsCfg.TestParams.Delta_Q_pct / 100.0f);
|
|
|
|
/// Max. up and down water temperature deviation
|
|
bool E4 = ProcessData.TempUpStat.Min < ProcessData.TempUpStat.Average - errorsCfg.TestParams.Delta_T
|
|
|| ProcessData.TempUpStat.Max > ProcessData.TempUpStat.Average + errorsCfg.TestParams.Delta_T
|
|
|| ProcessData.TempDownStat.Min < ProcessData.TempDownStat.Average - errorsCfg.TestParams.Delta_T
|
|
|| ProcessData.TempDownStat.Max > ProcessData.TempDownStat.Average + errorsCfg.TestParams.Delta_T;
|
|
|
|
/// Max. absolute value of up and down water temperature difference
|
|
bool E5 = ProcessData.TempDiffStat.Max > errorsCfg.TestParams.Delta_Tup_Tdn;
|
|
|
|
bool E6 = false;
|
|
|
|
/// Test time (min)
|
|
bool E7 = testTime < errorsCfg.TestParams.TestTime_min;
|
|
|
|
/// Test time (max)
|
|
bool E8 = testTime > errorsCfg.TestParams.TestTime_max;
|
|
|
|
bool E9 = false;
|
|
bool E10 = false;
|
|
bool E11 = false;
|
|
bool E12 = false;
|
|
|
|
/// Ambient temperature
|
|
bool E13 = ProcessData.AmbTempStat.Min < errorsCfg.TestParams.AmbTemp_min
|
|
|| ProcessData.AmbTempStat.Max > errorsCfg.TestParams.AmbTemp_max;
|
|
|
|
/// Water pressure
|
|
bool E14 = ProcessData.PressUpStat.Min < errorsCfg.TestParams.Pressure_min
|
|
|| ProcessData.PressUpStat.Max > errorsCfg.TestParams.Pressure_max;
|
|
|
|
bool E15 = false;
|
|
bool E16 = false;
|
|
|
|
int ErrorFlags = 0;
|
|
if (errorsCfg.TestParams.E1 && E1) ErrorFlags |= 0x0001;
|
|
if (errorsCfg.TestParams.E2 && E2) ErrorFlags |= 0x0002;
|
|
if (errorsCfg.TestParams.E3 && E3) ErrorFlags |= 0x0004;
|
|
if (errorsCfg.TestParams.E4 && E4) ErrorFlags |= 0x0008;
|
|
if (errorsCfg.TestParams.E5 && E5) ErrorFlags |= 0x0010;
|
|
if (errorsCfg.TestParams.E6 && E6) ErrorFlags |= 0x0020;
|
|
if (errorsCfg.TestParams.E7 && E7) ErrorFlags |= 0x0040;
|
|
if (errorsCfg.TestParams.E8 && E8) ErrorFlags |= 0x0080;
|
|
if (errorsCfg.TestParams.E9 && E9) ErrorFlags |= 0x0100;
|
|
if (errorsCfg.TestParams.E10 && E10) ErrorFlags |= 0x0200;
|
|
if (errorsCfg.TestParams.E11 && E11) ErrorFlags |= 0x0400;
|
|
if (errorsCfg.TestParams.E12 && E12) ErrorFlags |= 0x0800;
|
|
if (errorsCfg.TestParams.E13 && E13) ErrorFlags |= 0x1000;
|
|
if (errorsCfg.TestParams.E14 && E14) ErrorFlags |= 0x2000;
|
|
if (errorsCfg.TestParams.E15 && E15) ErrorFlags |= 0x4000;
|
|
if (errorsCfg.TestParams.E16 && E16) ErrorFlags |= 0x8000;
|
|
return ErrorFlags;
|
|
}
|
|
|
|
|
|
public Errors()
|
|
{
|
|
}
|
|
|
|
public Errors(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
|
|
: base(cfg)
|
|
{
|
|
errorsCfg = cfg as ErrorsCfg;
|
|
|
|
StartChangeHandler();
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
#region Configuration Change Handling
|
|
|
|
public static void OnCfgChange(object sender, CfgChangeArgs args)
|
|
{
|
|
if (CfgChangeHandler == null) return;
|
|
try { CfgChangeHandler(sender, args); }
|
|
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
|
|
}
|
|
|
|
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
|
|
|
|
public override void StartChangeHandler()
|
|
{
|
|
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
|
|
{
|
|
ErrorsCfg tmpcfg = args.Cfg as ErrorsCfg;
|
|
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
|
|
{
|
|
if (args.Command == CfgChangeCmd.CfgChange)
|
|
{
|
|
//errorsCfg.BlackAndWhite = tmpcfg.BlackAndWhite;
|
|
//errorsCfg.LowResolution = tmpcfg.LowResolution;
|
|
//errorsCfg.ImageRotation = tmpcfg.ImageRotation;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#endregion Configuration Change Handling
|
|
}
|
|
}
|