Task.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Util;
  4. using Aitex.Sorter.RT.EFEMs.Tasks;
  5. namespace Aitex.Sorter.RT.EFEMs.Servers
  6. {
  7. public interface ITaskT
  8. {
  9. bool Execute(out string result, string cmd, params string[] args);
  10. /// <returns>
  11. /// null value, wait,
  12. /// true completed,
  13. /// false error
  14. /// </returns>
  15. bool? Monitor(out string result, params string[] args);
  16. bool HasInfoMessage { get; }
  17. bool IsAcked { get; }
  18. bool IsWaitAck { get; }
  19. bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args);
  20. EfemCommandType CommandType { get; }
  21. EfemCommand CommandName { get; }
  22. string CommandData { get; set; }
  23. }
  24. public interface ITask
  25. {
  26. bool Execute(out string result, params string[] args);
  27. /// <returns>
  28. /// novalue, wait, true completed, false error
  29. /// </returns>
  30. bool? Monitor(out string result, params string[] args);
  31. bool HasInfoMessage { get; set; }
  32. }
  33. public class TaskT<T> : ITaskT, ICloneable
  34. where T : ITask, new()
  35. {
  36. private T _imp = default(T);
  37. private double _deley = 60;
  38. private DeviceTimer _timer = new DeviceTimer();
  39. private string _cmd;
  40. private string[] _args;
  41. public bool HasInfoMessage { get { return _imp.HasInfoMessage; } set { }}
  42. public bool IsAcked { get { return true; } }
  43. public bool IsWaitAck
  44. {
  45. get { return false; }
  46. }
  47. public EfemCommandType CommandType
  48. {
  49. get { return _commandType; }
  50. }
  51. public EfemCommand CommandName
  52. {
  53. get { return _commandName; }
  54. }
  55. public string CommandData
  56. {
  57. get;
  58. set;
  59. }
  60. private EfemCommandType _commandType;
  61. private EfemCommand _commandName;
  62. public TaskT(EfemCommandType type, EfemCommand cmd)
  63. {
  64. _commandType = type;
  65. _commandName = cmd;
  66. _imp = new T();
  67. }
  68. public bool Ack(EfemCommandType type, EfemCommand cmd, params string[] args)
  69. {
  70. return true;
  71. }
  72. public bool Execute(out string result, string cmd, params string[] args)
  73. {
  74. result = string.Empty;
  75. _cmd = cmd.Substring(4);
  76. if (!_imp.Execute(out result, args))
  77. {
  78. result = string.Format("CAN:{0}|{1}", _cmd, result);
  79. return false;
  80. }
  81. _args = new string[args.Length];
  82. args.CopyTo(_args, 0);
  83. _timer.Start(_deley*1000);
  84. result = string.Format("ACK:{0}", _cmd);
  85. return true;
  86. }
  87. public bool? Monitor(out string result, params string[] args)
  88. {
  89. result = string.Empty;
  90. /*
  91. if (_timer.IsTimeout())
  92. {
  93. _timer.Stop();
  94. result = string.Format("INF:{0}", _cmd);
  95. return true;
  96. }
  97. return false;
  98. */
  99. bool? ret = _imp.Monitor(out result, _args);
  100. if (ret.HasValue)
  101. {
  102. _timer.Stop();
  103. if(ret.Value) //completed
  104. {
  105. if(string.IsNullOrEmpty(result))
  106. result = string.Format("INF:{0}", _cmd);
  107. else
  108. result = string.Format("INF:{0}/{1}", _cmd, result);
  109. return true;
  110. }
  111. else
  112. {
  113. result = string.Format("ABS:{0}|ERROR/{1}/{2}", _cmd,result, "FAILED");
  114. return true;
  115. }
  116. }
  117. if(_timer.IsTimeout())
  118. {
  119. _timer.Stop();
  120. result = string.Format("ABS:{0}|ERROR/{1}/{2}", _cmd, "SYSTEM_FF10", "TIMEOUT");
  121. return false;
  122. }
  123. return null;
  124. }
  125. public object Clone()
  126. {
  127. return this.MemberwiseClone();
  128. }
  129. }
  130. public class TaskFactory
  131. {
  132. private Dictionary<string, ITaskT> _tasks = new Dictionary<string, ITaskT>();
  133. private List<string> _hideTasks = new List<string>();
  134. public TaskFactory()
  135. {
  136. _tasks["MOV.INIT"] = new TaskT<InitTask>(EfemCommandType.MOV, EfemCommand.INIT);
  137. _tasks["MOV.ORGSH"] = new TaskT<OrgshTask>(EfemCommandType.MOV, EfemCommand.ORGSH);
  138. _tasks["MOV.HOME"] = new TaskT<HomeTask>(EfemCommandType.MOV, EfemCommand.HOME);
  139. _tasks["MOV.LOCK"] = new TaskT<LockTask>(EfemCommandType.MOV, EfemCommand.LOCK);
  140. _tasks["MOV.UNLOCK"] = new TaskT<UnlockTask>(EfemCommandType.MOV, EfemCommand.UNLOCK);
  141. _tasks["MOV.DOCK"] = new TaskT<DockTask>(EfemCommandType.MOV, EfemCommand.DOCK);
  142. _tasks["MOV.UNDOCK"] = new TaskT<UnDockTask>(EfemCommandType.MOV, EfemCommand.UNDOCK);
  143. //open cassette wafsh = open
  144. _tasks["MOV.OPEN"] = new TaskT<OpenTask>(EfemCommandType.MOV, EfemCommand.OPEN);
  145. _tasks["MOV.CLOSE"] = new TaskT<CloseDoorTask>(EfemCommandType.MOV, EfemCommand.CLOSE);
  146. _tasks["GET.CSTID"] = new TaskT<CstidTask>(EfemCommandType.GET, EfemCommand.CSTID);
  147. _tasks["MOV.WAFSH"] = new TaskT<WafshTask>(EfemCommandType.MOV, EfemCommand.WAFSH);
  148. _tasks["GET.MAPDT"] = new TaskT<MapdtTask>(EfemCommandType.GET, EfemCommand.MAPDT);
  149. _tasks["MOV.ALIGN"] = new TaskT<AlignTask>(EfemCommandType.MOV, EfemCommand.ALIGN);
  150. _tasks["SET.ALIGN"] = new TaskT<SetAlignTask>(EfemCommandType.SET, EfemCommand.ALIGN);
  151. _tasks["MOV.GOTO"] = new TaskT<GotoTask>(EfemCommandType.MOV, EfemCommand.GOTO);
  152. _tasks["MOV.LOAD"] = new TaskT<PickTask>(EfemCommandType.MOV, EfemCommand.LOAD);
  153. _tasks["MOV.UNLOAD"] = new TaskT<PlaceTask>(EfemCommandType.MOV, EfemCommand.UNLOAD);
  154. _tasks["MOV.TRANS"] = new TaskT<TransferTask>(EfemCommandType.MOV, EfemCommand.TRANS);
  155. _tasks["MOV.CHANGE"] = new TaskT<ExchangeTask>(EfemCommandType.MOV, EfemCommand.CHANGE);
  156. _tasks["MOV.EMS"] = new TaskT<EmsTask>(EfemCommandType.MOV, EfemCommand.EMS);
  157. _tasks["MOV.HOLD"] = new TaskT<HoldTask>(EfemCommandType.MOV, EfemCommand.HOLD);
  158. _tasks["MOV.RESTR"] = new TaskT<RestrTask>(EfemCommandType.MOV, EfemCommand.RESTR);
  159. _tasks["MOV.ABORT"] = new TaskT<AbortTask>(EfemCommandType.MOV, EfemCommand.ABORT);
  160. _tasks["SET.ERROR"] = new TaskT<ClearErrorTask>(EfemCommandType.SET, EfemCommand.ERROR);
  161. _tasks["GET.ERROR"] = new TaskT<QueryErrorTask>(EfemCommandType.GET, EfemCommand.ERROR);
  162. _tasks["SET.EVENT"] = new TaskT<SetEventTask>(EfemCommandType.SET, EfemCommand.EVENT);
  163. _tasks["GET.EVENT"] = new TaskT<QueryEventTask>(EfemCommandType.GET, EfemCommand.EVENT);
  164. _tasks["SET.SIGOUT"] = new TaskT<SigoutTask>(EfemCommandType.SET, EfemCommand.SIGOUT);
  165. _tasks["GET.SIGSTAT"] = new TaskT<SigStatTask>(EfemCommandType.GET, EfemCommand.SIGSTAT);
  166. _tasks["SET.CLAMP"] = new TaskT<SetClampTask>(EfemCommandType.SET, EfemCommand.CLAMP);
  167. _tasks["GET.CLAMP"] = new TaskT<GetClampTask>(EfemCommandType.GET, EfemCommand.CLAMP);
  168. _tasks["SET.MODE"] = new TaskT<SetModeTask>(EfemCommandType.SET, EfemCommand.MODE);
  169. _tasks["GET.MODE"] = new TaskT<QueryModeTask>(EfemCommandType.GET, EfemCommand.MODE);
  170. _tasks["MOV.TRANSREQ"] = new TaskT<SetTransferTask>(EfemCommandType.MOV, EfemCommand.TRANSREQ);
  171. _tasks["GET.TRANSREQ"] = new TaskT<QueryTransferTask>(EfemCommandType.GET, EfemCommand.TRANSREQ);
  172. _tasks["GET.STATE"] = new TaskT<QueryStateTask>(EfemCommandType.GET, EfemCommand.STATE);
  173. _tasks["SET.FFU"] = new TaskT<SetFfuTask>(EfemCommandType.SET, EfemCommand.FFU);
  174. _tasks["SET.WTYPE"] = new TaskT<SetWtypeTask>(EfemCommandType.SET, EfemCommand.WTYPE);
  175. _tasks["GET.WTYPE"] = new TaskT<QueryWtypeTask>(EfemCommandType.GET, EfemCommand.WTYPE);
  176. _tasks["SET.PURGE"] = new TaskT<SetPurgeTask>(EfemCommandType.SET, EfemCommand.PURGE);
  177. _tasks["GET.PURGE"] = new TaskT<QueryPurgeTask>(EfemCommandType.GET, EfemCommand.PURGE);
  178. _tasks["MOV.ADPLOCK"] = new TaskT<SetAdplockTask>(EfemCommandType.MOV, EfemCommand.ADPLOCK);
  179. _tasks["SET.ADPUNLOCK"] = new TaskT<SetAdpunlockTask>(EfemCommandType.SET, EfemCommand.ADPUNLOCK);
  180. _tasks["SET.LED"] = new TaskT<SetLedTask>(EfemCommandType.SET, EfemCommand.LED);
  181. _tasks["MOV.WORKCHK"] = new TaskT<SetWorkchkTask>(EfemCommandType.MOV, EfemCommand.WORKCHK);
  182. _tasks["SET.FFUFAN"] = new TaskT<SetFfuFanTask>(EfemCommandType.SET, EfemCommand.FFUFAN);
  183. }
  184. public bool UnSupport(EfemCommandType type, EfemCommand cmd)
  185. {
  186. string key = string.Format("{0}.{1}", type, cmd);
  187. return _hideTasks.Exists(item => item == key) || !_tasks.ContainsKey(key);
  188. }
  189. public ITaskT Create(EfemCommandType type, EfemCommand cmd)
  190. {
  191. if (!UnSupport(type,cmd))
  192. {
  193. string key = string.Format("{0}.{1}", type, cmd);
  194. return (ITaskT)(((ICloneable)_tasks[key]).Clone());
  195. }
  196. return null;
  197. }
  198. }
  199. }