///
/// Copyright (c) 2020 Sensus Slovensko a.s.
///
using System;
using log4net;
using TBF.Boxes;
namespace TBF.BenchControl.Elde.Diverter
{
public class ReadDiverterStateOp : IOperation
{
private static readonly ILog log = LogManager.GetLogger(typeof(ReadDiverterStateOp));
public override string ToString() { return string.Format("ReadDiverterStateOp(div={0}, delay={1})", div.Name, delay); }
/// Set by the constructor
readonly GenericDevices.IDiverter div;
readonly int delay;
int startTime;
///
/// Events: FlowInDone, FlowOutDone or Error
///
/// Flow meter reference
/// Reference to the measured flow variable, value is in bar
/// Event to be returned by Run() when completed OK
public ReadDiverterStateOp(GenericDevices.IDiverter div, int delay)
{
this.div = div;
if (div == null) throw new ArgumentNullException();
this.delay = delay;
log.Debug(this.ToString());
}
public ReadDiverterStateOp(GenericDevices.IDiverter div)
: this(div, 0)
{
}
/// Start this operation
public void Start()
{
startTime = StateMachine.Time;
}
/// Run this operation
/// Event.ToTank or Event.ToSink
public Event Run()
{
if (StateMachine.Time - startTime <= delay)
{
return Event.None;
}
return div.State ? Event.ToTank : Event.ToSink;
}
/// Stop this operation
public void Stop() { }
}
}