Action.IsFromUI, MeasureFlow works OK, SetFlow in progress, ver. 3.1.1624
This commit is contained in:
@@ -11,11 +11,12 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
public enum ActionID
|
||||
{
|
||||
/// Basic
|
||||
RequestDataOnly = 0,
|
||||
ChangeRoute = 1, /// Change digital outputs (route)
|
||||
MeasureFlow = 2, /// Activate a flow meter to measure the flow
|
||||
SetFlow = 4, /// Set flow
|
||||
StartTest = 8, /// Start a test
|
||||
StopTest = 0x10, /// Stop a test or a flow regulation
|
||||
Stop = 0x10, /// Stop a test or a flow regulation
|
||||
RegVlvIncrMove = 0x20,
|
||||
RegVlvMoveToPos = 0x40,
|
||||
RegVlvStop = 0x80,
|
||||
@@ -33,6 +34,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(Action));
|
||||
|
||||
public ActionID ActionId { get; set; }
|
||||
public bool IsFromUI { get; set; } /// false = action is comming from the state machine, true = action is comming from the UI
|
||||
public ulong Route { get; set; } /// ChangeRoute argument
|
||||
public int FlowMId { get; set; } /// MeasureFlow, SetFlow and StartTest argument
|
||||
public int RegVId { get; set; } /// SetFlow and StartTest argument
|
||||
@@ -40,6 +42,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
public Command StartStop { get; set; } /// MeasureFlow, SetFlow, StartTest, StopTest and SwitchDiverter
|
||||
public bool IsSyncMethod { get; set; } /// StartTest argument
|
||||
public bool IsDivUsed { get; set; } /// StartTest argument
|
||||
public bool IsStartStop { get; set; } /// StartTest argument
|
||||
public bool ToTank { get; set; } /// SwitchDiverter argument
|
||||
public int TotalPulsesCount { get; set; } /// StartTest argument
|
||||
public int MassPulsesCount { get; set; } /// StartTest argument
|
||||
@@ -58,6 +61,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
FlowMId = -1;
|
||||
RegVId = -1;
|
||||
DivId = -1;
|
||||
TotalPulsesCount = -1;
|
||||
StartStop = Command.None;
|
||||
RegVMode = RegValveMode.None;
|
||||
|
||||
@@ -65,7 +69,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
Route = 0;
|
||||
IsSyncMethod = false;
|
||||
IsDivUsed = false;
|
||||
TotalPulsesCount = 0;
|
||||
IsStartStop = false;
|
||||
MassPulsesCount = 0;
|
||||
RVMovePar1 = 0;
|
||||
RVMovePar2 = 0;
|
||||
@@ -83,11 +87,23 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action ChangeRoute(ulong route)
|
||||
public static Action RequestDataOnly()
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RequestDataOnly,
|
||||
IsFromUI = false,
|
||||
};
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action ChangeRoute(bool isFromUI, ulong route)
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.ChangeRoute,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
Route = route,
|
||||
};
|
||||
}
|
||||
@@ -98,55 +114,62 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedChangeRouteArgs(Action newAction)
|
||||
{
|
||||
return Route == newAction.Route;
|
||||
return true;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action MeasureFlow(int flowMeterId)
|
||||
public static Action MeasureFlow(bool isFromUI, int flowMeterId)
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.MeasureFlow,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
FlowMId = flowMeterId,
|
||||
TotalPulsesCount = 0x7FFFFF,
|
||||
MassPulsesCount = 0x7FFFFF,
|
||||
StartStop = Command.Start,
|
||||
};
|
||||
}
|
||||
void SetMeasureFlowArgs(Action action)
|
||||
{
|
||||
FlowMId = action.FlowMId;
|
||||
TotalPulsesCount = action.TotalPulsesCount;
|
||||
MassPulsesCount = action.MassPulsesCount;
|
||||
StartStop = Command.Start;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedMeasureFlowArgs(Action newAction)
|
||||
{
|
||||
return (FlowMId == -1 || FlowMId == newAction.FlowMId) &&
|
||||
(TotalPulsesCount == -1 || TotalPulsesCount == newAction.TotalPulsesCount) &&
|
||||
(StartStop == Command.None || StartStop == Command.Start);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action SetFlow(int flowMeterId, int regValveId, double freqLo, double freqHi,
|
||||
int pid, int tolerRV, int stabTime)
|
||||
public static Action SetFlow(bool isFromUI, int regValveId, double freqLo, double freqHi,
|
||||
int pid, int stabTime_ms)
|
||||
{
|
||||
int rvMovePar1 = Convert.ToInt32(Math.Round(13.1072 * freqLo));
|
||||
int rvMovePar2 = Convert.ToInt32(Math.Round(13.1072 * freqHi));
|
||||
int stabTime = Convert.ToInt32(Math.Round(stabTime_ms / 200.0));
|
||||
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.SetFlow,
|
||||
FlowMId = flowMeterId,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
RegVId = regValveId,
|
||||
RegVMode = RegValveMode.TargetFrequency,
|
||||
RVMovePar1 = rvMovePar1,
|
||||
RVMovePar2 = rvMovePar2,
|
||||
PID = pid,
|
||||
TolerRV = tolerRV,
|
||||
TolerRV = 0,
|
||||
StabTime = stabTime,
|
||||
StartStop = Command.Start,
|
||||
};
|
||||
}
|
||||
void SetSetFlowArgs(Action action)
|
||||
{
|
||||
FlowMId = action.FlowMId;
|
||||
RegVId = action.RegVId;
|
||||
RegVMode = action.RegVMode;
|
||||
RVMovePar1 = action.RVMovePar1;
|
||||
@@ -154,31 +177,29 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
PID = action.PID;
|
||||
TolerRV = action.TolerRV;
|
||||
StabTime = action.StabTime;
|
||||
StartStop = Command.Start;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedSetFlowArgs(Action newAction)
|
||||
{
|
||||
return (FlowMId == -1 || FlowMId == newAction.FlowMId) &&
|
||||
(RegVId == -1 || RegVId == newAction.RegVId) &&
|
||||
(RegVMode == RegValveMode.None || RegVMode == newAction.RegVMode) &&
|
||||
(RVMovePar1 == -1 || RVMovePar1 == newAction.RVMovePar1) &&
|
||||
(RVMovePar2 == -1 || RVMovePar2 == newAction.RVMovePar2) &&
|
||||
(StartStop == Command.None || StartStop == Command.Start);
|
||||
return (RegVId == -1 || RegVId == newAction.RegVId) &&
|
||||
(RegVMode == RegValveMode.None || RegVMode == newAction.RegVMode);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action StartTest(int flowMId, int divId, int divThreshold, bool isSyncMethod,
|
||||
bool isDivUsed, int totalPulsesCount, int massPulsesCount = -1)
|
||||
public static Action StartTest(bool isFromUI, int flowMId, int divId, int divThreshold, bool isSyncMethod,
|
||||
bool isDivUsed, bool isStartStop, int totalPulsesCount, int massPulsesCount = -1)
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.StartTest,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
FlowMId = flowMId,
|
||||
DivId = divId,
|
||||
DivThreshold = divThreshold,
|
||||
IsSyncMethod = isSyncMethod,
|
||||
IsDivUsed = isDivUsed,
|
||||
IsStartStop = isStartStop,
|
||||
TotalPulsesCount = totalPulsesCount,
|
||||
MassPulsesCount = (massPulsesCount == -1) ? totalPulsesCount : massPulsesCount,
|
||||
StartStop = Command.Start,
|
||||
@@ -191,6 +212,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
DivThreshold = action.DivThreshold;
|
||||
IsSyncMethod = action.IsSyncMethod;
|
||||
IsDivUsed = action.IsDivUsed;
|
||||
IsStartStop = action.IsStartStop;
|
||||
TotalPulsesCount = action.TotalPulsesCount;
|
||||
MassPulsesCount = action.MassPulsesCount;
|
||||
StartStop = Command.Start;
|
||||
@@ -200,36 +222,41 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
{
|
||||
return (FlowMId == -1 || FlowMId == newAction.FlowMId) &&
|
||||
(DivId == -1 || DivId == newAction.DivId) &&
|
||||
(TotalPulsesCount == -1 || TotalPulsesCount == newAction.TotalPulsesCount) &&
|
||||
(StartStop == Command.None || StartStop == Command.Start);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action StopTest()
|
||||
public static Action Stop(bool isFromUI)
|
||||
{
|
||||
return new Action()
|
||||
{
|
||||
ActionId = ActionID.StopTest,
|
||||
ActionId = ActionID.Stop,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
StartStop = Command.Stop,
|
||||
};
|
||||
}
|
||||
void SetStopTestArgs(Action action)
|
||||
void SetStopArgs(Action action)
|
||||
{
|
||||
StartStop = Command.Stop;
|
||||
}
|
||||
/// Check whether new action arguments are compatible with alredy collected arguments (true = yes)
|
||||
bool CheckSharedStopTestArgs(Action action)
|
||||
bool CheckSharedStopArgs(Action action)
|
||||
{
|
||||
return (StartStop == Command.None || StartStop == Command.Stop);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action RegVlvIncrMove(int regValveId, double timeSec)
|
||||
public static Action RegVlvIncrMove(bool isFromUI, int regValveId, double timeSec)
|
||||
{
|
||||
int rvMovePar = Math.Abs(Convert.ToInt32(Math.Round(timeSec / 0.050))); /// Step is 50 ms
|
||||
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RegVlvIncrMove,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
RegVId = regValveId,
|
||||
RegVMode = (timeSec >= 0) ? RegValveMode.PulseWidth : (RegValveMode.PulseWidth | RegValveMode.NegPulseWidth),
|
||||
RVMovePar1 = rvMovePar,
|
||||
@@ -251,7 +278,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action RegVlvMoveToPos(int regValveId, double positionLo, double positionHi = -1)
|
||||
public static Action RegVlvMoveToPos(bool isFromUI, int regValveId, double positionLo, double positionHi = -1)
|
||||
{
|
||||
int rvMovePar1, rvMovePar2; /// TODO
|
||||
///
|
||||
@@ -271,6 +298,8 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RegVlvMoveToPos,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
RegVId = regValveId,
|
||||
RegVMode = RegValveMode.TargetPosition,
|
||||
RVMovePar1 = rvMovePar1,
|
||||
@@ -292,11 +321,13 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action RegVlvStop(int regValveId)
|
||||
public static Action RegVlvStop(bool isFromUI, int regValveId)
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.RegVlvStop,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
RegVId = regValveId,
|
||||
RegVMode = RegValveMode.Stop,
|
||||
RVMovePar1 = 0,
|
||||
@@ -318,11 +349,13 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action SwitchDiverter(int divId, bool toTank)
|
||||
public static Action SwitchDiverter(bool isFromUI, int divId, bool toTank)
|
||||
{
|
||||
return new Action
|
||||
{
|
||||
ActionId = ActionID.SwitchDiverter,
|
||||
IsFromUI = isFromUI,
|
||||
///
|
||||
DivId = divId,
|
||||
ToTank = toTank,
|
||||
StartStop = Command.Start,
|
||||
@@ -352,7 +385,7 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
case ActionID.MeasureFlow: SetMeasureFlowArgs(action); return;
|
||||
case ActionID.SetFlow: SetSetFlowArgs(action); return;
|
||||
case ActionID.StartTest: SetStartTestArgs(action); return;
|
||||
case ActionID.StopTest: SetStopTestArgs(action); return;
|
||||
case ActionID.Stop: SetStopArgs(action); return;
|
||||
case ActionID.RegVlvIncrMove: SetRegVlvIncrMoveArgs(action); return;
|
||||
case ActionID.RegVlvMoveToPos: SetRegVlvMoveToPosArgs(action); return;
|
||||
case ActionID.RegVlvStop: SetRegVlvStopArgs(action); return;
|
||||
@@ -370,11 +403,12 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
{
|
||||
switch (action.ActionId)
|
||||
{
|
||||
case ActionID.RequestDataOnly: return true;
|
||||
case ActionID.ChangeRoute: return CheckSharedChangeRouteArgs(action);
|
||||
case ActionID.MeasureFlow: return CheckSharedMeasureFlowArgs(action);
|
||||
case ActionID.SetFlow: return CheckSharedSetFlowArgs(action);
|
||||
case ActionID.StartTest: return CheckSharedStartTestArgs(action);
|
||||
case ActionID.StopTest: return CheckSharedStopTestArgs(action);
|
||||
case ActionID.Stop: return CheckSharedStopArgs(action);
|
||||
case ActionID.RegVlvIncrMove: return CheckSharedRegVlvIncrMoveArgs(action);
|
||||
case ActionID.RegVlvMoveToPos: return CheckSharedRegVlvMoveToPosArgs(action);
|
||||
case ActionID.RegVlvStop: return CheckSharedRegVlvStopArgs(action);
|
||||
@@ -384,22 +418,17 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
public static Action FetchNonConflictingActions(Queue<Action> queue)
|
||||
public static Action FetchNonConflictingActions(Queue<Action> queue, bool blockUI = false)
|
||||
{
|
||||
log.Debug("Fetching non conflicting actions:");
|
||||
|
||||
if (queue == null || queue.Count == 0) return null;
|
||||
|
||||
Action resultA = queue.Dequeue();
|
||||
log.Debug(resultA.ToString());
|
||||
Action combinedAction = Action.RequestDataOnly();
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var peekA = queue.Peek();
|
||||
if ((resultA.ActionId & peekA.ActionId) == 0 && resultA.CheckSharedArgs(peekA) == true)
|
||||
if ((combinedAction.ActionId & peekA.ActionId) == 0 && combinedAction.CheckSharedArgs(peekA) == true)
|
||||
{
|
||||
/// ActionId would not be repeated and arguments are compatible => apply the new action
|
||||
resultA.SetArgs(peekA);
|
||||
combinedAction.SetArgs(peekA);
|
||||
log.Debug(peekA.ToString());
|
||||
queue.Dequeue();
|
||||
}
|
||||
@@ -410,7 +439,28 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
}
|
||||
}
|
||||
|
||||
return resultA;
|
||||
log.InfoFormat("Combined action: {0} Rt={1} Et={2} RV={3} Div#={4} Cmd={5} Sync={6} wDiv={7} S/S={8} ToTank={9} Puls={10} MPls={11} RVMode={12} P1={13} P2={14}",
|
||||
((int)combinedAction.ActionId).ToString("X3"),
|
||||
combinedAction.Route.ToString("X12"),
|
||||
combinedAction.FlowMId,
|
||||
combinedAction.RegVId,
|
||||
combinedAction.DivId,
|
||||
combinedAction.StartStop,
|
||||
combinedAction.IsSyncMethod,
|
||||
combinedAction.IsDivUsed,
|
||||
combinedAction.IsStartStop,
|
||||
combinedAction.ToTank,
|
||||
combinedAction.TotalPulsesCount,
|
||||
combinedAction.MassPulsesCount,
|
||||
combinedAction.RegVMode,
|
||||
combinedAction.RVMovePar1,
|
||||
combinedAction.RVMovePar2,
|
||||
combinedAction.PID,
|
||||
combinedAction.TolerRV,
|
||||
combinedAction.StabTime,
|
||||
combinedAction.DivThreshold);
|
||||
|
||||
return combinedAction;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@@ -419,22 +469,22 @@ namespace TBF.Rig.ControlBoard.Uni
|
||||
switch (ActionId)
|
||||
{
|
||||
case ActionID.ChangeRoute:
|
||||
args = string.Format("Route={0}", Route.ToString("X16"));
|
||||
args = string.Format("Rt={0}", Route.ToString("X12"));
|
||||
break;
|
||||
case ActionID.MeasureFlow:
|
||||
args = string.Format("Etalon={0}", FlowMId);
|
||||
args = string.Format("Et={0}", FlowMId);
|
||||
break;
|
||||
case ActionID.SetFlow:
|
||||
args = string.Format("Etalon={0} RV={1} Par1={2} Par2={3}", FlowMId, RegVId, RVMovePar1, RVMovePar2);
|
||||
args = string.Format("RV={0} P1={1} P2={2}", RegVId, RVMovePar1, RVMovePar2);
|
||||
break;
|
||||
case ActionID.StartTest:
|
||||
args = string.Format("Etalon={0} TotalP={1} MassP={2}", FlowMId, TotalPulsesCount, MassPulsesCount);
|
||||
args = string.Format("Et={0} Puls={1} MPls={2} Sync={3} Div={4} SS={5}", FlowMId, TotalPulsesCount, MassPulsesCount, IsSyncMethod, IsDivUsed, IsStartStop);
|
||||
break;
|
||||
case ActionID.RegVlvIncrMove:
|
||||
args = string.Format("Time={0}ms", (RegVMode & RegValveMode.NegPulseWidth) != 0 ? -50 * RVMovePar1 : 50 * RVMovePar1);
|
||||
args = string.Format("RV={0} Time={1}ms", RegVId, (RegVMode & RegValveMode.NegPulseWidth) != 0 ? -50 * RVMovePar1 : 50 * RVMovePar1);
|
||||
break;
|
||||
case ActionID.RegVlvMoveToPos:
|
||||
args = string.Format("Position={0}%", 0); /// TODO
|
||||
args = string.Format("RV={0} Pos={1}%", RegVId, 0); /// TODO
|
||||
break;
|
||||
default:
|
||||
args = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user