This commit is contained in:
@@ -2,8 +2,12 @@ namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public readonly record struct PamhagenState {
|
||||
|
||||
private readonly LegacyPamhagenPlc.SensorStates Sensors;
|
||||
private readonly Func<LegacyPamhagenPlc.ActuatorStates> ActuatorsCb;
|
||||
private LegacyPamhagenPlc.ActuatorStates Actuators { get => ActuatorsCb == null ? default : ActuatorsCb(); }
|
||||
private readonly PamhagenPlc Plc;
|
||||
private LegacyPamhagenPlc.ActuatorStates Actuators => Plc == null ? default : Plc.Actuators;
|
||||
|
||||
public bool ManualControlMode => Plc != null && Plc.ManualControlMode;
|
||||
public bool OverridePathClearances => Plc != null && Plc.OverridePathClearances;
|
||||
public bool OverrideDryRunClearances => Plc != null && Plc.OverrideDryRunClearances;
|
||||
|
||||
public long Valves => Actuators.Valves;
|
||||
public long PressureSensors => Sensors.PressureSensors;
|
||||
@@ -57,20 +61,51 @@ namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public bool Press2_HasClearance => Sensors.ClearancePress2;
|
||||
public bool TroughAuger_HasClearance => Rebler_IsActive && !(MW1_IsSelected && MW1_FillLevel == FillState.Full) && !(MW2_IsSelected && MW2_FillLevel == FillState.Full);
|
||||
|
||||
public readonly bool MP1_HasPathClearance { get; }
|
||||
public readonly bool MP2_HasPathClearance { get; }
|
||||
public readonly bool P12_HasPathClearance { get; }
|
||||
public readonly bool P3_HasPathClearance { get; }
|
||||
public readonly bool P4_HasPathClearance { get; }
|
||||
public readonly bool P5_HasPathClearance { get; }
|
||||
public readonly bool P6_HasPathClearance { get; }
|
||||
public readonly bool MP1_HasDryRunClearance { get; }
|
||||
public readonly bool MP2_HasDryRunClearance { get; }
|
||||
public readonly bool P12_HasDryRunClearance { get; }
|
||||
public readonly bool P3_HasDryRunClearance { get; }
|
||||
public readonly bool P4_HasDryRunClearance { get; }
|
||||
public readonly bool P5_HasDryRunClearance { get; }
|
||||
public readonly bool P6_HasDryRunClearance { get; }
|
||||
private readonly bool MP1_PathClearance;
|
||||
private readonly bool MP2_PathClearance;
|
||||
private readonly bool P12_PathClearance;
|
||||
private readonly bool P3_PathClearance;
|
||||
private readonly bool P4_PathClearance;
|
||||
private readonly bool P5_PathClearance;
|
||||
private readonly bool P6_PathClearance;
|
||||
private readonly bool MP1_DryRunClearance;
|
||||
private readonly bool MP2_DryRunClearance;
|
||||
private readonly bool P12_DryRunClearance;
|
||||
private readonly bool P3_DryRunClearance;
|
||||
private readonly bool P4_DryRunClearance;
|
||||
private readonly bool P5_DryRunClearance;
|
||||
private readonly bool P6_DryRunClearance;
|
||||
|
||||
public readonly bool MP1_WantsPathClearance { get; }
|
||||
public readonly bool MP2_WantsPathClearance { get; }
|
||||
public readonly bool P12_WantsPathClearance { get; }
|
||||
public readonly bool P3_WantsPathClearance { get; }
|
||||
public readonly bool P4_WantsPathClearance { get; }
|
||||
public readonly bool P5_WantsPathClearance { get; }
|
||||
public readonly bool P6_WantsPathClearance { get; }
|
||||
|
||||
public bool MP1_WantActive => Plc.MP1_WantActive;
|
||||
public bool MP2_WantActive => Plc.MP2_WantActive;
|
||||
public bool P12_WantActive => Plc.P12_WantActive;
|
||||
public bool P3_WantActive => Plc.P3_WantActive;
|
||||
public bool P4_WantActive => Plc.P4_WantActive;
|
||||
public bool P5_WantActive => Plc.P5_WantActive;
|
||||
public bool P6_WantActive => Plc.P6_WantActive;
|
||||
|
||||
public bool MP1_HasPathClearance => OverridePathClearances || MP1_PathClearance;
|
||||
public bool MP2_HasPathClearance => OverridePathClearances || MP2_PathClearance;
|
||||
public bool P12_HasPathClearance => OverridePathClearances || P12_PathClearance;
|
||||
public bool P3_HasPathClearance => OverridePathClearances || P3_PathClearance;
|
||||
public bool P4_HasPathClearance => OverridePathClearances || P4_PathClearance;
|
||||
public bool P5_HasPathClearance => OverridePathClearances || P5_PathClearance;
|
||||
public bool P6_HasPathClearance => OverridePathClearances || P6_PathClearance;
|
||||
public bool MP1_HasDryRunClearance => OverrideDryRunClearances || MP1_DryRunClearance;
|
||||
public bool MP2_HasDryRunClearance => OverrideDryRunClearances || MP2_DryRunClearance;
|
||||
public bool P12_HasDryRunClearance => OverrideDryRunClearances || P12_DryRunClearance;
|
||||
public bool P3_HasDryRunClearance => OverrideDryRunClearances || P3_DryRunClearance;
|
||||
public bool P4_HasDryRunClearance => OverrideDryRunClearances || P4_DryRunClearance;
|
||||
public bool P5_HasDryRunClearance => OverrideDryRunClearances || P5_DryRunClearance;
|
||||
public bool P6_HasDryRunClearance => OverrideDryRunClearances || P6_DryRunClearance;
|
||||
public bool MP1_HasClearance => MP1_HasDryRunClearance && MP1_HasPathClearance;
|
||||
public bool MP2_HasClearance => MP2_HasDryRunClearance && MP2_HasPathClearance;
|
||||
public bool P12_HasClearance => P12_HasDryRunClearance && P12_HasPathClearance;
|
||||
@@ -79,25 +114,33 @@ namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
public bool P5_HasClearance => P4_HasDryRunClearance && P5_HasPathClearance;
|
||||
public bool P6_HasClearance => P6_HasDryRunClearance && P6_HasPathClearance;
|
||||
|
||||
public PamhagenState(LegacyPamhagenPlc.SensorStates sensors, Func<LegacyPamhagenPlc.ActuatorStates> actuatorsCb, bool overridePathClearances = false, bool overrideDryRunClearances = false) {
|
||||
public PamhagenState(LegacyPamhagenPlc.SensorStates sensors, PamhagenPlc plc) {
|
||||
Sensors = sensors;
|
||||
ActuatorsCb = actuatorsCb;
|
||||
Plc = plc;
|
||||
|
||||
MP1_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.MP1);
|
||||
MP2_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.MP2);
|
||||
P12_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.P12);
|
||||
P3_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.P3);
|
||||
P4_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.P4);
|
||||
P5_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.P5);
|
||||
P6_HasPathClearance = overridePathClearances || HasPathClearance(this, Paths.P6);
|
||||
MP1_WantsPathClearance = WantsPathClearnace(this, Paths.MP1);
|
||||
MP2_WantsPathClearance = WantsPathClearnace(this, Paths.MP2);
|
||||
P12_WantsPathClearance = WantsPathClearnace(this, Paths.P12);
|
||||
P3_WantsPathClearance = WantsPathClearnace(this, Paths.P3);
|
||||
P4_WantsPathClearance = WantsPathClearnace(this, Paths.P4);
|
||||
P5_WantsPathClearance = WantsPathClearnace(this, Paths.P5);
|
||||
P6_WantsPathClearance = WantsPathClearnace(this, Paths.P6);
|
||||
|
||||
MP1_HasDryRunClearance = overrideDryRunClearances || MW1_FillLevel != FillState.Empty;
|
||||
MP2_HasDryRunClearance = overrideDryRunClearances || MW2_FillLevel != FillState.Empty;
|
||||
P12_HasDryRunClearance = overrideDryRunClearances || T1_FillLevel != FillState.Empty || T2_FillLevel != FillState.Empty;
|
||||
P3_HasDryRunClearance = overrideDryRunClearances || T3_FillLevel != FillState.Empty;
|
||||
P4_HasDryRunClearance = overrideDryRunClearances || T4_FillLevel != FillState.Empty;
|
||||
P5_HasDryRunClearance = overrideDryRunClearances || T5_FillLevel != FillState.Empty;
|
||||
P6_HasDryRunClearance = true;
|
||||
MP1_PathClearance = HasPathClearance(this, Paths.MP1);
|
||||
MP2_PathClearance = HasPathClearance(this, Paths.MP2);
|
||||
P12_PathClearance = HasPathClearance(this, Paths.P12);
|
||||
P3_PathClearance = HasPathClearance(this, Paths.P3);
|
||||
P4_PathClearance = HasPathClearance(this, Paths.P4);
|
||||
P5_PathClearance = HasPathClearance(this, Paths.P5);
|
||||
P6_PathClearance = HasPathClearance(this, Paths.P6);
|
||||
|
||||
MP1_DryRunClearance = MW1_FillLevel != FillState.Empty;
|
||||
MP2_DryRunClearance = MW2_FillLevel != FillState.Empty;
|
||||
P12_DryRunClearance = T1_FillLevel != FillState.Empty || T2_FillLevel != FillState.Empty;
|
||||
P3_DryRunClearance = T3_FillLevel != FillState.Empty;
|
||||
P4_DryRunClearance = T4_FillLevel != FillState.Empty;
|
||||
P5_DryRunClearance = T5_FillLevel != FillState.Empty;
|
||||
P6_DryRunClearance = true;
|
||||
}
|
||||
|
||||
public bool Valve_IsClosed(int n) => Sensors.GetDS(n);
|
||||
@@ -124,10 +167,18 @@ namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
return masks.Any(m => state.Valves == m && ~state.PressureSensors == m);
|
||||
}
|
||||
|
||||
private static bool HasAnyClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
private static bool HasAnyPathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves >= m && ~state.PressureSensors >= m);
|
||||
}
|
||||
|
||||
private static bool WantsSinglePathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves == m);
|
||||
}
|
||||
|
||||
private static bool WantsAnyPathClearance(PamhagenState state, IEnumerable<ValveStateMask> masks) {
|
||||
return masks.Any(m => state.Valves >= m);
|
||||
}
|
||||
|
||||
private static bool HasPathClearance(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) masks) {
|
||||
return
|
||||
(HasSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
@@ -144,6 +195,22 @@ namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
false;
|
||||
}
|
||||
|
||||
private static bool WantsPathClearnace(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) masks) {
|
||||
return
|
||||
(WantsSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
(WantsSinglePathClearance(state, masks.Press2) && state.Press2_HasClearance) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[0]) && state.T1_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[1]) && state.T2_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[2]) && state.T3_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[3]) && state.T4_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[4]) && state.T5_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[5]) && state.T6_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[6]) && state.T7_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[7]) && state.T8_FillLevel != FillState.Full) ||
|
||||
(WantsSinglePathClearance(state, masks.Tanks[8]) && state.T9_FillLevel != FillState.Full) ||
|
||||
false;
|
||||
}
|
||||
|
||||
private static bool HasPathClearance(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2) masks) {
|
||||
return
|
||||
(HasSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
@@ -151,6 +218,13 @@ namespace PamhagenSysCtrl.Helpers.Plc {
|
||||
false;
|
||||
}
|
||||
|
||||
private static bool WantsPathClearnace(PamhagenState state, (ValveStateMask[] Press1, ValveStateMask[] Press2) masks) {
|
||||
return
|
||||
(WantsSinglePathClearance(state, masks.Press1) && state.Press1_HasClearance) ||
|
||||
(WantsSinglePathClearance(state, masks.Press2) && state.Press2_HasClearance) ||
|
||||
false;
|
||||
}
|
||||
|
||||
private static readonly (
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) MP1,
|
||||
(ValveStateMask[] Press1, ValveStateMask[] Press2, ValveStateMask[][] Tanks) MP2,
|
||||
|
||||
Reference in New Issue
Block a user