فهرست منبع

AutoManager 추가

SK.Kang 6 سال پیش
والد
کامیت
b5a62e9210

+ 17 - 0
Dev/OHV/OHV.Common/Shareds/SharedEnumType.cs

@@ -42,6 +42,23 @@
 	}
     #endregion
 
+    #region Opertation
+	public enum eOperatationMode
+	{
+		ManualMode,
+		AutoMode,
+		InitialMode,
+	}
+
+	public enum eAutoModeState
+	{
+		ErrorStop,
+		StartRun,
+		Run,
+	}
+
+    #endregion
+
     #region Command
     public enum eCommandType
 	{

+ 4 - 0
Dev/OHV/OHV.Vehicle/App.xaml.cs

@@ -7,6 +7,7 @@ using OHV.Common.Events;
 using Prism.Events;
 using Prism.Ioc;
 using Prism.Modularity;
+using Prism.Mvvm;
 using Prism.Unity;
 using VehicleControlSystem;
 
@@ -68,11 +69,14 @@ namespace OHV.Vehicle
 
         protected override void RegisterTypes(IContainerRegistry containerRegistry)
         {
+            containerRegistry.RegisterSingleton<VCSystem>();
         }
 
         protected override void ConfigureViewModelLocator()
         {
             base.ConfigureViewModelLocator();
+
+            //ViewModelLocationProvider.Register<MainWindow, MainWindowViewModel>();
         }
 
         protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)

+ 14 - 1
Dev/OHV/OHV.Vehicle/MainWindowViewModel.cs

@@ -9,10 +9,14 @@ using OHV.Common.Events;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
+using Prism.Ioc;
 using VehicleControlSystem;
