143 lines
5.4 KiB
C#
143 lines
5.4 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using log4net;
|
|
using TBF.Rig.GenericDevices;
|
|
|
|
namespace TBF.Rig.ControlBoard.Uni
|
|
{
|
|
public class StandingStartStopTestOp : IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(StandingStartStopTestOp));
|
|
public override string ToString() { return string.Format("StandingStartStopTestOp()"); }
|
|
|
|
/// 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
|
|
|
|
/// <summary>
|
|
/// Operation for a Standing start-stop test (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
|
|
/// </summary>
|
|
/// <param name="cb">Control board component</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 StandingStartStopTestOp(UniCB cb, OutputPath devices, double qFrom, double qTo, int pulsesCount)
|
|
{
|
|
this.uniCB = cb;
|
|
|
|
flowMeter = devices.FlowMeter as TBF.Rig.Uni.FlowMeter.FlowMeter;
|
|
if (flowMeter == null) throw new ArgumentNullException("Invalid flow meter");
|
|
|
|
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;
|
|
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// Internal states of this operation
|
|
enum OpState
|
|
{
|
|
StartingTest,
|
|
TestInProgress,
|
|
TestCompleted,
|
|
}
|
|
|
|
OpState opState;
|
|
|
|
/// <summary>
|
|
/// Start this operation
|
|
/// </summary>
|
|
public void Start()
|
|
{
|
|
log.InfoFormat("Op.Start() RV#={0} Et#={1} Qfrom={2} Qto={3}", regV.Idx1, flowMeter.Idx1, qFrom, qTo);
|
|
|
|
/// Start the test (and the flow measurement)
|
|
uniCB.StartTest(false, flowMeter.Idx1, 0, 0, false, false, true, false, pulsesCount, 0);
|
|
|
|
opState = OpState.StartingTest;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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>
|
|
public Event Run()
|
|
{
|
|
log.DebugFormat("Op.Run() opState={0}", opState);
|
|
|
|
switch (opState)
|
|
{
|
|
case OpState.StartingTest:
|
|
|
|
if (qFrom < 0 || qFrom >= qTo || qTo > 1.25 * flowMeter.NominalFlow)
|
|
{
|
|
return Event.OpArgumentError; /// Invalid qFrom, qTo
|
|
}
|
|
|
|
if (!flowMeter.MsrmntAvailable || /// Flow measurement not started yet
|
|
(uniCB.State & (ulong)StatusP.TestInProgress) == 0 || /// Test was not started yet
|
|
(flowMeter.ReadFlow()) == 0) /// Measured flow is 0
|
|
{
|
|
return Event.StartingTest; /// Flow regulation cannot be started
|
|
}
|
|
|
|
/// Start flow regulation
|
|
double reqFlowAve = (qFrom + qTo) / 2;
|
|
double reqFlowLo = (0.7 * qFrom) + (0.3 * reqFlowAve); /// Move the lower limit 15% of the range up
|
|
double reqFlowHi = (0.7 * qTo) + (0.3 * reqFlowAve); /// Move the upper limit 15% of the range down
|
|
///
|
|
uniCB.SetFlow(false, regV.Idx1, 2000 * reqFlowLo / flowMeter.NominalFlow,
|
|
2000 * reqFlowHi / flowMeter.NominalFlow);
|
|
|
|
opState = OpState.TestInProgress;
|
|
return Event.TestInProgress;
|
|
|
|
case OpState.TestInProgress:
|
|
|
|
if ((uniCB.State & (ulong)StatusP.TestCompleted) == 0)
|
|
{
|
|
return Event.TestInProgress; /// Test was not completed yet
|
|
}
|
|
opState = OpState.TestCompleted;
|
|
return Event.TestCompleted;
|
|
|
|
case OpState.TestCompleted:
|
|
default:
|
|
return Event.TestCompleted;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stop this operation
|
|
/// </summary>
|
|
public void Stop()
|
|
{
|
|
log.Info("Op.Stop()");
|
|
uniCB.Stop(false);
|
|
}
|
|
}
|
|
}
|