123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823 |
- using System;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.Utilities;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Schedulers;
- using Virgo_DCommon;
- using Virgo_DRT.Device;
- using Virgo_DRT.Device.YASKAWA;
- namespace Virgo_DRT.Modules
- {
- class EfemEntity : Entity, IEntity, IModuleEntity
- {
- public enum STATE
- {
- Unknown, // 0
- Initializing, // 1
- Idle, // 2
- Error, // 3
- Picking, // 4
- Placing, // 5
- Aligning, // 6
- Mapping, // 7
- Init, // 8
- Orgshing, // 9
- Lifting, // 10
- InitingAL, // 11
- InitingRB, // 12
- Extending, // 13
- Retracting, // 14
- SettingLamp //15
-
- }
- public enum MSG
- {
- HomeAll, // 0
- Pick, // 1
- Place, // 2
- Align, // 3
- ActionDone, // 4
- RecHwMsg, // 5
- MoveCmd, // 6
- LED, // 7
- Recover, // 8
- Goto, // 9
- Error, // 10
- Online, // 11
- CommReady, // 12
- Lift, // 13
- HomeAL, // 14
- HomeRB, // 15
- Extend, // 16
- Retract, // 17
- PMLiftPinUp, // 18
- PMLiftPinDown, // 19
- AllLightsOFF,
- Abort,
- Map,
- }
- public bool Check(int msg, out string reason, params object[] args)
- {
- throw new NotImplementedException();
- }
- // Fields
- //
- private readonly string Name;
- private readonly Efem _efem;
- private readonly LoadportEntity[] _lpms = new LoadportEntity[2];
- // Constructor
- //
- public EfemEntity()
- {
- _efem = new Efem();
- _lpms[0] = new LoadportEntity(ModuleName.LP1, _efem);
- _lpms[1] = new LoadportEntity(ModuleName.LP2, _efem);
- Name = ModuleName.EFEM.ToString();
- InitFsmMap();
- _lpms[0].Initialize();
- _lpms[1].Initialize();
- }
- public void NotifyLP(ModuleName mod, LoadportEntity.MSG msg)
- {
- _lpms[mod - ModuleName.LP1].PostMsg(msg);
- }
- protected override bool Init()
- {
- OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAll); return true; });
- OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.ClearError}", (cmd, args) => { PostMsg(MSG.Recover); return true; });
- OP.Subscribe($"{ModuleName.EFEM}.{EfemOperation.TurnOffAllLights}", (cmd, args) => { PostMsg(MSG.AllLightsOFF); return true; });
- OP.Subscribe($"{ModuleName.EFEM}.Online", (cmd, args) => { PostMsg(MSG.Online); return true; });
- OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Pick}", (cmd, args) => { PostMsg(MSG.Pick, args[0], args[1], Hand.Blade1, args[2]); return true; });
- OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Place}", (cmd, args) => { PostMsg(MSG.Place, args[0], args[1], Hand.Blade1, args[2]); return true; });
- OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Extend}", (cmd, args) => { PostMsg(MSG.Extend, args[0], args[1]); return true; });
- OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Retract}", (cmd, args) => { PostMsg(MSG.Retract, args[0], args[1]); return true; });
- OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Abort}", (cmd, args) => { PostMsg(MSG.Abort); return true; });
- OP.Subscribe($"{ModuleName.EfemRobot}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeRB); return true; });
- OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner1); return true; });
- OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Home}", (cmd, args) => { PostMsg(MSG.HomeAL, ModuleName.Aligner2); return true; });
- OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Aligner1, args[0]); return true; });
- OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Align}", (cmd, args) => { PostMsg(MSG.Align, ModuleName.Aligner2, args[0]); return true; });
- OP.Subscribe($"{ModuleName.Aligner1}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Aligner1); return true; });
- OP.Subscribe($"{ModuleName.Aligner2}.{EfemOperation.Lift}", (cmd, args) => { PostMsg(MSG.Lift, ModuleName.Aligner2); return true; });
- DATA.Subscribe($"{Name}.FsmState", () => ((STATE)fsm.State).ToString());
- DATA.Subscribe($"{Name}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString());
- DATA.Subscribe($"{Name}.FsmLastMessage", GetFsmLastMessage);
- return true;
- }
- private void InitFsmMap()
- {
- fsm = new StateMachine<EfemEntity>("EFEM", (int)STATE.Unknown, 50);
- AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
- AnyStateTransition(MSG.RecHwMsg, fnRecMsg, FSM_STATE.SAME);
- AnyStateTransition(MSG.LED, fnSetLED, STATE.SettingLamp);
- AnyStateTransition(MSG.AllLightsOFF, fnTurnOffLED, STATE.SettingLamp);
- AnyStateTransition(MSG.Recover, fnRecover, STATE.Idle);
- AnyStateTransition(MSG.Error, fnError, STATE.Error);
- AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Abort, fnAbortRobot, FSM_STATE.SAME);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Initializing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- EnterExitTransition<STATE, FSM_MSG>(STATE.InitingRB, fnEnterExecute, FSM_MSG.NONE, null);
- EnterExitTransition<STATE, FSM_MSG>(STATE.InitingAL, fnEnterExecute, FSM_MSG.NONE, null);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Picking, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Placing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Extending, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Retracting, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Lifting, fnEnterExecute, FSM_MSG.NONE, null);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Aligning, fnEnterExecute, FSM_MSG.NONE, null);
- EnterExitTransition<STATE, FSM_MSG>(STATE.SettingLamp, fnEnterExecute, FSM_MSG.NONE, null);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Mapping, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- Transition(STATE.Unknown, MSG.CommReady, null, STATE.Init);
- // Home
- Transition(STATE.Init, MSG.HomeAll, fnHomeAll, STATE.Initializing);
- Transition(STATE.Idle, MSG.HomeAll, fnHomeAll, STATE.Initializing); // 暂时加,出错的时候做 HOME
- Transition(STATE.Initializing, MSG.ActionDone, null, STATE.Orgshing);
- Transition(STATE.Orgshing, MSG.ActionDone, fnActionDone, STATE.Idle);
- Transition(STATE.Idle, MSG.HomeRB, fnHomeRobot, STATE.InitingRB);
- Transition(STATE.InitingRB, MSG.ActionDone, null, STATE.Idle);
- Transition(STATE.SettingLamp, MSG.ActionDone, fnSetLampDone, STATE.Idle);
- // Pick
- Transition(STATE.Idle, MSG.Pick, fnPick, STATE.Picking);
- Transition(STATE.Picking, MSG.ActionDone, fnActionDone, STATE.Idle);
- Transition(STATE.Picking, MSG.PMLiftPinUp, fnPmPinUp, STATE.Idle);
- Transition(STATE.Picking, MSG.PMLiftPinDown, fnPmPinDown, STATE.Idle);
-
- // Place
- Transition(STATE.Idle, MSG.Place, fnPlace, STATE.Placing);
- Transition(STATE.Placing, MSG.ActionDone, fnActionDone, STATE.Idle);
- Transition(STATE.Placing, MSG.PMLiftPinUp, fnPmPinUp, STATE.Idle);
- Transition(STATE.Placing, MSG.PMLiftPinDown, fnPmPinDown, STATE.Idle);
- // Extend
- Transition(STATE.Idle, MSG.Extend, fnExtend, STATE.Extending);
- Transition(STATE.Extending, MSG.ActionDone, fnActionDone, STATE.Idle);
- // Retract
- Transition(STATE.Idle, MSG.Retract, fnRetract, STATE.Retracting);
- Transition(STATE.Retracting, MSG.ActionDone, fnActionDone, STATE.Idle);
- // Map
- Transition(STATE.Idle, MSG.Map, fnMap, STATE.Mapping);
- Transition(STATE.Mapping, MSG.ActionDone, fnActionDone, STATE.Idle);
- // Aligner
- Transition(STATE.Idle, MSG.HomeAL, fnHomeAligner, STATE.InitingAL);
- Transition(STATE.InitingAL, MSG.ActionDone, fnActionDone, STATE.Idle);
- Transition(STATE.Idle, MSG.Lift, fnLift, STATE.Lifting);
- Transition(STATE.Lifting, MSG.ActionDone, fnActionDone, STATE.Idle);
- Transition(STATE.Idle, MSG.Align, fnAlign, STATE.Aligning);
- Transition(STATE.Aligning, MSG.ActionDone, fnActionDone, STATE.Idle);
- EnumLoop<STATE>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
- EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
- }
- private bool fnHomeAll(object[] param)
- {
- _efem.ClearActions();
- _efem.HomeAll();
- return true;
- }
- private bool fnHomeRobot(object[] param)
- {
- _efem.Home(ModuleName.EfemRobot);
- return true;
- }
- private bool fnHomeAligner(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- _efem.Home(unit);
- return true;
- }
- private bool fnEnterExecute(object[] param)
- {
- _efem.ExecuteAction();
- return false;
- }
- private bool fnExitExecute(object[] param)
- {
- _efem.ExecuteAction();
- return false;
- }
- private bool fnActionDone(object[] param)
- {
- try
- {
- EfemOperation actionType = (EfemOperation)param[0];
- if (actionType == EfemOperation.Extend)
- {
- if (fsm.State == (int)STATE.Placing)
- {
- _efem.ExecuteAction();
- return false;
- }
- else if (fsm.State == (int)STATE.Picking)
- {
- if (_efem.HasActions)
- {
- _efem.ExecuteAction();
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- return true;
- }
- catch (Exception ex)
- {
- EV.PostAlarmLog(ModuleName.EFEM.ToString(), ex.Message);
- return true;
- }
- }
- public bool CheckToPostMessage(int msg, params object[] args)
- {
- if (!fsm.FindTransition(fsm.State, msg))
- {
- EV.PostWarningLog(Name, $"{Name} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
- return false;
- }
- Running = true;
- fsm.PostMsg(msg, args);
- return true;
- }
- private bool fnRecMsg(object[] param)
- {
- if (param == null) return false;
- string strHwMsg = param[0] as string;
- if (_efem is EfemBase device)
- {
- device.ReceiveMessage(strHwMsg);
- return true;
- }
- return false;
- }
- private bool fnMonitor(object[] param)
- {
- STATE curSt = (STATE)fsm.State;
- if (curSt == STATE.Initializing || curSt == STATE.Mapping)
- {
- if (fsm.ElapsedTime > 60 * 1000)
- {
- PostMsg(MSG.Recover);
- }
- }
- if (curSt == STATE.Aligning)
- {
- if (fsm.ElapsedTime > 10 * 1000)
- {
- EV.PostAlarmLog(ModuleName.Aligner.ToString(), "Align timeout");
- PostMsg(MSG.ActionDone, "alignment timeout");
- }
- }
- return true;
- }
-
- private bool fnOnline(object[] param)
- {
- bool bOnlineFlag = (bool)param[0];
- if (_efem is EfemBase efem)
- {
- efem.SetOnline(bOnlineFlag);
- }
- return true;
- }
- private string GetFsmLastMessage()
- {
- int msg = fsm.LastMsg;
- if (msg >= (int)MSG.HomeAll && msg <= (int)MSG.Error)
- return ((MSG)msg).ToString();
- if (msg == (int)FSM_MSG.TIMER)
- return "Timer";
- return msg.ToString();
- }
- private bool fnError(object[] param)
- {
- return true;
- }
- private bool fnRecover(object[] param)
- {
- _efem.ClearActions();
- _efem.ClearError();
- _efem.ExecuteAction();
- return true;
- }
- private bool fnAbortRobot(object[] param)
- {
- _efem.AbortRobot();
- _efem.ExecuteAction();
- return true;
- }
- private bool fnSetLED(object[] param)
- {
- LightType light = (LightType)param[0];
- LightStatus st = (LightStatus)param[1];
- _efem.SetLamp(light, st);
- return true;
- }
- private bool fnTurnOffLED(object[] param)
- {
- _efem.TurnOffAllLamps();
- return true;
- }
- private bool fnSetLampDone(object[] param)
- {
- if (_efem.HasActions)
- {
- _efem.ExecuteAction();
- return false;
- }
- else
- {
- return true;
- }
- }
- private bool fnPick(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- // slot
- byte slot = (byte)(int)param[1];
- // hand
- Hand arm = (Hand)param[2];
- // wafer size
- WaferSize ws1 = WaferSize.WS0;
- if (param[3] is string s2)
- {
- if (Enum.TryParse(s2, out WaferSize p5))
- ws1 = p5;
- }
- else if (param[3] is WaferSize p6)
- {
- ws1 = p6;
- }
- MoveParam mp = new MoveParam(unit, slot, ModuleName.EfemRobot, (byte)arm, arm, ws1);
- _efem.Pick(mp);
- return true;
- }
- private bool fnPlace(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- // slot
- byte slot = (byte)(int)param[1];
- // hand
- Hand arm = (Hand)param[2];
- // wafer size
- WaferSize ws1 = WaferSize.WS0;
- if (param[3] is string s2)
- {
- if (Enum.TryParse(s2, out WaferSize p5))
- ws1 = p5;
- }
- else if (param[3] is WaferSize p6)
- {
- ws1 = p6;
- }
- MoveParam mp = new MoveParam(ModuleName.EfemRobot, (byte)arm, unit, slot, arm, ws1);
- _efem.Place(mp);
- return true;
- }
- private bool fnExtend(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- ExtendParam mp = new ExtendParam
- {
- Module = unit,
- Pos = (ExtendPos)Enum.Parse(typeof(ExtendPos), param[1] as string)
- };
- _efem.Extend(mp);
- return true;
- }
- private bool fnRetract(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- ExtendParam mp = new ExtendParam
- {
- Module = unit,
- Pos = (ExtendPos)Enum.Parse(typeof(ExtendPos), param[1] as string)
- };
- _efem.Retract(mp);
- return true;
- }
- private bool fnPmPinUp(object[] param)
- {
- _efem.UpdateStatus((ushort)param[0], ActionStatus.Completed);
- if (_efem.HasActions)
- {
- _efem.ExecuteAction();
- return false;
- }
- else
- {
- return true;
- }
- }
- private bool fnPmPinDown(object[] param)
- {
- _efem.UpdateStatus((ushort)param[0], ActionStatus.Completed);
- if (_efem.HasActions)
- {
- _efem.ExecuteAction();
- return false;
- }
- else
- {
- return true;
- }
- }
- private bool fnLift(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- _efem.SetPinUp(unit);
- return true;
- }
- private bool fnAlign(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- // wafer size
- WaferSize ws1 = WaferSize.WS0;
- if (param[1] is string s2)
- {
- if (Enum.TryParse(s2, out WaferSize p5))
- ws1 = p5;
- }
- else if (param[1] is WaferSize p6)
- {
- ws1 = p6;
- }
- _efem.Align(unit, 1000, ws1);
- return true;
- }
- private bool fnMap(object[] param)
- {
- // module
- ModuleName unit = ModuleName.EFEM;
- if (param[0] is string s1)
- unit = ModuleNameString.ToEnum(s1);
- else if (param[0] is ModuleName mod)
- unit = mod;
- else
- throw new ArgumentException("Argument error");
- _efem.Map(unit);
- return true;
- }
- 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; }
- public int Invoke(string function, params object[] args)
- {
- switch (function)
- {
- case "Home":
- CheckToPostMessage((int)MSG.HomeAll);
- return (int)MSG.HomeAll;
- }
- return (int)FSM_MSG.NONE;
- }
- public bool CheckAcked(int msg)
- {
- return fsm.CheckExecuted(msg);
- }
- internal void InvokeReset()
- {
- PostMsg((int)MSG.Recover);
- }
- public int InvokeAlign(string module, float time)
- {
- if (CheckToPostMessage((int)MSG.Align, module, time))
- return (int)MSG.Align;
- return (int)FSM_MSG.NONE;
- }
- public int InvokePick(ModuleName source, int slot, Hand hand, WaferSize size)
- {
- if (CheckToPostMessage((int)MSG.Pick, source, slot, hand, size))
- return (int)MSG.Pick;
- return (int)FSM_MSG.NONE;
- }
- public int InvokePlace(ModuleName target, int slot, Hand hand, WaferSize size)
- {
- if (CheckToPostMessage((int)MSG.Place, target, slot, hand, size))
- return (int)MSG.Place;
- return (int)FSM_MSG.NONE;
- }
- public int InvokeMap(string target )
- {
- if (CheckToPostMessage((int)MSG.Map, target ))
- return (int)MSG.Map;
- return (int)FSM_MSG.NONE;
- }
- public bool IsPrepareTransferReady(ModuleName module, EnumTransferType type, int slot)
- {
- if (type == EnumTransferType.Pick)
- {
- //需要补充:判断LP 放好了,而且已经map过。
- return _efem[module].HasCassette && _efem[module].IsMapped;
- }
- else if (type == EnumTransferType.Place)
- {
- //需要补充:判断LP 放好了,而且已经map过。
- return _efem[module].HasCassette && _efem[module].IsMapped;
- }
- return false;
- }
- internal bool CheckReadyRunNewJob(ModuleName module)
- {
- //???
- return true;
- }
- internal bool CheckReadyTransfer(ModuleName module)
- {
- return _efem[module].HasCassette && _efem[module].IsMapped;
- }
- }
- /// <summary>
- /// LP entity
- /// </summary>
- class LoadportEntity : Entity, IEntity
- {
- private enum STATE
- {
- Unknown,
- Idle, // 1
- Initializing, // 2
- Initialized, // 3
- Mapping, // 4
- Mapped, // 5
- }
- public enum MSG
- {
- Home, // 0
- Map, // 1
- ActionDone, // 2
- RecHwMsg, // 3
- Recover, // 4
- Abort, // 5
- Online, // 6
- Error // 7
- }
- private readonly Efem _efem;
- private ModuleName Module { get; }
- public LoadportEntity(ModuleName mod, Efem efem)
- {
- this.Module = mod;
- _efem = efem;
- InitFsmMap();
- OP.Subscribe($"{Module}.Home", (cmd, args) => { PostMsg(MSG.Home); return true; });
- OP.Subscribe($"{Module}.Abort", (cmd, args) => { PostMsg(MSG.Abort); return true; });
- //OP.Subscribe($"{Module}.Map", (cmd, args) => { PostMsg(MSG.Map); return true; });
- OP.Subscribe($"{Module}.Online", (cmd, args) => { PostMsg(MSG.Online); return true; });
- DATA.Subscribe($"{Module}.Status", () => ((STATE)fsm.State).ToString());
- DATA.Subscribe($"{Module}.FsmState", () => ((STATE)fsm.State).ToString());
- DATA.Subscribe($"{Module}.FsmPrevState", () => ((STATE)fsm.PrevState).ToString());
- DATA.Subscribe($"{Module}.FsmLastMessage", GetFsmLastMessage);
- }
- private string GetFsmLastMessage()
- {
- int msg = fsm.LastMsg;
- if (msg >= (int)MSG.Home && msg <= (int)MSG.Error)
- return ((MSG)msg).ToString();
- if (msg == (int)FSM_MSG.TIMER)
- return "Timer";
- return msg.ToString();
- }
- private void InitFsmMap()
- {
- fsm = new StateMachine<LoadportEntity>($"LPM_{Module}", (int)STATE.Idle, 500);
- AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
- //AnyStateTransition(MSG.RecHwMsg, fnRecMsg, FSM_STATE.SAME);
- AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Recover, fnRecover, STATE.Idle);
- AnyStateTransition(MSG.Abort, fnRecover, STATE.Idle);
- EnterExitTransition<STATE, FSM_MSG>(STATE.Initializing, fnEnterExecute, FSM_MSG.NONE, fnExitExecute);
- // Home
- AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
- Transition(STATE.Initializing, MSG.ActionDone, fnActionDone, STATE.Idle);
- }
- private bool fnOnline(object[] param)
- {
- bool online = (bool)param[0];
- _efem.SetOnline(Module, online);
- return true;
- }
- private bool fnRecover(object[] param)
- {
- return true;
- }
- private bool fnMonitor(object[] param)
- {
- STATE curSt = (STATE)fsm.State;
- if (curSt == STATE.Initializing || curSt == STATE.Mapping)
- {
- if (fsm.ElapsedTime > 20 * 1000)
- {
- PostMsg(MSG.Recover);
- }
- }
- return true;
- }
- private bool fnEnterExecute(object[] param)
- {
- _efem.ExecuteAction();
- return true;
- }
- private bool fnExitExecute(object[] param)
- {
- return true;
- }
- private bool fnActionDone(object[] param)
- {
- return true;
- }
- private bool fnHome(object[] param)
- {
- _efem.Home(Module);
- return true;
- }
- public bool Check(int msg, out string reason, params object[] args)
- {
- throw new NotImplementedException();
- }
- }
- }
|