Selaa lähdekoodia

Enhance the EFEMM design for thread safe and throughput issues.

sangwq 11 kuukautta sitten
vanhempi
commit
e806a46292
1 muutettua tiedostoa jossa 36 lisäystä ja 17 poistoa
  1. 36 17
      Venus/Venus_RT/Modules/EFEM/EfemEntity.cs

+ 36 - 17
Venus/Venus_RT/Modules/EFEM/EfemEntity.cs

@@ -158,7 +158,7 @@ namespace Venus_RT.Modules
         private readonly string Name;
         private readonly EfemBase _efem;
         private readonly LoadPortModule[] _lpms = new LoadPortModule[3];
-        private readonly EfemBackroundMsgProcessor _signalTower;
+        private readonly EfemBackroundMsgProcessor _backroundMsgPrococessor;
 
         private readonly EfemType _efemType;
         public EfemBase EfemDevice => _efem;
@@ -194,7 +194,7 @@ namespace Venus_RT.Modules
             _efemType = (EfemType)SC.GetValue<int>($"EFEM.EfemType");
 
             _efem = new JetEfem();
-            _signalTower = new EfemBackroundMsgProcessor(_efem);
+            _backroundMsgPrococessor = new EfemBackroundMsgProcessor(_efem);
 
             Name = ModuleName.EFEM.ToString();
 
@@ -433,7 +433,7 @@ namespace Venus_RT.Modules
             }
 
             _efem.Monitor();
-            _signalTower.Monitor();
+            _backroundMsgPrococessor.Monitor();
             return true;
         }
  
@@ -486,7 +486,7 @@ namespace Venus_RT.Modules
 
         private bool fnBackroundCommand(object[] param)
         {
-            _signalTower.SendBackroundCommand(param);
+            _backroundMsgPrococessor.SendBackroundCommand(param);
             return true;
         }
 
@@ -1018,6 +1018,7 @@ namespace Venus_RT.Modules
     {
         private EfemBase _efem;
         private ConcurrentQueue<object[]> _pendingCmds = new ConcurrentQueue<object[]>();
+        private ConcurrentQueue<object[]> _signalTowerCmds = new ConcurrentQueue<object[]>();
         public EfemBackroundMsgProcessor(EfemBase efem)
         {
             _efem = efem;
@@ -1025,26 +1026,47 @@ namespace Venus_RT.Modules
 
         public void Monitor()
         {
-            if(Singleton<RouteManager>.Instance.EFEM.RobotStatus != RState.Running && _pendingCmds.Count > 0)
+            if(Singleton<RouteManager>.Instance.EFEM.RobotStatus != RState.Running)
             {
-                if(_pendingCmds.TryDequeue(out object[] args))
+                // process backround commmand first
+                if(Singleton<RouteManager>.Instance.EFEM.RobotStatus == RState.End)
                 {
-                    EfemEntity.MSG cmd = (EfemEntity.MSG)args[0];
-                    if ((int)cmd > (int)EfemEntity.MSG.BackroundCmd && (int)cmd < (int)EfemEntity.MSG.MaxMsgValue)
+                    if (_pendingCmds.Count > 0 && _pendingCmds.TryDequeue(out object[] args))
                     {
-                        processBackroundCommand(cmd, args);
-                    }
-                    else
-                    {
-                        LOG.Write(eEvent.ERR_EFEM_ROBOT, ModuleName.EFEM, $"Invalid EFEM backround command {cmd}");
+                        EfemEntity.MSG cmd = (EfemEntity.MSG)args[0];
+                        if ((int)cmd > (int)EfemEntity.MSG.BackroundCmd && (int)cmd < (int)EfemEntity.MSG.MaxMsgValue)
+                        {
+                            processBackroundCommand(cmd, args);
+                            return;
+                        }
+                        else
+                        {
+                            LOG.Write(eEvent.ERR_EFEM_ROBOT, ModuleName.EFEM, $"Invalid EFEM backround command {cmd}");
+                        }
                     }
                 }
+
+
+                // process signal tower command
+                if(_signalTowerCmds.Count > 0 && _signalTowerCmds.TryDequeue(out object[] letCmds))
+                {
+                    _efem.SetLamp((LightType)letCmds[1], (LightStatus)letCmds[2]);
+                    return;
+                }
             }
         }
 
         public void SendBackroundCommand(object[] args)
         {
-            _pendingCmds.Enqueue(args);
+            EfemEntity.MSG cmd = (EfemEntity.MSG)args[0];
+            if(cmd == EfemEntity.MSG.Light)
+            {
+                _signalTowerCmds.Enqueue(args);
+            }
+            else
+            {
+                _pendingCmds.Enqueue(args);
+            }
         }
 
 
@@ -1052,9 +1074,6 @@ namespace Venus_RT.Modules
         {
             switch(cmd)
             {
-                case EfemEntity.MSG.Light:
-                    _efem.SetLamp((LightType)args[1], (LightStatus)args[2]);
-                    break;
                 case EfemEntity.MSG.SetThickness:
                     _efem.SetThickness((ModuleName)args[1], (string)args[2]);
                     break;