Procházet zdrojové kódy

Complete the first verion

SenGao před 4 týdny
rodič
revize
88a162e1c1

+ 1 - 2
Tools/AlarmInfoServerSim/App.xaml.cs

@@ -16,8 +16,7 @@ namespace AlarmInfoServerSim
         {
             //Services
             containerRegistry.RegisterSingleton<ISharedConfig, SharedConfig>();
-            containerRegistry.RegisterSingleton<ISendInfoService, SendInfoService>();
-
+            containerRegistry.RegisterSingleton<IInfoSendingService, InfoSendingService>();
         }
     }
 

+ 14 - 0
Tools/AlarmInfoServerSim/Services/IInfoSendingService.cs

@@ -0,0 +1,14 @@
+using RTCommunicatorBase;
+using UniversalNetFrame451.IO;
+
+namespace AlarmInfoServerSim.Services
+{
+    public interface IInfoSendingService
+    {
+        bool Open();
+        bool Send(byte tag, ST_ALARM alarm);
+
+        event EventHandler<bool>? ConnectionStatusChanged;
+        event EventHandler<TcpConnection>? TcpConnectionChanged;
+    }
+}

+ 0 - 12
Tools/AlarmInfoServerSim/Services/ISendInfoService.cs

@@ -1,12 +0,0 @@
-using RTCommunicatorBase;
-
-namespace AlarmInfoServerSim.Services
-{
-    public interface ISendInfoService
-    {
-        bool Open();
-        bool Send(byte tag, ST_ALARM alarm);
-
-        event EventHandler<bool>? ConnectionChanged;
-    }
-}

+ 10 - 10
Tools/AlarmInfoServerSim/Services/SendInfoService.cs

