|
@@ -55,6 +55,10 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
+ GetEvent(Topic.DisConnect).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.DisConnect).Publish(this);
|
|
|
+ });
|
|
|
this.GetType().Assembly.GetTypes()
|
|
|
.Where(x => x.IsAnsiClass && !x.IsAbstract && x.IsAssignableTo(typeof(ObservableObject)))
|
|
|
.ToList()
|
|
@@ -69,24 +73,24 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
{
|
|
|
|
|
|
}
|
|
|
- public Avalonia.Media.IBrush TitleColor => CommunicationViewModel.Intance.LocalIsConnect ? Brushes.Black : Brushes.Red;
|
|
|
+ public Avalonia.Media.IBrush TitleColor => CommunicationViewModel.Instance.LocalIsConnect ? Brushes.Black : Brushes.Red;
|
|
|
public ICommand ExitCommand => new RelayCommand(Exit);
|
|
|
private void Exit()
|
|
|
{
|
|
|
ShowAsk(App.Current?.FindResource("PromptExitMsg")+"",()=>
|
|
|
{
|
|
|
- CommunicationViewModel.Intance.LocalCommunication?.GetEvent(Topic.STOP)?.Publish(this, null);
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STOP)?.Publish(this, null);
|
|
|
Environment.Exit(0);
|
|
|
});
|
|
|
}
|
|
|
private string GetTitle()
|
|
|
{
|
|
|
string s = string.Empty;
|
|
|
- if(ViewModels.CommunicationViewModel.Intance.LocalIsConnect)
|
|
|
+ if(ViewModels.CommunicationViewModel.Instance.LocalIsConnect)
|
|
|
{
|
|
|
if(MainPageViewModel.Instance.MainPageType == MainPageType.StartPage)
|
|
|
{
|
|
|
- s = $"{App.Current?.FindResource("Title")}-{ViewModels.DeviceMangerViewModel.Instance.CurrentDevice!.Name}[{CommunicationViewModel.Intance.LocalCommunication.IP}:{CommunicationViewModel.Intance.LocalCommunication.Port}]";
|
|
|
+ s = $"{App.Current?.FindResource("Title")}-{ViewModels.DeviceMangerViewModel.Instance.CurrentDevice!.Name}[{CommunicationViewModel.Instance.LocalCommunication.IP}:{CommunicationViewModel.Instance.LocalCommunication.Port}]";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -99,6 +103,11 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
}
|
|
|
return s;
|
|
|
}
|
|
|
+ public ICommand ConnectCommand => new RelayCommand(Connect);
|
|
|
+ private void Connect()
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.Connect(ViewModels.ShakerSettingViewModel.Instance.RemoteIP, ViewModels.ShakerSettingViewModel.Instance.RemotePort);
|
|
|
+ }
|
|
|
|
|
|
public override string Title => GetTitle();
|
|
|
|
|
@@ -229,7 +238,7 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
public ICommand CloseCommand => new RelayCommand(Close);
|
|
|
private void Close()
|
|
|
{
|
|
|
- CommunicationViewModel.Intance.LocalCommunication?.GetEvent(Topic.STOP)?.Publish(this, null);
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STOP)?.Publish(this, null);
|
|
|
Environment.Exit(0);
|
|
|
}
|
|
|
public ICommand DebugCommand => new RelayCommand<string?>(Debug);
|
|
@@ -287,6 +296,168 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
await window.ShowDialog(desktop.MainWindow!);
|
|
|
}
|
|
|
}
|
|
|
+ public void InitServiceMsg()
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<string>(Topic.SERVICERESULT).Subscrip((_, _) => Topic.SERVICERESULT);
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<Shaker.Models.AllConfig>(Shaker.Models.Topic.SYNCCONFIG).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ return new AllConfig()
|
|
|
+ {
|
|
|
+ OilSource = OilSourceStatusViewModel.Instance.Model,
|
|
|
+ RandomConfig = RandomConfigViewModel.Instance.Model,
|
|
|
+ ShakerConfig = ShakerConfigViewModel.Instance.Model,
|
|
|
+ ShakerControl = ShakerControlViewModel.Instance.Model,
|
|
|
+ ShakerStatus = ShakerStatusViewModel.Instance.Model,
|
|
|
+ SweepConfig = SweepConfigViewModel.Instance.Model,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<DeviceInfoModel?>().Publish(this, ViewModels.DeviceMangerViewModel.Instance.CurrentDevice?.Model);
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<RandomTestStep>().Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent<RandomTestStep>().Publish(this, args.Data);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<MainPageType>().Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent<MainPageType>().Publish(this, args.Data);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Shaker.Models.Topic.START).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.START).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.STARTRANDOMTEST).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STARTRANDOMTEST).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.STOP).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STOP).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.RISETABLE).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.RISETABLE).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.ZEROCHANGE).Subscrip((_, e) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.ZEROCHANGE).Publish(this, null, e.Data[0]);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.DROPTABLE).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.DROPTABLE).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.STOPSIGNALGEN).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STOPSIGNALGEN).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.VALVEPOWER).Subscrip((_, e) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STOPSIGNALGEN).Publish(this, null, e.Data[0]);
|
|
|
+ });
|
|
|
+
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.STARTSIGNALGEN).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STARTSIGNALGEN).Publish(this);
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.RESETERROR).Subscrip((_, _) =>
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.RESETERROR).Publish(this);
|
|
|
+ });
|
|
|
+
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.CircuitPressure).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 2 && args.Data[0] is int index && args.Data[1] is float pressure)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.CircuitPressure).Publish(this, null, index, pressure);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.CircuitStart).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 2 && args.Data[0] is int index && args.Data[1] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.CircuitStart).Publish(this, null, index, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.CircuitLoad).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 2 && args.Data[0] is int index && args.Data[1] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.CircuitLoad).Publish(this, null, index, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.ForerunnerPressure).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is float pressure)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.ForerunnerPressure).Publish(this, null, pressure);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.ForerunnerStart).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.ForerunnerStart).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.ForerunnerLoad).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.ForerunnerLoad).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.AssistantPressure).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is float pressure)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.AssistantPressure).Publish(this, null, pressure);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.AssistantStart).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.AssistantStart).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.AssistantLoad).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.AssistantLoad).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.CirculatePressure).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is float pressure)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.CirculatePressure).Publish(this, null, pressure);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.CirculateStart).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.CirculateStart).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.CirculateLoad).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.CirculateLoad).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent(Topic.OilEmergencyStop).Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data.Length >= 1 && args.Data[0] is bool state)
|
|
|
+ {
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.OilEmergencyStop).Publish(this, null, state);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
public ICommand RandomConfigCommand => new RelayCommand<string?>(RandomConfig);
|
|
|
private async void RandomConfig(string? p)
|
|
|
{
|
|
@@ -316,8 +487,8 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
{
|
|
|
ShowAsk(App.Current?.FindResource("AskDisconnect") + "", () =>
|
|
|
{
|
|
|
- CommunicationViewModel.Intance.LocalCommunication?.GetEvent(Topic.STOP).Publish(this, null);
|
|
|
- CommunicationViewModel.Intance.DisConnect();
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.STOP).Publish(this, null);
|
|
|
+ CommunicationViewModel.Instance.DisConnect();
|
|
|
});
|
|
|
}
|
|
|
public ICommand ShakerControlCommand => new RelayCommand<string?>(ShakerControl);
|
|
@@ -359,7 +530,19 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
public void SyncConfig()
|
|
|
{
|
|
|
LogViewModel.Instance.AddLog($"同步控制器设置参数");
|
|
|
- var config= CommunicationViewModel.Intance.LocalCommunication.GetEvent<Shaker.Models.AllConfig>(Shaker.Models.Topic.SYNCCONFIG).Publish(this);
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent<DeviceInfoModel?>().Subscrip((sender, args) =>
|
|
|
+ {
|
|
|
+ if (args.Data == null)
|
|
|
+ {
|
|
|
+ DeviceMangerViewModel.Instance.CurrentDevice = null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (DeviceMangerViewModel.Instance.CurrentDevice == null) DeviceMangerViewModel.Instance.CurrentDevice = new DeviceInfoViewModel();
|
|
|
+ DeviceMangerViewModel.Instance.CurrentDevice.UpDateModel(args.Data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var config= CommunicationViewModel.Instance.LocalCommunication?.GetEvent<Shaker.Models.AllConfig>(Shaker.Models.Topic.SYNCCONFIG).Publish(this);
|
|
|
if(config ==null)
|
|
|
{
|
|
|
LogViewModel.Instance.AddLog($"同步控制器设置参数失败", LogType.Error);
|
|
@@ -367,14 +550,17 @@ public class MainViewModel : ViewModelBase<IModel>
|
|
|
.WithTitle(App.Current?.FindResource("PromptTitle") + "")
|
|
|
.WithContent(App.Current?.FindResource("GetConfigError")+"")
|
|
|
.Queue();
|
|
|
- CommunicationViewModel.Intance.LocalCommunication.Close();
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.Close();
|
|
|
return;
|
|
|
}
|
|
|
LogViewModel.Instance.AddLog($"同步控制器设置参数成功");
|
|
|
GetEvent<AllConfig>().Publish(this, config);
|
|
|
- CommunicationViewModel.Intance.LocalCommunication.GetEvent(Topic.START).Publish(this);
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<AllConfig>(Topic.SYNCCONFIG).Publish(this,null, config);
|
|
|
+ CommunicationViewModel.Instance.LocalCommunication?.GetEvent(Topic.START).Publish(this);
|
|
|
OnPropertyChanged(nameof(Title));
|
|
|
OnPropertyChanged(nameof(TitleColor));
|
|
|
+ CommunicationViewModel.Instance.ServiceCommunication?.GetEvent<DeviceInfoModel?>().Publish(this, DeviceMangerViewModel.Instance.CurrentDevice?.Model);
|
|
|
+
|
|
|
}
|
|
|
public static MainViewModel Default { get; } = new MainViewModel();
|
|
|
|