Uni.FlyingStartStopTestOp merged with Uni.FlyingStartStopTestWithDivOp, IAdvancedControlBoard. ver. 3.1.1601

This commit is contained in:
Milan Hanajik
2021-03-22 09:08:00 +01:00
parent 747195fc10
commit 8f5291332f
14 changed files with 142 additions and 280 deletions
@@ -10,33 +10,54 @@ namespace TBF.Rig.ControlBoard.Uni
public class FlyingStartStopTestOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(FlyingStartStopTestOp));
public override string ToString() { return string.Format("FlyingStartStopTestOp()"); }
public override string ToString() { return string.Format("FlyingStartStopTestWithDivOp()"); }
/// Arguments of the constructor
readonly UniCB uniCB;
readonly TBF.Rig.Uni.RegValve.RegValve regV;
readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter;
readonly double qFrom;
readonly double qTo;
readonly int pulsesCount; /// Number of reference pulses for a complete test
readonly int pulsesCount; /// Number of reference pulses for a complete test
readonly bool withDiverter;
readonly bool isProlonged;
readonly int massPulsesCount; /// Number of reference pulses for mass collection
readonly bool readDivTransition;
readonly TBF.Rig.Uni.RegValve.RegValve regV;
readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter;
readonly int diverterNr;
readonly int divThreshold;
/// <summary>
/// Operation for a Flying start-stop test (constructor)
/// Operation for a Flying start-stop test with a diverter (constructor)
///
/// Events: OpArgumentError .... invalid arguments, test cannot be started
/// StartingTest ....... starting a test
/// TestInProgress ..... test was successfully started, test is running
/// TestCompleted ...... test was successfully completed
/// Error .............. unspecified error while running a test
/// Events: OpArgumentError ...... invalid arguments, test cannot be started
/// StartingTest ......... starting a test
/// TestInProgress ....... test was successfully started, test is running
/// TestPart1InProgress .. test was successfully started, part1 of a prolonged test (collecting water) is running
/// TestPart2InProgress .. first part of a prolonged test was successfully completed, part2 is in progress.
/// Prolonged method only: (massPulsesCount GT 0) and (massPulsesCount LT pulsesCount)
/// TestCompleted ........ test was successfully completed
/// Error ................ unspecified error while running a test
/// </summary>
/// <param name="cb">Control board component</param>
/// <param name="devices">Components used by the test</param>
/// <param name="devices">Components used by the test</param>
/// <param name="qFrom">Flow lower limit</param>
/// <param name="qTo">Flow upper limit</param>
/// <param name="pulsesCount">Test duration - number of reference flow meter pulses</param>
public FlyingStartStopTestOp(UniCB cb, OutputPath devices, double qFrom, double qTo, int pulsesCount)
/// <param name="withDiverter">true = Test with diverter</param>
/// <param name="isProlonged">true = Prolonged test with diverter</param>
/// <param name="massPulsesCount">Test part 1 duration - number of reference flow meter pulses<</param>
/// <param name="readDivTransition">true = Read diverter transition</param>
public FlyingStartStopTestOp(UniCB cb, OutputPath devices, double qFrom, double qTo, int pulsesCount,
bool withDiverter, bool isProlonged, int massPulsesCount, bool readDivTransition)
{
this.uniCB = cb;
this.qFrom = qFrom;
this.qTo = qTo;
this.pulsesCount = pulsesCount;
this.withDiverter = withDiverter;
this.isProlonged = withDiverter && isProlonged;
this.massPulsesCount = massPulsesCount;
this.readDivTransition = withDiverter && readDivTransition;
flowMeter = devices.FlowMeter as TBF.Rig.Uni.FlowMeter.FlowMeter;
if (flowMeter == null) throw new ArgumentNullException("Invalid flow meter");
@@ -44,18 +65,23 @@ namespace TBF.Rig.ControlBoard.Uni
regV = devices.RegValve as TBF.Rig.Uni.RegValve.RegValve;
if (regV == null) throw new ArgumentNullException("Invalid regulation valve");
this.qFrom = qFrom;
this.qTo = qTo;
this.pulsesCount = pulsesCount;
diverterNr = (withDiverter && devices.Diverter is TBF.Rig.Uni.Diverter.Diverter)
? (devices.Diverter as TBF.Rig.Uni.Diverter.Diverter).DiverterNr : 0;
divThreshold = (withDiverter && devices.Diverter is TBF.Rig.Uni.Diverter.Diverter)
? (devices.Diverter as TBF.Rig.Uni.Diverter.Diverter).StartThreshold : 0;
log.Debug(this.ToString());
}
/// Internal state of this operation
/// Internal states of this operation
enum OpState
{
StartingTest,
ReadingDivTransition,
TestInProgress,
TestPart1InProgress, /// prolonged test only
TestPart2InProgress, /// prolonged test only
TestCompleted,
}
@@ -66,10 +92,10 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary>
public void Start()
{
log.InfoFormat("Op.Start() RV#={0} Et#={1} Qfrom={2} Qto={3}", regV.Idx1, flowMeter.Idx1, qFrom, qTo);
log.InfoFormat("Op.Start() RV#={0} Et#={1} Div#={2} Qfrom={3} Qto={4}", regV.Idx1, flowMeter.Idx1, diverterNr, qFrom, qTo);
/// Start the test (and the flow measurement)
uniCB.StartTest(false, flowMeter.Idx1, 0, 0, true, false, false, false, pulsesCount, 0);
uniCB.StartTest(false, flowMeter.Idx1, diverterNr, divThreshold, true, withDiverter, false, isProlonged, pulsesCount, massPulsesCount);
opState = OpState.StartingTest;
}
@@ -78,12 +104,15 @@ namespace TBF.Rig.ControlBoard.Uni
/// Run this operation
/// </summary>
/// <returns>
/// Event.OpArgumentError .... invalid arguments, test cannot be started
/// Event.StartingTest ....... starting a test
/// Event.TestInProgress ..... test was successfully started, test is running
/// Event.TestCompleted ...... test was successfully completed
/// Event.Error .............. unspecified error while running a test
/// </returns>
/// Event.OpArgumentError ...... invalid arguments, test cannot be started
/// Event.StartingTest ......... starting a test
/// Event.TestInProgress ....... test was successfully started, test is running
/// Event.TestPart1InProgress .. test was successfully started, part1 of a prolonged test (collecting water) is running
/// Event.TestPart2InProgress .. first part of a prolonged test was successfully completed, part2 is in progress.
/// Prolonged method only: (massPulsesCount GT 0) and (massPulsesCount LT pulsesCount)
/// Event.TestCompleted ........ test was successfully completed
/// Event.Error ................ unspecified error while running a test
/// </returns>
public Event Run()
{
log.DebugFormat("Op.Run() opState={0}", opState);
@@ -96,12 +125,16 @@ namespace TBF.Rig.ControlBoard.Uni
{
return Event.OpArgumentError; /// Invalid qFrom, qTo
}
if (isProlonged && (massPulsesCount <= 0 || massPulsesCount >= pulsesCount))
{
return Event.OpArgumentError; /// Invalid qFrom, qTo
}
if (!flowMeter.MsrmntAvailable || /// Flow measurement not started yet
(uniCB.State & (ulong)StatusP.ReadingCounters) == 0 || /// Test was not started yet
uniCB.RefFrequency == 0) /// Measured flow is 0
{
return Event.StartingTest; /// Flow regulation cannot be started
return Event.StartingTest; /// Flow regulation cannot be started
}
/// Start flow regulation
@@ -112,8 +145,17 @@ namespace TBF.Rig.ControlBoard.Uni
uniCB.SetFlow(false, regV.Idx1, 2000 * reqFlowLo / flowMeter.NominalFlow,
2000 * reqFlowHi / flowMeter.NominalFlow);
opState = OpState.TestInProgress;
return Event.TestInProgress;
opState = readDivTransition ? OpState.ReadingDivTransition
: (isProlonged ? OpState.TestPart1InProgress : OpState.TestInProgress);
return isProlonged ? Event.TestPart1InProgress : Event.TestInProgress;
case OpState.ReadingDivTransition:
/// Read diverter transition data
uniCB.ReadDiverterTransition(false, diverterNr);
opState = isProlonged ? OpState.TestPart1InProgress : OpState.TestInProgress;
return isProlonged ? Event.TestPart1InProgress : Event.TestInProgress;
case OpState.TestInProgress:
@@ -124,11 +166,30 @@ namespace TBF.Rig.ControlBoard.Uni
opState = OpState.TestCompleted;
return Event.TestCompleted;
case OpState.TestPart1InProgress:
if ((uniCB.State & (ulong)StatusP.DirectionOfDiverter) != 0)
{
return Event.TestPart1InProgress; /// Test was not completed yet
}
opState = OpState.TestPart2InProgress;
return Event.TestPart2InProgress;
case OpState.TestPart2InProgress:
if ((uniCB.State & (ulong)StatusP.TestCompleted) == 0)
{
/// Test was not completed yet
return Event.TestPart2InProgress;
}
opState = OpState.TestCompleted;
return Event.TestCompleted;
case OpState.TestCompleted:
default:
return Event.TestCompleted;
}
}
}
/// <summary>
/// Stop this operation