@@ -1,15 +1,10 @@
 using RTCommunicatorBase;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using TLVProtocal;
 using UniversalNetFrame451.IO;
 
 namespace AlarmInfoServerSim.Services
 {
-    public class SendInfoService : ISendInfoService, ITlvProvider, IDisposable
+    public class InfoSendingService : IInfoSendingService, ITlvProvider, IDisposable
     {
         private readonly ISharedConfig _sharedConfig;
         private readonly ITlvCommunicatorServer _server;
@@ -17,15 +12,18 @@ namespace AlarmInfoServerSim.Services
         private bool _isConnected = false;
         private bool disposedValue;
 
-        public SendInfoService(ISharedConfig sharedConfig) 
+        public InfoSendingService(ISharedConfig sharedConfig) 
         {
             _sharedConfig= sharedConfig;
 
             _server = TlvFactory.GetTlvServer();
             _server.Initialize(this);
+
+            Open();
         }
 
-        public event EventHandler<bool>? ConnectionChanged;
+        public event EventHandler<bool>? ConnectionStatusChanged;
+        public event EventHandler<TcpConnection>? TcpConnectionChanged;
 
         public bool Open()
         {
@@ -48,13 +46,15 @@ namespace AlarmInfoServerSim.Services
         public void Connected(TcpConnection connection)
         {
             _isConnected = true;
-            ConnectionChanged?.Invoke(null, _isConnected);
+            ConnectionStatusChanged?.Invoke(null, _isConnected);
+            TcpConnectionChanged?.Invoke(null, connection);
         }
 
         public void Disconnected(TcpConnection connection)
         {
             _isConnected = false;
-            ConnectionChanged?.Invoke(null, _isConnected);
+            ConnectionStatusChanged?.Invoke(null, _isConnected);
+            TcpConnectionChanged?.Invoke(null, connection);
         }
 
         public void Received(TlvData data)

+ 17 - 0
Tools/AlarmInfoServerSim/ViewModels/LogBarViewModel.cs

@@ -0,0 +1,17 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AlarmInfoServerSim.ViewModels
+{
+    public class LogBarViewModel : ObservableObject
+    {
+        public LogBarViewModel() 
+        {
+
+        }
+    }
+}

+ 1 - 4
Tools/AlarmInfoServerSim/ViewModels/MainWindowViewModel.cs

@@ -1,7 +1,4 @@
-using AlarmInfoServerSim.Views;
-using Prism.Ioc;
-
-namespace AlarmInfoServerSim.ViewModels
+namespace AlarmInfoServerSim.ViewModels
 {
     public class MainWindowViewModel
     {

+ 15 - 6
Tools/AlarmInfoServerSim/ViewModels/StatusBarViewModel.cs

@@ -6,7 +6,7 @@ namespace AlarmInfoServerSim.ViewModels
     public partial class StatusBarViewModel : ObservableObject
     {
         private readonly ISharedConfig _sharedConfig;
-        private readonly ISendInfoService _sendInfoService;
+        private readonly IInfoSendingService _sendInfoService;
 
         [ObservableProperty]
         private string _status;
@@ -17,18 +17,27 @@ namespace AlarmInfoServerSim.ViewModels
         [ObservableProperty]
         private ushort _port;
 
-        public StatusBarViewModel(ISharedConfig sharedConfig, ISendInfoService sendInfoService)
+        public StatusBarViewModel(ISharedConfig sharedConfig, IInfoSendingService sendInfoService)
         {
             _sharedConfig = sharedConfig;
-            _status = "Unknown";
-            _ipAddress = _sharedConfig.BasicInfo?.RTServerAddress ?? "Unknown";
+            _status = "Disconnected";
+            _ipAddress = "Unknown";
             _port = _sharedConfig.BasicInfo?.RTServerPort ?? 0;
 
             _sendInfoService = sendInfoService;
-            _sendInfoService.ConnectionChanged += OnConnectionChanged;
+            _sendInfoService.ConnectionStatusChanged += OnConnectionStatusChanged;
+            _sendInfoService.TcpConnectionChanged += OnTcpConnectionChanged;
         }
 
-        private void OnConnectionChanged(object? sender, bool e)
+        private void OnTcpConnectionChanged(object? sender, UniversalNetFrame451.IO.TcpConnection e)
+        {
+            if(Status== "Connected")
+            {
+                IpAddress=e.RemoteEndPoint.Address.ToString();
+            }
+        }
+
+        private void OnConnectionStatusChanged(object? sender, bool e)
         {
             Status = e ? "Connected" : "Disconnected";
         }

+ 93 - 0
Tools/AlarmInfoServerSim/ViewModels/WorkAreaViewModel.cs

@@ -0,0 +1,93 @@
+using AlarmInfoServerSim.Services;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using ConfigOperator;
+using HardwareData;
+using RealtimeData;
+using RTCommunicatorBase;
+using System.Collections.Concurrent;
+using System.IO;
+
+namespace AlarmInfoServerSim.ViewModels
+{
+    public partial class WorkAreaViewModel : ObservableObject
+    {
+        private readonly IInfoSendingService _infoSendingService;
+
+        private readonly Hardwares _hardwares;
+
+        [ObservableProperty]
+        private ConcurrentDictionary<byte, Mini8Data> _mini8;
+
+        [ObservableProperty]
+        private int _selectedMini8Index = -1;
+
+        [ObservableProperty]
+        private ConcurrentDictionary<byte, ChannelData> _mini8Channel;
+
+        [ObservableProperty]
+        private int _selectedChannelIndex = -1;
+
+        [ObservableProperty]
+        private AlarmType[] _alarmTypes;
+
+        [ObservableProperty]
+        private int _selectedAlarmTypeIndex = -1;
+
+        [ObservableProperty]
+        private float _pV;
+
+        [ObservableProperty]
+        private float _caps;
+
+        [ObservableProperty]
+        private float _floor;
+
+        public WorkAreaViewModel(IInfoSendingService infoSendingService)
+        {
+            _infoSendingService = infoSendingService;
+
+            _hardwares = new Hardwares();
+            HardwareFileLoader hardwareFileLoader = new HardwareFileLoader(_hardwares);
+            string folderPath = Path.Combine(new DirectoryInfo(Paths.LocalPath!)!.Parent!.Parent!.FullName, "Settings", "Hardwares");
+
+            _mini8 = hardwareFileLoader.Load(folderPath) ? _hardwares.Mini8s : [];
+            _mini8Channel = [];
+
+            _alarmTypes = Enum.GetValues<AlarmType>();
+        }
+
+        
+
+        partial void OnSelectedMini8IndexChanged(int value)
+        {
+            SelectedChannelIndex = -1;
+            SelectedAlarmTypeIndex = -1;
+            var index = Mini8.ElementAt(value).Key;
+            Mini8Channel = _hardwares.Mini8Channels[index];
+        }
+
+        partial void OnSelectedChannelIndexChanged(int value)
+        {
+            SelectedAlarmTypeIndex = -1;
+        }
+
+        [RelayCommand]
+        private void SendInfo()
+        {
+            if (SelectedMini8Index > -1 && SelectedChannelIndex > -1 && SelectedAlarmTypeIndex > -1)
+            {
+                // ChannelAlarmNotify = 1
+                _infoSendingService.Send(1, new ST_ALARM()
+                {
+                    Mini8Index = Mini8.ElementAt(SelectedMini8Index).Key,
+                    ChannelIndex = Mini8Channel.ElementAt(SelectedChannelIndex).Key,
+                    PV = PV,
+                    Caps = Caps,
+                    Floor = Floor,
+                    AlarmType = (AlarmType)SelectedAlarmTypeIndex
+                });
+            }
+        }
+    }
+}

+ 1 - 1
Tools/AlarmInfoServerSim/Views/MainWindow.xaml

@@ -6,7 +6,7 @@
         xmlns:local="clr-namespace:AlarmInfoServerSim.Views"
         xmlns:prism="http://prismlibrary.com/"
         prism:ViewModelLocator.AutoWireViewModel="True"
-        Title="MainWindow" Height="600" Width="600" ResizeMode="CanMinimize"
+        Title="Alarm Information Service" Height="600" Width="600" ResizeMode="CanMinimize"
         mc:Ignorable="d">
     <Grid>
         <Grid.RowDefinitions>

+ 27 - 3
Tools/AlarmInfoServerSim/Views/WorkArea.xaml

@@ -13,9 +13,33 @@
             <ColumnDefinition Width="300" />
             <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
-        <StackPanel Grid.Column="0" Orientation="Vertical">
-            
+        <StackPanel Grid.Column="0" Orientation="Vertical" Margin="5,10,2,10">
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0">
+                <Label>Mini8: </Label>
+                <ComboBox Width="120" SelectedIndex="{Binding SelectedMini8Index}" ItemsSource="{Binding Mini8}" DisplayMemberPath="Value.Name"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0">
+                <Label>Channel: </Label>
+                <ComboBox Width="120" SelectedIndex="{Binding SelectedChannelIndex}" ItemsSource="{Binding Mini8Channel}" DisplayMemberPath="Value.Name"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0">
+                <Label>Alarm Type: </Label>
+                <ComboBox Width="120" SelectedIndex="{Binding SelectedAlarmTypeIndex}" ItemsSource="{Binding AlarmTypes}"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0">
+                <Label>PV:</Label>
+                <TextBox Width="80" Text="{Binding PV}"></TextBox>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0">
+                <Label>Caps:</Label>
+                <TextBox Width="80" Text="{Binding Caps}"></TextBox>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10,0,0">
+                <Label>Floor:</Label>
+                <TextBox Width="80" Text="{Binding Floor}"></TextBox>
+            </StackPanel>
+
         </StackPanel>
-        <Button Grid.Column="1" Content="Send" Margin="70,50,70,260"/>
+        <Button Grid.Column="1" Content="Send" Command="{Binding SendInfoCommand}" Margin="70,50,70,260"/>
     </Grid>
 </UserControl>