|
|
@ -1,22 +1,38 @@ |
|
|
|
using FSM.Machines; |
|
|
|
using FSM.Machines; |
|
|
|
|
|
|
|
using FSM.Recipes; |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
using System.Timers; |
|
|
|
|
|
|
|
|
|
|
|
namespace FSM.States |
|
|
|
namespace FSM.States |
|
|
|
{ |
|
|
|
{ |
|
|
|
class RunningState : IEquipmentState |
|
|
|
class RunningState : IEquipmentState |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
private Recipe _currentRecipe; |
|
|
|
|
|
|
|
private Timer _timer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RunningState(Recipe recipe) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_currentRecipe = recipe; |
|
|
|
|
|
|
|
_timer = new Timer(3000); |
|
|
|
|
|
|
|
_timer.Elapsed += OnTimedEvent; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Enter() |
|
|
|
public void Enter() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.WriteLine("Entering RunningState"); |
|
|
|
Console.WriteLine(string.Format("Entering RunningState with recipe: {0}", _currentRecipe.Name)); |
|
|
|
|
|
|
|
ExecuteCurrentStep(); |
|
|
|
|
|
|
|
_timer.Start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Exit() |
|
|
|
public void Exit() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.WriteLine("Exiting RunningState"); |
|
|
|
Console.WriteLine("Exiting RunningState"); |
|
|
|
|
|
|
|
_timer.Stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool HandleEvent(EquipmentEvent equipmentEvent, Machines.EquipmentStateMachine machine) |
|
|
|
public bool HandleEvent(EquipmentEvent equipmentEvent, Machines.EquipmentStateMachine machine) |
|
|
@ -24,7 +40,7 @@ namespace FSM.States |
|
|
|
switch (equipmentEvent) |
|
|
|
switch (equipmentEvent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case EquipmentEvent.Pause: |
|
|
|
case EquipmentEvent.Pause: |
|
|
|
machine.SetState(new PausedState()); |
|
|
|
machine.SetState(new PausedState(_currentRecipe)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case EquipmentEvent.Stop: |
|
|
|
case EquipmentEvent.Stop: |
|
|
|
machine.SetState(new IdleState()); |
|
|
|
machine.SetState(new IdleState()); |
|
|
@ -36,5 +52,31 @@ namespace FSM.States |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ExecuteCurrentStep() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var step = _currentRecipe.GetCurrentStep(); |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(step)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Console.WriteLine("Recipe completed"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Console.WriteLine(string.Format("Execute step {0}: {1}", _currentRecipe.CurrentStepIndex + 1, step)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTimedEvent(object sender, ElapsedEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (_currentRecipe.MoveToNextStep()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ExecuteCurrentStep(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Console.WriteLine("Recipe completed"); |
|
|
|
|
|
|
|
_timer.Stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|