ResetStaticProperties( ) eliminated from ComponentBase, IComponentFactory and factories.

This commit is contained in:
Milan Hanajik
2021-04-02 16:10:38 +02:00
parent c7e87c95da
commit dd08ca770d
182 changed files with 34 additions and 408 deletions
+26 -38
View File
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using log4net;
using Dirichlet.Numerics;
using SchematicDrawing;
using TBF.Rig.ControlBoard.Uni;
using TBF.Rig.Generic;
using TBF.Boxes;
@@ -12,41 +13,20 @@ using TBF.Resources;
namespace TBF.Rig.Uni.Diverter
{
public class Diverter : ComponentBase, IDevice, GenericDevices.IDiverter, GenericDevices.ISequenceCondition, GenericDevices.IHasCalendarEvents, SchematicDrawing.IDrawingItCmpnt
public class Diverter : ComponentBase, IDevice, GenericDevices.IDiverter, GenericDevices.ISequenceCondition, GenericDevices.IHasCalendarEvents, IDrawingItCmpnt
{
private static readonly ILog log = LogManager.GetLogger(typeof(Diverter));
public override string ToString() { return string.Format("Diverter({0})", Cfg.ToString(-1)); }
/// <summary>
/// Enumeration of balances via static fields and methods
/// </summary>
static int nextIdx = 0;
public static new void ResetStaticProperties()
{
nextIdx = 0;
}
public static int DivertersCount { get { return nextIdx; } }
public static GenericDevices.IDiverter[] Diverters;
/// Configuration and wrappers
readonly DiverterCfg divCfg;
public SchematicDrawing.IDrawingItem DrawingItem { get { return divCfg as SchematicDrawing.IDrawingItem; } }
readonly UniCB cBoard;
readonly UInt128 mask; /// derived from bitPosition in the constructor
///
public int DiverterNr { get { return divCfg.DivNr1; } } /// 1-based public diverter number
public int AdcNr { get { return divCfg.AdcNr; } }
readonly IOperation diverterToTankOp;
readonly IOperation diverterToSinkOp;
public bool State { get { return (cBoard.Route & mask) != 0; } }
public int AdcValueToSink { get { return divCfg.AdcValueToSink; } }
public int AdcValueToTank { get { return divCfg.AdcValueToTank; } }
public IDrawingItem DrawingItem { get { return divCfg as IDrawingItem; } }
///
public int StartThreshold
{
get { return Math.Max(0, Math.Min(1023, Convert.ToInt32(divCfg.AdcValueToSink + (divCfg.AdcValueToTank - divCfg.AdcValueToSink) * (divCfg.StartThresholdPct / 100.0)))); }
@@ -60,6 +40,16 @@ namespace TBF.Rig.Uni.Diverter
get { return Math.Max(0, Math.Min(1023, Convert.ToInt32(divCfg.AdcValueToSink + (divCfg.AdcValueToTank - divCfg.AdcValueToSink) * (divCfg.ThresholdHiPct / 100.0)))); }
}
readonly UniCB uniCB;
readonly UInt128 mask; /// derived from bitPosition in the constructor
///
public bool State { get { return (uniCB.Route & mask) != 0; } }
readonly IOperation diverterToTankOp;
readonly IOperation diverterToSinkOp;
FloatBox switchTimeStart;
FloatBox switchTimeEnd;
public FloatBox SwitchTimeStart { get { return switchTimeStart; } }
@@ -74,17 +64,15 @@ namespace TBF.Rig.Uni.Diverter
}
public Diverter()
{
}
public Diverter() { }
public Diverter(Generic.IComponentCfg cfg, IList<Generic.IComponent> components)
: base(cfg)
{
divCfg = cfg as DiverterCfg;
cBoard = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
if (cBoard == null) throw new Exception("Cannot find " + Name + " parent");
uniCB = TbfComponents.FindComponent(cfg.ParentName, components) as UniCB;
if (uniCB == null) throw new Exception("Cannot find " + Name + " parent");
if (cfg.DebugLevel != Config.Entities.DebugMode.Off)
{
@@ -106,8 +94,8 @@ namespace TBF.Rig.Uni.Diverter
// Name, cBoard.RegValveCalib.GetLength(0), diverterCfg.AdcNr);
//}
diverterToTankOp = new SwitchDiverterOp(cBoard, DiverterNr, true);
diverterToSinkOp = new SwitchDiverterOp(cBoard, DiverterNr, false);
diverterToTankOp = new SwitchDiverterOp(uniCB, DiverterNr, true);
diverterToSinkOp = new SwitchDiverterOp(uniCB, DiverterNr, false);
log.Warn(this.ToString());
}
@@ -154,7 +142,7 @@ namespace TBF.Rig.Uni.Diverter
public void Initialize() { }
public void RunDeviceBefore()
{
Int16 adcValue = cBoard.Data.AnalogInput[divCfg.AdcNr];
Int16 adcValue = uniCB.Data.AnalogInput[divCfg.AdcNr];
Handlers.OnAdcChanged(this, new CmdResponseArgs(CfgChangeCmd.GetAdc, divCfg.BitNr, adcValue));
}
public void RunDeviceAfter() { }
@@ -204,20 +192,20 @@ namespace TBF.Rig.Uni.Diverter
}
else if (args.Command == CfgChangeCmd.GetAdc1 || args.Command == CfgChangeCmd.GetAdc2)
{
Int16 adcValue = cBoard.Data.AnalogInput[divCfg.AdcNr];
Int16 adcValue = uniCB.Data.AnalogInput[divCfg.AdcNr];
DiverterCfgCtrl.OnCmdResponse(this, new CmdResponseArgs(args.Command, divCfg.BitNr, adcValue));
}
else if (args.Command == CfgChangeCmd.DivToTank)
{
cBoard.SwitchDiverter(true, divCfg.DivNr1, true);
uniCB.SwitchDiverter(true, divCfg.DivNr1, true);
}
else if (args.Command == CfgChangeCmd.DivToSink)
{
cBoard.SwitchDiverter(true, divCfg.DivNr1, false);
uniCB.SwitchDiverter(true, divCfg.DivNr1, false);
}
else if (args.Command == CfgChangeCmd.ReadDivTransition)
{
cBoard.GetDiverterTransitionData(true, this, this.State);
uniCB.GetDiverterTransitionData(true, this, this.State);
}
}
};
-2
View File
@@ -11,8 +11,6 @@ namespace TBF.Rig.Uni.Diverter
public string ClassName { get { return "Diverter"; } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { Diverter.ResetStaticProperties(); }
public IComponent DummyComponent() { return new Diverter(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Diverter(cfg, components); }
-2
View File
@@ -11,8 +11,6 @@ namespace TBF.Rig.Uni.FlowMeter
public string ClassName { get { return "FlowMeter"; } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { FlowMeter.ResetStaticProperties(); }
public IComponent DummyComponent() { return new FlowMeter(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new FlowMeter(cfg, components); }
@@ -11,8 +11,6 @@ namespace TBF.Rig.Uni.FlowMetersInParallel
public string ClassName { get { return "FlowMetersInParallel"; } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { FlowMeter.ResetStaticProperties(); }
public IComponent DummyComponent() { return new FlowMeter(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new FlowMeter(cfg, components); }
-2
View File
@@ -11,8 +11,6 @@ namespace TBF.Rig.Uni.RegValve
public string ClassName { get { return "RegValve"; } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { RegValve.ResetStaticProperties(); }
public IComponent DummyComponent() { return new RegValve(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new RegValve(cfg, components); }
-2
View File
@@ -11,8 +11,6 @@ namespace TBF.Rig.Uni.RegValveAnalog
public string ClassName { get { return "RegValveAnalog"; } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { RegValve.ResetStaticProperties(); }
public IComponent DummyComponent() { return new RegValve(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new RegValve(cfg, components); }
-2
View File
@@ -11,8 +11,6 @@ namespace TBF.Rig.Uni.RegValveTandem
public string ClassName { get { return "RegValveTandem"; } }
public override string ToString() { return ClassName; }
public void ResetStaticProperties() { RegValveTandem.ResetStaticProperties(); }
public IComponent DummyComponent() { return new RegValveTandem(); }
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new RegValveTandem(cfg, components); }