From 1c4426810c71eead57084be8a18ade8d314dd8c4 Mon Sep 17 00:00:00 2001
From: patrick <patrick.xu@broconcentric.com>
Date: 星期二, 10 十二月 2019 14:24:31 +0800
Subject: [PATCH] 1. 重构项目

---
 src/A032.Process/ProcessControl.cs |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/src/A032.Process/ProcessControl.cs b/src/A032.Process/ProcessControl.cs
index 1c21d00..f823dc3 100644
--- a/src/A032.Process/ProcessControl.cs
+++ b/src/A032.Process/ProcessControl.cs
@@ -3,7 +3,6 @@
 using Bro.Common.Helper;
 using Bro.Common.Interface;
 using Bro.Common.Model;
-using Bro.Common.Model.Interface;
 using Bro.Common.PubSub;
 using Bro.Device.AuboRobot;
 using Bro.Device.OmronFins;
@@ -35,7 +34,7 @@
         {
             #region AutoFac娉ㄥ唽
             builder.RegisterInstance<ProcessConfig>(StationConfig as ProcessConfig);
-            builder.RegisterInstance<List<IDevice>>(GetDeviceList());
+            builder.RegisterInstance<List<IDevice>>(DeviceList);
             builder.RegisterInstance<List<ProcessMethodAttribute>>(CollectProcessMethods());
 
             if (isBuild)
@@ -119,6 +118,8 @@
         Dictionary<string, AuboRobotDriver> RobotDict = new Dictionary<string, AuboRobotDriver>();
         Dictionary<string, SeerAGVDriver> AGVDict = new Dictionary<string, SeerAGVDriver>();
         Dictionary<string, CameraBase> CameraDict = new Dictionary<string, CameraBase>();
+
+        public List<IDevice> DeviceList { get; set; } = new List<IDevice>();
 
         private ProcessConfig Config { get => StationConfig as ProcessConfig; }
 
@@ -296,12 +297,16 @@
             WarningRemains.CollectionChanged -= _warningRemains_CollectionChanged;
             WarningRemains.CollectionChanged += _warningRemains_CollectionChanged;
 
+            #region 璁惧鍒濆鍖�
+            DeviceList = new List<IDevice>();
+
             InitialPLCs();
             InitialAGVs();
             InitialRobots();
             InitialCameras();
             InitialAGVBindUnit();
             //InitialMachineTrayNums();
+            #endregion
 
             AutoFacRegister();
 
@@ -345,6 +350,8 @@
                 CameraBase camera = CameraHelper.GetCameraInstance(c.DriverType);
                 camera.InitialConfig = c;
                 CameraDict[camera.InitialConfig.ID] = camera;
+
+                DeviceList.Add(camera);
             });
         }
 
@@ -361,6 +368,8 @@
 
                 plc.OnMonitorAlarm += OnMonitorAlarm;
                 plc.OnMonitorInvoke += OnMonitorInvoke;
+
+                DeviceList.Add(plc);
             });
         }
 
@@ -381,6 +390,8 @@
 
                 robot.OnMonitorAlarm += OnMonitorAlarm;
                 robot.OnMonitorInvoke += OnMonitorInvoke;
+
+                DeviceList.Add(robot);
             });
         }
 
@@ -395,10 +406,15 @@
                 agv.OnMonitorAlarm -= OnMonitorAlarm;
                 agv.OnMonitorInvoke -= OnMonitorInvoke;
 
+                agv.OnMonitorAlarm += OnMonitorAlarm;
+                agv.OnMonitorInvoke += OnMonitorInvoke;
+
                 agv.OnLog = OnDeviceLog;
                 agv.OnAGVPositoinChanged = OnAGVPositionChanged;
                 agv.OnAGVTaskStatusChanged = OnAGVTaskStatusChanged;
                 agv.OnAGVBatteryLvlChanged = OnAGVBatteryLvlChanged;
+
+                DeviceList.Add(agv);
             });
         }
 
@@ -542,17 +558,17 @@
             });
         }
 
-        public List<IDevice> GetDeviceList()
-        {
-            List<IDevice> list = new List<IDevice>();
+        //public List<IDevice> GetDeviceList()
+        //{
+        //    List<IDevice> list = new List<IDevice>();
 
-            list.AddRange(PLCDict.Values);
-            list.AddRange(RobotDict.Values);
-            list.AddRange(AGVDict.Values);
-            list.AddRange(CameraDict.Values);
+        //    list.AddRange(PLCDict.Values);
+        //    list.AddRange(RobotDict.Values);
+        //    list.AddRange(AGVDict.Values);
+        //    list.AddRange(CameraDict.Values);
 
-            return list;
-        }
+        //    return list;
+        //}
 
         #region IMonitor鐩戝惉
         private void OnMonitorInvoke(DateTime dt, IDevice device, MonitorSet monitorSet)
@@ -631,8 +647,22 @@
             #endregion
         }
 
-        private void OnMonitorAlarm(DateTime dt, IDevice device, WarningSet warning, bool isAlarmRaised)
+        private void OnMonitorAlarm(DateTime dt, IDevice device, WarningSet warning)
         {
+            var bind = Config.AGVBindCollection.FirstOrDefault(u => u.CameraId == device.Id || u.RobotId == device.Id || u.AGVId == device.Id);
+
+            if (bind == null)
+            {
+                throw new ProcessException($"{device.Name}鐨勫紓甯镐俊鎭湭鑳借幏鍙栫浉鍏崇粦瀹氳澶囦俊鎭�");
+            }
+
+            if (warning.CurrentStatus == warning.TriggerValue)
+            {
+                bind.WarningMsg.Add(warning.WarningDescription);
+                bind.UnitState = AGVState.Warning;
+            }
+
+            //鏆傛椂涓嶆墽琛岃嚜鍔ㄥ浣嶏紝闇�瑕佹墜宸ュ浣�
         }
 
         //List<int> _monitorList = new List<int>();

--
Gitblit v1.8.0