LLEntity.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. using System;
  2. using Aitex.Core.Util;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using MECF.Framework.Common.Equipment;
  6. using Venus_RT.Modules.TM;
  7. using Venus_RT.Devices;
  8. using Venus_Core;
  9. namespace Venus_RT.Modules
  10. {
  11. class LLEntity : Entity, IEntity, IModuleEntity
  12. {
  13. public enum LLStatus
  14. {
  15. Not_Ready,
  16. Ready_For_TM,
  17. Ready_For_EFEM,
  18. }
  19. public enum STATE
  20. {
  21. Unknown,
  22. Init,
  23. Initializing,
  24. Idle,
  25. Error,
  26. Pumping,
  27. Venting,
  28. Purging,
  29. LeakCheck,
  30. Prepare_For_TM,
  31. Prepare_For_EFEM,
  32. Ready_For_TM,
  33. Ready_For_EFEM,
  34. }
  35. public enum MSG
  36. {
  37. Home,
  38. Online,
  39. Offline,
  40. Pump,
  41. Vent,
  42. Purge,
  43. CyclePurge,
  44. LeakCheck,
  45. Prepare_TM,
  46. Prepare_EFEM,
  47. TM_Exchange_Ready,
  48. EFEM_Exchange_Ready,
  49. Error,
  50. Abort,
  51. }
  52. public ModuleName Module { get; private set; }
  53. public LLStatus Status { get; private set; }
  54. public bool Check(int msg, out string reason, params object[] args)
  55. {
  56. throw new NotImplementedException();
  57. }
  58. public bool IsIdle
  59. {
  60. get { return fsm.State == (int)STATE.Idle; }
  61. }
  62. public bool IsError
  63. {
  64. get { return fsm.State == (int)STATE.Error; }
  65. }
  66. public bool IsInit
  67. {
  68. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  69. }
  70. public bool IsBusy
  71. {
  72. get { return !IsInit && !IsError && !IsIdle; }
  73. }
  74. public bool IsOnline { get; internal set; }
  75. private readonly JetTM _JetTM;
  76. private readonly MFPumpRoutine _pumpingRoutine;
  77. private readonly MFVentRoutine _ventingRoutine;
  78. private readonly MFLeakCheckRoutine _leakCheckRoutine;
  79. private readonly MFPurgeRoutine _purgeRoutine;
  80. public LLEntity(ModuleName module)
  81. {
  82. Module = module;
  83. _JetTM = Singleton<JetTM>.Instance;
  84. _pumpingRoutine = new MFPumpRoutine(_JetTM, Module);
  85. _ventingRoutine = new MFVentRoutine(_JetTM, Module);
  86. _leakCheckRoutine = new MFLeakCheckRoutine(_JetTM, Module);
  87. _purgeRoutine = new MFPurgeRoutine(_JetTM, Module);
  88. InitFsmMap();
  89. }
  90. private void InitFsmMap()
  91. {
  92. fsm = new StateMachine<LLEntity>(Module.ToString(), (int)STATE.Init, 50);
  93. fsm.EnableRepeatedMsg(true);
  94. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_TM, fnEnterTMReady, FSM_MSG.NONE, fnExitTMReady);
  95. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_EFEM, fnEnterEFEMReady, FSM_MSG.NONE, fnExitEFEMReady);
  96. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  97. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  98. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  99. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  100. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  101. // Home
  102. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  103. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  104. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  105. //vent sequence
  106. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  107. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  108. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  109. //Pump sequence
  110. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  111. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  112. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  113. // Purge sequence
  114. Transition(STATE.Idle, MSG.CyclePurge, FnStartPurge, STATE.Purging);
  115. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  116. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  117. // Leak check sequence
  118. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.LeakCheck);
  119. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  120. Transition(STATE.LeakCheck, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  121. // Prepare TM Transfer
  122. Transition(STATE.Idle, MSG.Prepare_TM, FnStartPrepareTM, STATE.Prepare_For_TM);
  123. Transition(STATE.Prepare_For_TM, FSM_MSG.TIMER, FnPreparaTMTimeout, STATE.Ready_For_TM);
  124. Transition(STATE.Ready_For_TM, MSG.TM_Exchange_Ready, null, STATE.Idle);
  125. // Prepare EFEM Transfer
  126. Transition(STATE.Idle, MSG.Prepare_EFEM, FnStartPrepareEFEM, STATE.Prepare_For_EFEM);
  127. Transition(STATE.Prepare_For_EFEM, FSM_MSG.TIMER, FnPrepareEFEMTimeout, STATE.Ready_For_EFEM);
  128. Transition(STATE.Ready_For_EFEM, MSG.EFEM_Exchange_Ready, null, STATE.Idle);
  129. Running = true;
  130. }
  131. public int Invoke(string function, params object[] args)
  132. {
  133. switch (function)
  134. {
  135. case "Home":
  136. CheckToPostMessage((int)MSG.Home);
  137. return (int)MSG.Home;
  138. }
  139. return (int)FSM_MSG.NONE;
  140. }
  141. public bool CheckAcked(int msg)
  142. {
  143. return fsm.CheckExecuted(msg);
  144. }
  145. public bool CheckToPostMessage(int msg, params object[] args)
  146. {
  147. if (!fsm.FindTransition(fsm.State, msg))
  148. {
  149. LOG.Write(eEvent.WARN_FSM_WARN, Module, $"{Module} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  150. return false;
  151. }
  152. Running = true;
  153. fsm.PostMsg(msg, args);
  154. return true;
  155. }
  156. private bool fnEnterTMReady(object[] param)
  157. {
  158. Status = LLStatus.Ready_For_TM;
  159. return true;
  160. }
  161. private bool fnExitTMReady(object[] param)
  162. {
  163. Status = LLStatus.Not_Ready;
  164. return true;
  165. }
  166. private bool fnEnterEFEMReady(object[] param)
  167. {
  168. Status = LLStatus.Ready_For_EFEM;
  169. return true;
  170. }
  171. private bool fnExitEFEMReady(object[] param)
  172. {
  173. Status = LLStatus.Not_Ready;
  174. return true;
  175. }
  176. private bool fnMonitor(object[] param)
  177. {
  178. _debugRoutine();
  179. return true;
  180. }
  181. private bool fnError(object[] param)
  182. {
  183. IsOnline = false;
  184. return true;
  185. }
  186. private bool fnOnline(object[] param)
  187. {
  188. IsOnline = true;
  189. return true;
  190. }
  191. private bool fnOffline(object[] param)
  192. {
  193. IsOnline = false;
  194. return true;
  195. }
  196. private bool fnAbort(object[] param)
  197. {
  198. return true;
  199. }
  200. private bool fnHome(object[] param)
  201. {
  202. return true;
  203. }
  204. private bool fnHoming(object[] param)
  205. {
  206. return true;
  207. }
  208. private bool FnStartVent(object[] param)
  209. {
  210. return _ventingRoutine.Start() == RState.Running;
  211. }
  212. private bool FnVentTimeout(object[] param)
  213. {
  214. RState ret = _ventingRoutine.Monitor();
  215. if (ret == RState.Failed || ret == RState.Timeout)
  216. {
  217. PostMsg(MSG.Error);
  218. return false;
  219. }
  220. return ret == RState.End;
  221. }
  222. private bool FnAbortVent(object[] param)
  223. {
  224. _ventingRoutine.Abort();
  225. return true;
  226. }
  227. private bool FnStartPump(object[] param)
  228. {
  229. return _pumpingRoutine.Start() == RState.Running;
  230. }
  231. private bool FnPumpTimeout(object[] param)
  232. {
  233. RState ret = _pumpingRoutine.Monitor();
  234. if (ret == RState.Failed || ret == RState.Timeout)
  235. {
  236. PostMsg(MSG.Error);
  237. return false;
  238. }
  239. return ret == RState.End;
  240. }
  241. private bool FnAbortPump(object[] param)
  242. {
  243. _pumpingRoutine.Abort();
  244. return true;
  245. }
  246. private bool FnStartPurge(object[] param)
  247. {
  248. return _purgeRoutine.Start() == RState.Running;
  249. }
  250. private bool FnPurgeTimeout(object[] param)
  251. {
  252. RState ret = _purgeRoutine.Monitor();
  253. if (ret == RState.Failed || ret == RState.Timeout)
  254. {
  255. PostMsg(MSG.Error);
  256. return false;
  257. }
  258. return ret == RState.End;
  259. }
  260. private bool FnAbortPurge(object[] param)
  261. {
  262. _purgeRoutine.Abort();
  263. return true;
  264. }
  265. private bool FnStartLeakCheck(object[] param)
  266. {
  267. return _leakCheckRoutine.Start() == RState.Running;
  268. }
  269. private bool FnLeakCheckTimeout(object[] param)
  270. {
  271. RState ret = _leakCheckRoutine.Monitor();
  272. if (ret == RState.Failed || ret == RState.Timeout)
  273. {
  274. PostMsg(MSG.Error);
  275. return false;
  276. }
  277. return ret == RState.End;
  278. }
  279. private bool FnAbortLeakCheck(object[] param)
  280. {
  281. _leakCheckRoutine.Abort();
  282. return true;
  283. }
  284. private bool FnStartPrepareTM(object[] param)
  285. {
  286. return _pumpingRoutine.Start() == RState.Running;
  287. }
  288. private bool FnPreparaTMTimeout(object[] param)
  289. {
  290. RState ret = _pumpingRoutine.Monitor();
  291. if (ret == RState.Failed || ret == RState.Timeout)
  292. {
  293. PostMsg(MSG.Error);
  294. return false;
  295. }
  296. return ret == RState.End;
  297. }
  298. private bool FnStartPrepareEFEM(object[] param)
  299. {
  300. return _ventingRoutine.Start() == RState.Running;
  301. }
  302. private bool FnPrepareEFEMTimeout(object[] param)
  303. {
  304. RState ret = _ventingRoutine.Monitor();
  305. if (ret == RState.Failed || ret == RState.Timeout)
  306. {
  307. PostMsg(MSG.Error);
  308. return false;
  309. }
  310. return ret == RState.End;
  311. }
  312. private void _debugRoutine()
  313. {
  314. int flag = 0;
  315. // Test Home routine
  316. if (flag == 1)
  317. {
  318. PostMsg(MSG.Home);
  319. }
  320. else if (flag == 2)
  321. {
  322. PostMsg(MSG.Vent);
  323. }
  324. else if (flag == 3)
  325. {
  326. PostMsg(MSG.Pump);
  327. }
  328. //else if (flag == 4)
  329. //{
  330. // PostMsg(MSG.PumpLoadLock);
  331. //}
  332. //else if (flag == 5)
  333. //{
  334. // PostMsg(MSG.VentLoadLock);
  335. //}
  336. //else if (flag == 6)
  337. //{
  338. // PostMsg(MSG.PurgeLoadLock);
  339. //}
  340. //else if (flag == 7)
  341. //{
  342. // PostMsg(MSG.LaunchPump);
  343. //}
  344. //else if (flag == 8)
  345. //{
  346. // PostMsg(MSG.LaunchTurboPump);
  347. //}
  348. //else if (flag == 9)
  349. //{
  350. // PostMsg(MSG.LoadLockLeakCheck);
  351. //}
  352. else if (flag == 10)
  353. {
  354. PostMsg(MSG.CyclePurge);
  355. }
  356. //else if (flag == 11)
  357. //{
  358. // PostMsg(MSG.GasLinePurge);
  359. //}
  360. //else if (flag == 12)
  361. //{
  362. // PostMsg(MSG.LeakCheck);
  363. //}
  364. //else if (flag == 13)
  365. //{
  366. // PostMsg(MSG.GasLeakCheck);
  367. //}
  368. //else if (flag == 14)
  369. //{
  370. // PostMsg(MSG.LLPlace);
  371. //}
  372. //else if (flag == 15)
  373. //{
  374. // PostMsg(MSG.LLPick);
  375. //}
  376. //else if (flag == 16)
  377. //{
  378. // PostMsg(MSG.RunRecipe, "7777");
  379. //}
  380. //else if (flag == 17)
  381. //{
  382. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  383. //}
  384. }
  385. }
  386. }