/// /// 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()"); } /// /// Set by the constructor /// readonly UniCB uniCB; readonly TBF.Rig.Uni.FlowMeter.FlowMeter flowMeter; readonly TBF.Rig.Uni.Diverter.Diverter diverter; readonly int pulsesCount; /// Number of reference pulses for a complete test readonly bool withDiverter; /// Test with diverter (and scale) /// /// Internal state of this operation /// enum OpState { StartingTest, TestInProgress, TestCompleted, } OpState opState; /// /// 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 /// /// Control board component /// Components used by the test /// Flow lower limit /// Flow upper limit /// Test duration - number of reference flow meter pulses public StandingStartStopTestOp(UniCB cb, OutputPath devices, int pulsesCount, bool withDiverter) { this.uniCB = cb; flowMeter = devices.FlowMeter as TBF.Rig.Uni.FlowMeter.FlowMeter; if (flowMeter == null) throw new ArgumentNullException("Invalid flow meter"); this.pulsesCount = pulsesCount; this.withDiverter = withDiverter; if (withDiverter) { diverter = devices.Diverter as TBF.Rig.Uni.Diverter.Diverter; if (diverter == null) throw new ArgumentNullException("Invalid diverter"); } log.Debug(this.ToString()); } /// /// Start this operation /// public void Start() { log.InfoFormat("Start() Et#={0} pulses={1} withDiverter={2}", flowMeter.Idx1, pulsesCount, withDiverter); /// Start the test (and the flow measurement) uniCB.StartTest(false, flowMeter.Idx1, (withDiverter ? diverter.DiverterNr : 0), 0, false, withDiverter, true, false, pulsesCount); opState = OpState.StartingTest; } /// /// Run this operation /// /// /// 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 /// public Event Run() { log.DebugFormat("Run() opState={0}", opState); switch (opState) { case OpState.StartingTest: opState = OpState.TestInProgress; return Event.TestInProgress; case OpState.TestInProgress: if (uniCB.RefPulses < pulsesCount) { return Event.TestInProgress; /// Test was not completed yet } opState = OpState.TestCompleted; return Event.TestCompleted; case OpState.TestCompleted: default: return Event.TestCompleted; } } /// /// Stop this operation /// public void Stop() { log.Info("Stop()"); uniCB.StopAll(false); } } }