77 lines
1.8 KiB
C#
77 lines
1.8 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Slovensko a.s.
|
|
///
|
|
namespace TBF.Rig.Modbus.TankSelector
|
|
{
|
|
public class UnselectTankOp : IOperation
|
|
{
|
|
TankSelector tankSelector;
|
|
TankId tankId;
|
|
ushort unselectBitMask;
|
|
bool doUnselect;
|
|
bool unselectedWaitLevel;
|
|
|
|
public UnselectTankOp(TankSelector tankSelector)
|
|
{
|
|
this.tankSelector = tankSelector;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
if (tankSelector.CurrentActivity == Activity.Selected ||
|
|
tankSelector.CurrentActivity == Activity.Selected_Waiting1min)
|
|
{
|
|
tankId = tankSelector.CurrentTank;
|
|
unselectBitMask = (ushort)((tankId == TankId.Cold) ? QuidoOutputs.PumpToColdTank
|
|
: (tankId == TankId.Warm) ? QuidoOutputs.PumpToWarmTank
|
|
: QuidoOutputs.PumpToHotTank);
|
|
doUnselect = true;
|
|
unselectedWaitLevel = false;
|
|
|
|
tankSelector.SetBit(unselectBitMask);
|
|
}
|
|
else if (tankSelector.CurrentActivity == Activity.Unselected_WaitingLevel)
|
|
{
|
|
tankId = tankSelector.CurrentTank;
|
|
|
|
doUnselect = false;
|
|
unselectedWaitLevel = true;
|
|
}
|
|
else /// tankSelector.CurrentActivity == Activity.Idle or Activity.Uknown
|
|
{
|
|
doUnselect = false;
|
|
unselectedWaitLevel = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
public Event Run()
|
|
{
|
|
if (doUnselect)
|
|
{
|
|
tankSelector.ResetBit(unselectBitMask);
|
|
doUnselect = false;
|
|
unselectedWaitLevel = true;
|
|
return Event.ConditionNotMet;
|
|
}
|
|
else if (unselectedWaitLevel)
|
|
{
|
|
if (tankSelector.CurrentActivity == Activity.Idle)
|
|
{
|
|
unselectedWaitLevel = false;
|
|
return Event.ConditionMet;
|
|
}
|
|
return Event.ConditionNotMet;
|
|
}
|
|
else
|
|
{
|
|
return Event.ConditionMet;
|
|
}
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop() { }
|
|
}
|
|
}
|