tbf/TBF/Rig/BuiltIn/SwitchPoint.cs

57 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using Dirichlet.Numerics;
using TBF.Rig.GenericDevices;
namespace TBF.Rig.BuiltIn
{
public class SwitchPoint
{
public int TimeSec; /// Relative time in [s] from the start of the operation
public IList<IValve> VOpen; /// List of valves to open in this point of time
public IList<IValve> VClose; /// List of valves to close in this point of time
public UInt128 MasksOpen; /// OR-ed bitmasks of valves to open in this point of time
public UInt128 MasksClose; /// OR-ed bitmasks of valves to close in this point of time
public SwitchPoint(int time, IList<IValve> vOpen, IList<IValve> vClose)
{
this.TimeSec = time;
this.VOpen = (vOpen == null) ? new List<IValve>() : vOpen;
this.VClose = (vClose == null) ? new List<IValve>() : vClose;
}
/// <summary>
/// Max. delay of all valves that were opened or closed
/// </summary>
/// <param name="changed">'ulong' with bits of valves that were actually changed set ot '1'</param>
/// <returns>Delay in [s]</returns>
public int MaxDelay(UInt128 changed)
{
int max = 0;
foreach (var vlv in VOpen)
{
/// Skip the delay evaluation and update in case the valve/pump have not changed
if (vlv is Valve.Valve && ((vlv as Valve.Valve).Mask & changed) == 0) continue;
if (vlv is Pump.Pump && ((vlv as Pump.Pump).Mask & changed) == 0) continue;
if (vlv is Danfoss.VLT2800.Pump && ((vlv as Danfoss.VLT2800.Pump).Mask & changed) == 0) continue;
if (vlv is Modbus.PumpFM.DanfossVLT.Pump && ((vlv as Modbus.PumpFM.DanfossVLT.Pump).Mask & changed) == 0) continue;
if (vlv is Modbus.PumpFM.Grundfoss.Pump && ((vlv as Modbus.PumpFM.Grundfoss.Pump).Mask & changed) == 0) continue;
if ((vlv != null) && (vlv.Delay > max)) max = vlv.Delay;
}
foreach (var vlv in VClose)
{
/// Skip the delay evaluation and update in case the valve/pump have not changed
if (vlv is Valve.Valve && ((vlv as Valve.Valve).Mask & changed) == 0) continue;
if (vlv is Pump.Pump && ((vlv as Pump.Pump).Mask & changed) == 0) continue;
if (vlv is Danfoss.VLT2800.Pump && ((vlv as Danfoss.VLT2800.Pump).Mask & changed) == 0) continue;
if (vlv is Modbus.PumpFM.DanfossVLT.Pump && ((vlv as Modbus.PumpFM.DanfossVLT.Pump).Mask & changed) == 0) continue;
if (vlv is Modbus.PumpFM.Grundfoss.Pump && ((vlv as Modbus.PumpFM.Grundfoss.Pump).Mask & changed) == 0) continue;
if ((vlv != null) && (vlv.Delay > max)) max = vlv.Delay;
}
return max;
}
}
}