diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-07 19:50:40 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-07 19:50:40 +0200 |
| commit | 84a74bd9ea68a3f913e733a470ec64d1f8f50424 (patch) | |
| tree | d49e0c3d705f592cb81087f46aa0e4c8dffa2ed7 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels | |
| parent | b84ea5c89946d6e21ffa72f913cab3bec5f1d5c6 (diff) | |
| download | Tango-84a74bd9ea68a3f913e733a470ec64d1f8f50424.tar.gz Tango-84a74bd9ea68a3f913e733a470ec64d1f8f50424.zip | |
Started working on monitoring view..
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
2 files changed, 140 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs new file mode 100644 index 000000000..83eee1333 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/IOVM.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class IOVM : ExtendedObject + { + private Io _io; + public Io IO + { + get { return _io; } + set { _io = value; RaisePropertyChangedAuto(); } + } + + private String _name; + public String Name + { + get { return _name; } + set { _name = value; } + } + + private bool _index; + public bool Index + { + get { return _index; } + set { _index = value; } + } + + private double _value; + public double Value + { + get { return _value; } + set { _value = value; RaisePropertyChanged(nameof(Value)); } + } + + public IOVM(Io io, String name) + { + IO = io; + Name = name; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs new file mode 100644 index 000000000..8edbd7b83 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MonitoringViewVM.cs @@ -0,0 +1,93 @@ +using Google.Protobuf.Collections; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Observables; +using Tango.Integration.Services; +using Tango.MachineStudio.Common.StudioApplication; +using Tango.PMR.Diagnostics; +using Tango.SharedUI; + +namespace Tango.MachineStudio.Developer.ViewModels +{ + public class MonitoringViewVM : ViewModel + { + private ObservableCollection<IOVM> _availableControllers; + public ObservableCollection<IOVM> AvailableControllers + { + get { return _availableControllers; } + set { _availableControllers = value; } + } + + private ObservableCollection<IOVM> _controllers; + public ObservableCollection<IOVM> Controllers + { + get { return _controllers; } + set { _controllers = value; } + } + + private ObservablesEntitiesAdapter _adapter; + public ObservablesEntitiesAdapter Adapter + { + get { return _adapter; } + set { _adapter = value; } + } + + public IStudioApplicationManager ApplicationManager { get; set; } + + public MonitoringViewVM(IStudioApplicationManager applicationManager) + { + ApplicationManager = applicationManager; + ApplicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; + + if (!this.DesignMode) + { + Adapter = ObservablesEntitiesAdapter.Instance; + AvailableControllers = Adapter.Ios.Select(x => new IOVM(x, x.Name)).ToObservableCollection(); + } + + Controllers = new ObservableCollection<IOVM>(); + } + + private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine) + { + if (machine != null) + { + machine.DiagnosticsDataAvailable -= Machine_DiagnosticsDataAvailable; + machine.DiagnosticsDataAvailable += Machine_DiagnosticsDataAvailable; + } + } + + private void Machine_DiagnosticsDataAvailable(object sender, PushDiagnosticsResponse data) + { + foreach (var prop in data.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + IOVM controller = _controllers.SingleOrDefault(x => x.IO.Name == prop.Name); + + if (controller != null) + { + if (!controller.IO.MultiChannel) + { + RepeatedField<double> arr = prop.GetValue(data) as RepeatedField<double>; + controller.Value = arr.Last(); + } + else + { + //DoubleArray[] arrayOfDoubles = Enumerable.ToArray(prop.GetValue(data) as IEnumerable<DoubleArray>); + //(controller as GraphMultiController).PushData(arrayOfDoubles.Select(x => x.Data.ToList()).ToList()); + } + } + } + } + + public void OnDropAvailableIO(IOVM ioVM) + { + Controllers.Add(ioVM); + AvailableControllers.Remove(ioVM); + } + } +} |
