From bb3a6ff4f3ea87b83820096eab5f26de9cd11f7b Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Fri, 2 Apr 2021 20:26:48 +0200 Subject: [PATCH] BuiltIn components clean-up. --- TBF/Rig/BuiltIn/PumpTandem/Pump.cs | 23 +++++++++++++---------- TBF/Rig/BuiltIn/Valve/Valve.cs | 29 ++++++++++++----------------- TBF/Rig/BuiltIn/ValveEx/Valve.cs | 18 +++++------------- TBF/Rig/BuiltIn/ValveEx/ValveCfg.cs | 2 +- TBF/Rig/ControlBoard/Uni/UniCB.cs | 2 +- 5 files changed, 32 insertions(+), 42 deletions(-) diff --git a/TBF/Rig/BuiltIn/PumpTandem/Pump.cs b/TBF/Rig/BuiltIn/PumpTandem/Pump.cs index b84082738..2f92b3144 100644 --- a/TBF/Rig/BuiltIn/PumpTandem/Pump.cs +++ b/TBF/Rig/BuiltIn/PumpTandem/Pump.cs @@ -19,8 +19,8 @@ namespace TBF.Rig.BuiltIn.PumpTandem readonly GenericDevices.IPump pump1; readonly GenericDevices.IPump pump2; - readonly GenericDevices.IPumpFM pumpFm1; - readonly GenericDevices.IPumpFM pumpFm2; + GenericDevices.IPumpFM pumpFm1; + GenericDevices.IPumpFM pumpFm2; public bool State { get { return pump1.State || pump2.State; } } @@ -38,8 +38,8 @@ namespace TBF.Rig.BuiltIn.PumpTandem public int LagClosing { get { return 0; } } - readonly UInt128 mask1; - readonly UInt128 mask2; + UInt128 mask1; + UInt128 mask2; public UInt128 Mask { get { return mask1 | mask2; } } /// derived from masks of two pumps @@ -56,11 +56,16 @@ namespace TBF.Rig.BuiltIn.PumpTandem pump2 = TbfComponents.FindComponent(pumpCfg.Pump2, components) as GenericDevices.IPump; if (pump2 == null) throw new Exception("Cannot find component Pump 2"); - pumpFm1 = pump1 as GenericDevices.IPumpFM; - pumpFm2 = pump2 as GenericDevices.IPumpFM; + log.Warn(this.ToString()); + } + + public override void Initialize() + { + pumpFm1 = pump1 as GenericDevices.IPumpFM; + pumpFm2 = pump2 as GenericDevices.IPumpFM; if (pump1 is BuiltIn.Pump.Pump) { mask1 = (pump1 as BuiltIn.Pump.Pump).Mask; } - else if (pump1 is Danfoss.VLT2800.Pump) { mask1 = (pump1 as Danfoss.VLT2800.Pump).Mask; } + else if (pump1 is Danfoss.VLT2800.Pump) { mask1 = (pump1 as Danfoss.VLT2800.Pump).Mask; } else if (pump1 is Modbus.PumpFM.DanfossVLT.Pump) { mask1 = (pump1 as Modbus.PumpFM.DanfossVLT.Pump).Mask; } else { mask1 = 0; } @@ -68,9 +73,7 @@ namespace TBF.Rig.BuiltIn.PumpTandem else if (pump2 is Danfoss.VLT2800.Pump) { mask2 = (pump2 as Danfoss.VLT2800.Pump).Mask; } else if (pump2 is Modbus.PumpFM.DanfossVLT.Pump) { mask2 = (pump2 as Modbus.PumpFM.DanfossVLT.Pump).Mask; } else { mask2 = 0; } - - log.Warn(this.ToString()); - } + } public void TurnOn(double powerArg) diff --git a/TBF/Rig/BuiltIn/Valve/Valve.cs b/TBF/Rig/BuiltIn/Valve/Valve.cs index b4b56bc9b..11a4e619a 100644 --- a/TBF/Rig/BuiltIn/Valve/Valve.cs +++ b/TBF/Rig/BuiltIn/Valve/Valve.cs @@ -33,10 +33,11 @@ namespace TBF.Rig.BuiltIn.Valve public int LagOpening { get { return valveCfg.LagOpening; } } public int LagClosing { get { return valveCfg.LagClosing; } } - public readonly UInt128 Mask; /// derived from bitPosition in the constructor - + public readonly UInt128 Mask; /// derived from bitPosition in the constructor public int BitPosition { get { return valveCfg.BitNr; } } + public bool State { get { return (controlBoard.Route & Mask) != 0; } } + public Valve() { } @@ -48,26 +49,20 @@ namespace TBF.Rig.BuiltIn.Valve controlBoard = TbfComponents.FindComponent(cfg.ParentName, components) as TBF.Rig.ControlBoard.IControlBoard; if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - if (valveCfg.BitNr < 0 || valveCfg.BitNr >= 128) - { - throw new ArgumentOutOfRangeException("position"); - } - this.Mask = (((UInt128)1) << valveCfg.BitNr); + if (valveCfg.CoupledToName != null) + { + coupledTo = (IValve)TbfComponents.FindComponent(valveCfg.CoupledToName, components); + } - if (valveCfg.CoupledToName != null) - { - coupledTo = (IValve)TbfComponents.FindComponent(valveCfg.CoupledToName, components); - } + if (valveCfg.BitNr < 0 || valveCfg.BitNr >= 128) + { + throw new ArgumentOutOfRangeException("position"); + } + Mask = (((UInt128)1) << valveCfg.BitNr); log.Warn(this.ToString()); } - public bool State - { - get { return (controlBoard.Route & Mask) != 0; } - } - - #region Configuration Change Handling public static void OnCfgChange(object sender, CfgChangeArgs args) diff --git a/TBF/Rig/BuiltIn/ValveEx/Valve.cs b/TBF/Rig/BuiltIn/ValveEx/Valve.cs index edd070851..efd121b17 100644 --- a/TBF/Rig/BuiltIn/ValveEx/Valve.cs +++ b/TBF/Rig/BuiltIn/ValveEx/Valve.cs @@ -15,10 +15,8 @@ namespace TBF.Rig.BuiltIn.ValveEx public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } readonly ValveCfg valveCfg; - - public readonly UInt128 Mask; /// derived from bitPosition in the constructor - /// - public readonly IValve[] InputValves; + public readonly IValve[] InputValves; + public readonly UInt128 Mask; /// derived from bitPosition in the constructor public Valve() { } @@ -27,15 +25,6 @@ namespace TBF.Rig.BuiltIn.ValveEx : base(cfg) { valveCfg = cfg as ValveCfg; - - //controlBoard = (ControlBoardDev)TbfComponents.FindComponent(cfg.ParentName, components); - //if (controlBoard == null) throw new Exception("Cannot find " + Name + " parent"); - - if (valveCfg.BitPosition < 0 || valveCfg.BitPosition >= 128) - { - throw new ArgumentOutOfRangeException("position"); - } - this.Mask = (((UInt128)1) << valveCfg.BitPosition); InputValves = new IValve[valveCfg.InputValvesCount]; InputValves[0] = TbfComponents.FindComponent(valveCfg.Input1, components) as IValve; @@ -53,9 +42,12 @@ namespace TBF.Rig.BuiltIn.ValveEx InputValves[4] = TbfComponents.FindComponent(valveCfg.Input5, components) as IValve; } + Mask = (((UInt128)1) << valveCfg.BitPosition); + log.Warn(this.ToString()); } + public void UpdateRoute(ref UInt128 route) { bool output; diff --git a/TBF/Rig/BuiltIn/ValveEx/ValveCfg.cs b/TBF/Rig/BuiltIn/ValveEx/ValveCfg.cs index c8ab312ed..ae6b9a5d7 100644 --- a/TBF/Rig/BuiltIn/ValveEx/ValveCfg.cs +++ b/TBF/Rig/BuiltIn/ValveEx/ValveCfg.cs @@ -17,7 +17,7 @@ namespace TBF.Rig.BuiltIn.ValveEx /// /// Serialized parameters /// - public int BitPosition; /// Bit-position + public int BitPosition; /// Bit-position 0 .. 127 /// public ValveExOperation LogicalOp; /// Logical operation between input valves public bool InvertOutput; /// Invert the output of logical operation diff --git a/TBF/Rig/ControlBoard/Uni/UniCB.cs b/TBF/Rig/ControlBoard/Uni/UniCB.cs index 131e24d37..cb2ffc5db 100644 --- a/TBF/Rig/ControlBoard/Uni/UniCB.cs +++ b/TBF/Rig/ControlBoard/Uni/UniCB.cs @@ -184,7 +184,7 @@ namespace TBF.Rig.ControlBoard.Uni /// /// Initialize control board device hardware /// - public void Initialize() + public override void Initialize() { devices = new OutputPath(string.Empty, 0); actionQueue = new Queue();