|
@@ -1,117 +1,118 @@
|
|
using AlarmInfoServerSim.Services;
|
|
using AlarmInfoServerSim.Services;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
-using ConfigOperator;
|
|
|
|
using HardwareData;
|
|
using HardwareData;
|
|
using RealtimeData;
|
|
using RealtimeData;
|
|
using RTCommunicatorBase;
|
|
using RTCommunicatorBase;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
-using System.IO;
|
|
|
|
|
|
|
|
-namespace AlarmInfoServerSim.ViewModels
|
|
|
|
|
|
+namespace AlarmInfoServerSim.ViewModels;
|
|
|
|
+
|
|
|
|
+public partial class WorkAreaViewModel : ObservableObject
|
|
{
|
|
{
|
|
- public partial class WorkAreaViewModel : ObservableObject
|
|
|
|
- {
|
|
|
|
- private readonly IInfoSendingService _infoSendingService;
|
|
|
|
|
|
+ private readonly IInfoSendingService _infoSendingService;
|
|
|
|
|
|
- private readonly Hardwares _hardwares;
|
|
|
|
|
|
+ private readonly Hardwares _hardwares;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private ConcurrentDictionary<byte, Mini8Data> _mini8;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private ConcurrentDictionary<byte, Mini8Data> _mini8;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private int _selectedMini8Index = -1;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private int _selectedMini8Index = -1;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private ConcurrentDictionary<byte, ChannelData> _mini8Channel;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private ConcurrentDictionary<byte, ChannelData> _mini8Channel;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private int _selectedChannelIndex = -1;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private int _selectedChannelIndex = -1;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private AlarmType[] _alarmTypes;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private AlarmType[] _alarmTypes;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private int _selectedAlarmTypeIndex = -1;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private int _selectedAlarmTypeIndex = -1;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private float _pV;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private float _pV;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private float _caps;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private float _caps;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private float _floor;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private float _floor;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- private ObservableCollection<string> _receivingTime;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private ObservableCollection<string> _receivingTime;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
|
- [NotifyCanExecuteChangedFor(nameof(SendInfoCommand))]
|
|
|
|
- private bool _hasConnection;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ [NotifyCanExecuteChangedFor(nameof(SendInfoCommand))]
|
|
|
|
+ private bool _hasConnection;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- public WorkAreaViewModel(IInfoSendingService infoSendingService)
|
|
|
|
|
|
+ public WorkAreaViewModel(ISharedConfig sharedConfig ,IInfoSendingService infoSendingService)
|
|
|
|
+ {
|
|
|
|
+ if(sharedConfig.Hardwares is null)
|
|
{
|
|
{
|
|
- _infoSendingService = infoSendingService;
|
|
|
|
- _infoSendingService.ConnectionStatusChanged += OnConnectionStatusChanged;
|
|
|
|
- _infoSendingService.DataReceived += OnDataReceived;
|
|
|
|
|
|
+ throw new ArgumentNullException(nameof(sharedConfig.Hardwares));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _hardwares = sharedConfig.Hardwares;
|
|
|
|
|
|
- _hardwares = new Hardwares();
|
|
|
|
- HardwareFileLoader hardwareFileLoader = new HardwareFileLoader(_hardwares);
|
|
|
|
- string folderPath = Path.Combine(new DirectoryInfo(Paths.LocalPath!)!.Parent!.Parent!.FullName, "Settings", "Hardwares");
|
|
|
|
|
|
+ _mini8 = _hardwares.Mini8s;
|
|
|
|
+ _mini8Channel = [];
|
|
|
|
+ _alarmTypes = Enum.GetValues<AlarmType>();
|
|
|
|
+ _receivingTime = [];
|
|
|
|
|
|
- _mini8 = hardwareFileLoader.Load(folderPath) ? _hardwares.Mini8s : [];
|
|
|
|
- _mini8Channel = [];
|
|
|
|
|
|
+ _infoSendingService = infoSendingService;
|
|
|
|
+ _infoSendingService.ConnectionChanged += OnConnectionChanged;
|
|
|
|
+ _infoSendingService.DataReceived += OnDataReceived;
|
|
|
|
+ }
|
|
|
|
|
|
- _alarmTypes = Enum.GetValues<AlarmType>();
|
|
|
|
- _receivingTime = [];
|
|
|
|
- }
|
|
|
|
|
|
+ partial void OnSelectedMini8IndexChanged(int value)
|
|
|
|
+ {
|
|
|
|
+ SelectedChannelIndex = -1;
|
|
|
|
+ SelectedAlarmTypeIndex = -1;
|
|
|
|
+ Mini8Channel = _hardwares.Mini8Channels[Mini8.ElementAt(value).Key];
|
|
|
|
+ }
|
|
|
|
|
|
- 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;
|
|
|
|
+ }
|
|
|
|
|
|
- partial void OnSelectedChannelIndexChanged(int value)
|
|
|
|
|
|
+ [RelayCommand(CanExecute = nameof(HasConnection))]
|
|
|
|
+ private void SendInfo()
|
|
|
|
+ {
|
|
|
|
+ if (SelectedMini8Index == -1 || SelectedChannelIndex == -1 || SelectedAlarmTypeIndex == -1)
|
|
{
|
|
{
|
|
- SelectedAlarmTypeIndex = -1;
|
|
|
|
|
|
+ //log
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- [RelayCommand(CanExecute = nameof(HasConnection))]
|
|
|
|
- private void SendInfo()
|
|
|
|
|
|
+ // ChannelAlarmNotify = 1
|
|
|
|
+ _infoSendingService.Send(1, new ST_ALARM()
|
|
{
|
|
{
|
|
- 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
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ Mini8Index = Mini8.ElementAt(SelectedMini8Index).Key,
|
|
|
|
+ ChannelIndex = Mini8Channel.ElementAt(SelectedChannelIndex).Key,
|
|
|
|
+ PV = PV,
|
|
|
|
+ Caps = Caps,
|
|
|
|
+ Floor = Floor,
|
|
|
|
+ AlarmType = (AlarmType)SelectedAlarmTypeIndex
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
- private void OnConnectionStatusChanged(object? sender, bool e)
|
|
|
|
|
|
+ private void OnConnectionChanged(object? sender, (bool, UniversalNetFrame451.IO.TcpConnection) e)
|
|
|
|
+ {
|
|
|
|
+ App.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
{
|
|
- App.Current.Dispatcher.Invoke(() =>
|
|
|
|
- {
|
|
|
|
- HasConnection = e;
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ HasConnection = e.Item1;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
- private void OnDataReceived(object? sender, (ushort, TLVProtocal.TlvData) e)
|
|
|
|
- {
|
|
|
|
- ReceivingTime.Add(e.Item2.DateTime.ToString());
|
|
|
|
- }
|
|
|
|
|
|
+ private void OnDataReceived(object? sender, (ushort, TLVProtocal.TlvData) e)
|
|
|
|
+ {
|
|
|
|
+ ReceivingTime.Add(e.Item2.DateTime.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|