123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- using System;
- using Aitex.Core.Util;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.Equipment;
- using Venus_RT.Modules.TM;
- using Venus_RT.Devices;
- using Venus_Core;
- namespace Venus_RT.Modules
- {
- class LLEntity : Entity, IEntity, IModuleEntity
- {
- public enum STATE
- {
- Unknown,
- Init,
- Initializing,
- Idle,
- Error,
- Pumping,
- Venting,
- Purging,
- Leakchecking,
- }
- public enum MSG
- {
- Home,
- Online,
- Offline,
- Pump,
- Vent,
- Purge,
- CyclePurge,
- LeakCheck,
- Error,
- Abort,
- }
- public ModuleName Module { get; private set; }
- public bool Check(int msg, out string reason, params object[] args)
- {
- throw new NotImplementedException();
- }
- public bool IsIdle
- {
- get { return fsm.State == (int)STATE.Idle; }
- }
- public bool IsError
- {
- get { return fsm.State == (int)STATE.Error; }
- }
- public bool IsInit
- {
- get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
- }
- public bool IsBusy
- {
- get { return !IsInit && !IsError && !IsIdle; }
- }
- public bool IsOnline { get; internal set; }
- private readonly JetTM _JetTM;
- private readonly MFPumpRoutine _pumpingRoutine;
- private readonly MFVentRoutine _ventingRoutine;
- private readonly MFLeakCheckRoutine _leakCheckRoutine;
- private readonly MFPurgeRoutine _purgeRoutine;
- public LLEntity(ModuleName module)
- {
- Module = module;
- _JetTM = Singleton<JetTM>.Instance;
- _pumpingRoutine = new MFPumpRoutine(_JetTM, Module);
- _ventingRoutine = new MFVentRoutine(_JetTM, Module);
- _leakCheckRoutine = new MFLeakCheckRoutine(_JetTM, Module);
- _purgeRoutine = new MFPurgeRoutine(_JetTM, Module);
- InitFsmMap();
- }
- private void InitFsmMap()
- {
- fsm = new StateMachine<TMEntity>(Module.ToString(), (int)STATE.Init, 50);
- fsm.EnableRepeatedMsg(true);
- AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
- AnyStateTransition(MSG.Error, fnError, STATE.Error);
- AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
- // Home
- Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
- //vent sequence
- Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
- Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
- Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
- //Pump sequence
- Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
- Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
- Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
- // Purge sequence
- Transition(PMState.Idle, MSG.CyclePurge, FnStartPurge, PMState.Purging);
- Transition(PMState.Purging, FSM_MSG.TIMER, FnPurgeTimeout, PMState.Idle);
- Transition(PMState.Purging, MSG.Abort, FnAbortPurge, PMState.Idle);
- // Leak check sequence
- Transition(PMState.Idle, MSG.LeakCheck, FnStartLeakCheck, PMState.LeakCheck);
- Transition(PMState.LeakCheck, FSM_MSG.TIMER, FnLeakCheckTimeout, PMState.Idle);
- Transition(PMState.LeakCheck, MSG.Abort, FnAbortLeakCheck, PMState.Idle);
- Running = true;
- }
- public int Invoke(string function, params object[] args)
- {
- switch (function)
- {
- case "Home":
- CheckToPostMessage((int)MSG.Home);
- return (int)MSG.Home;
- }
- return (int)FSM_MSG.NONE;
- }
- public bool CheckAcked(int msg)
- {
- return fsm.CheckExecuted(msg);
- }
- public bool CheckToPostMessage(int msg, params object[] args)
- {
- if (!fsm.FindTransition(fsm.State, msg))
- {
- LOG.Write(eEvent.WARN_FSM_WARN, Module, $"{Module} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
- return false;
- }
- Running = true;
- fsm.PostMsg(msg, args);
- return true;
- }
- private bool fnMonitor(object[] param)
- {
- return true;
- }
- private bool fnError(object[] param)
- {
- IsOnline = false;
- return true;
- }
- private bool fnOnline(object[] param)
- {
- return true;
- }
- private bool fnOffline(object[] param)
- {
- IsOnline = false;
- return true;
- }
- private bool fnAbort(object[] param)
- {
- return true;
- }
- private bool fnHome(object[] param)
- {
- return true;
- }
- private bool fnHoming(object[] param)
- {
- return true;
- }
- private bool FnStartVent(object[] param)
- {
- return _ventingRoutine.Start() == RState.Running;
- }
- private bool FnVentTimeout(object[] param)
- {
- RState ret = _ventingRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool FnAbortVent(object[] param)
- {
- _ventingRoutine.Abort();
- return true;
- }
- private bool FnStartPump(object[] param)
- {
- return _pumpingRoutine.Start() == RState.Running;
- }
- private bool FnPumpTimeout(object[] param)
- {
- RState ret = _pumpingRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool FnAbortPump(object[] param)
- {
- _pumpingRoutine.Abort();
- return true;
- }
- private bool FnStartPurge(object[] param)
- {
- return _purgeRoutine.Start() == RState.Running;
- }
- private bool FnPurgeTimeout(object[] param)
- {
- RState ret = _purgeRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool FnAbortPurge(object[] param)
- {
- _purgeRoutine.Abort();
- return true;
- }
- private bool FnStartLeakCheck(object[] param)
- {
- return _leakCheckRoutine.Start() == RState.Running;
- }
- private bool FnLeakCheckTimeout(object[] param)
- {
- RState ret = _leakCheckRoutine.Monitor();
- if (ret == RState.Failed || ret == RState.Timeout)
- {
- PostMsg(MSG.Error);
- return false;
- }
- return ret == RState.End;
- }
- private bool FnAbortLeakCheck(object[] param)
- {
- _leakCheckRoutine.Abort();
- return true;
- }
- }
- }
|