+using Prism.Modularity;
+using Prism.Unity;
 
 namespace OHV.Vehicle
 {
+    [ModuleDependency("VCSystem")]
     public class MainWindowViewModel :BindableBase
     {
         private string _title = "Prism Unity Application";
@@ -23,14 +27,17 @@ namespace OHV.Vehicle
         }
 
         IEventAggregator eventAggregator = null;
+        VCSystem VCSystem = null;
 
         public ICommand TestCommand { get; set; }
 
-        public MainWindowViewModel(IEventAggregator ea)
+        public MainWindowViewModel(IEventAggregator ea, VCSystem cSystem)
         {
             this.eventAggregator = ea;
             this.eventAggregator.GetEvent<GUIMessagePubSubEvent>().Subscribe(UICallbackCommunication, ThreadOption.UIThread);
 
+            this.VCSystem = cSystem;
+
             this.TestCommand = new DelegateCommand(ExecuteTextCommand);
         }
 
@@ -51,6 +58,12 @@ namespace OHV.Vehicle
         public void InitViewModel()
         {
             //VCSystem.Instance.Init();
+            var containerRegistry = ServiceLocator.Current.GetInstance<VCSystem>();
+            if (containerRegistry.Equals(this.VCSystem))
+            {
+                Console.WriteLine("==");
+            }
+            //var vsys = containerRegistry.GetContainer().Resolve<IContainerProvider>();
         }
 
         public void Dispose()

+ 140 - 0
Dev/OHV/VehicleControlSystem/Managers/AutoManager.cs

@@ -0,0 +1,140 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using GSG.NET.Concurrent;
+using GSG.NET.Logging;
+using OHV.Common.Shareds;
+using VehicleControlSystem.ControlLayer.IO;
+
+namespace VehicleControlSystem.Managers
+{
+    public class AutoManager : IDisposable
+    {
+        static Logger logger = Logger.GetLogger();
+
+        Thread threadWorker = null;
+        bool isThreadAlive = false;
+
+        IIO iO = null;
+
+        private eOperatationMode operationMode;
+
+        public eOperatationMode OperationModeProperty
+        {
+            get { return operationMode; }
+            set { operationMode = value; }
+        }
+
+        private eAutoModeState autoModeState;
+
+        public eAutoModeState AutoModeStateProperty
+        {
+            get { return autoModeState; }
+            set { autoModeState = value; }
+        }
+
+
+
+        public AutoManager( IIO io )
+        {
+            this.iO = io;
+        }
+
+        public void Init()
+        {
+            this.isThreadAlive = true;
+            this.threadWorker = ThreadUtils.Invoke(this.ThreadWork);
+        }
+
+        void ThreadWork()
+        {
+            while (this.isThreadAlive)
+            {
+                try
+                {
+                    Thread.Sleep(5);
+
+                    DoWork();
+                }
+                catch (Exception ex)
+                {
+                    logger.E($"{GetType().Name} - Thread Exception : {ex.StackTrace}");
+                }
+            }
+        }
+
+
+        public void DoWork()
+        {
+            switch (this.OperationModeProperty)
+            {
+                case eOperatationMode.ManualMode:
+                    break;
+                case eOperatationMode.AutoMode:
+                    switch (this.AutoModeStateProperty)
+                    {
+                        case eAutoModeState.ErrorStop:
+                            break;
+                        case eAutoModeState.StartRun:
+                            break;
+                        case eAutoModeState.Run:
+                            break;
+                        default:
+                            break;
+                    }
+                    break;
+                case eOperatationMode.InitialMode:
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        public void ProcessAlarm()
+        {
+            
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false; // 중복 호출을 검색하려면
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                    // TODO: 관리되는 상태(관리되는 개체)를 삭제합니다.
+                    this.isThreadAlive = false;
+                    if (!this.threadWorker.Join(3000))
+                        ThreadUtils.Kill(this.threadWorker);
+                }
+
+                // TODO: 관리되지 않는 리소스(관리되지 않는 개체)를 해제하고 아래의 종료자를 재정의합니다.
+                // TODO: 큰 필드를 null로 설정합니다.
+
+                disposedValue = true;
+            }
+        }
+
+        // TODO: 위의 Dispose(bool disposing)에 관리되지 않는 리소스를 해제하는 코드가 포함되어 있는 경우에만 종료자를 재정의합니다.
+        // ~AutoManager()
+        // {
+        //   // 이 코드를 변경하지 마세요. 위의 Dispose(bool disposing)에 정리 코드를 입력하세요.
+        //   Dispose(false);
+        // }
+
+        // 삭제 가능한 패턴을 올바르게 구현하기 위해 추가된 코드입니다.
+        public void Dispose()
+        {
+            // 이 코드를 변경하지 마세요. 위의 Dispose(bool disposing)에 정리 코드를 입력하세요.
+            Dispose(true);
+            // TODO: 위의 종료자가 재정의된 경우 다음 코드 줄의 주석 처리를 제거합니다.
+            // GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+}

+ 6 - 1
Dev/OHV/VehicleControlSystem/VCSystem.cs

@@ -22,6 +22,7 @@ namespace VehicleControlSystem
         Scheduler scheduler = null;
         IEventAggregator eventAggregator = null;
         IIO IO = null;
+        AutoManager autoManager = null;
 
         public VCSystem(IEventAggregator ea) 
         {
@@ -41,18 +42,22 @@ namespace VehicleControlSystem
             this.scheduler = new Scheduler(eventAggregator);
             this.scheduler.Init();
 
+            this.autoManager = new AutoManager(this.IO);
+            this.autoManager.Init();
+
             //SqlManager.Instance.RouteDal.Add(new Route {Id=1, Name="P01", PrePoint="P10", NextPoint="P02", Form=Route.eRoadForm.Straight, Type=Route.ePointType.Charging, ScaleValue=0.005, UserPIO=false });
         }
 
         public void Dispose()
         {
             this.scheduler.Dispose();
-
+            this.autoManager.Dispose();
             (this.IO as IDisposable).Dispose(); //IO 는 마지막에 정리함.
         }
 
         public void RegisterTypes(IContainerRegistry containerRegistry)
         {
+            //containerRegistry.RegisterSingleton<VCSystem>();
         }
 
         public void OnInitialized(IContainerProvider containerProvider)

+ 1 - 0
Dev/OHV/VehicleControlSystem/VehicleControlSystem.csproj

@@ -77,6 +77,7 @@
     <Compile Include="ControlLayer\IO\Lib\MOTION_DEFINE_PlusE.cs" />
     <Compile Include="ControlLayer\IO\Lib\MOTION_EziSERVO2_DEFINE.cs" />
     <Compile Include="ControlLayer\Vehicle.cs" />
+    <Compile Include="Managers\AutoManager.cs" />
     <Compile Include="Managers\Scheduler.cs" />
     <Compile Include="Managers\SqlManager.cs" />
     <Compile Include="VCSystem.cs" />