Skip to content

Commit 76ac433

Browse files
committed
Merged dev into main.
1 parent 91f0bc0 commit 76ac433

File tree

14 files changed

+495
-88
lines changed

14 files changed

+495
-88
lines changed

IPR.Control.Panel/Controls/DefaultValueOffsetControl.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ protected override void OnDataContextChanged(EventArgs e)
3131
private void InitDefaultValue()
3232
{
3333
_sensor = (DataContext as Models.Control).Sensor;
34+
if(_sensor == null)
35+
return;
3436
tbDefaultValue.Text = _sensor.DefaultValue.ToString();
3537
}
3638

IPR.Control.Panel/Controls/GraphOffsetValueControl.axaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ private void InitGraph()
5252
private void SetSensor()
5353
{
5454
_sensor = _control.Sensor;
55+
if(_sensor == null)
56+
return;
5557
_graphEditor.Plot.SetAxisLimits(yMin: _sensor.MinValue, yMax: _sensor.MaxValue, yAxisIndex: 1);
5658
_sensor.History.CollectionChanged += History_CollectionChanged;
5759
}
@@ -70,7 +72,7 @@ private void RefreshSensorPlot(IEnumerable<ValueHistory> history)
7072
if (_historyPlot != null)
7173
_graphEditor.Plot.Remove(_historyPlot);
7274
_historyPlot = _graphEditor.Plot.AddSignal(ys, color: Color.DarkBlue);
73-
_graphEditor.Plot.SetAxisLimits(yMin: ys.Min(), yMax: ys.Max(), xMin: 0, xMax: Constants.HISTORY_TIMESPAN, yAxisIndex: 1);
75+
_graphEditor.Plot.SetAxisLimits(yMin: _control.MinValue, yMax: _control.MaxValue, xMin: 0, xMax: Constants.HISTORY_TIMESPAN, yAxisIndex: 1);
7476
_historyPlot.MarkerShape = ScottPlot.MarkerShape.none;
7577
_historyPlot.YAxisIndex = 1;
7678
_graphEditor.Refresh();
@@ -84,15 +86,15 @@ private void SetMarker()
8486
var ys = _control.Markers.Select(x => x.Y).ToArray();
8587
if (_controlPlot != null)
8688
_graphEditor.Plot.Remove(_controlPlot);
87-
_graphEditor.Plot.SetAxisLimits(yMin: ys.Min(), yMax: ys.Max(), xMin: 0, xMax: Constants.HISTORY_TIMESPAN, yAxisIndex: 0);
88-
_controlPlot = _graphEditor.Plot.AddScatterLines(xs, ys, Color.LightBlue);
89+
_graphEditor.Plot.SetAxisLimits(yMin: _control.MinValue, yMax: _control.MaxValue, xMin: 0, xMax: Constants.HISTORY_TIMESPAN, yAxisIndex: 0);
90+
_controlPlot = _graphEditor.Plot.AddScatterLines(xs, ys, Color.LightBlue);
8991
_controlPlot.YAxisIndex = 0;
9092
_graphEditor.Refresh();
9193
}
9294

9395
private void EditGraph_Clicked(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
9496
{
95-
var controlViewModel = ((Avalonia.StyledElement)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)((Avalonia.Controls.Control)sender).Parent).Parent).Parent).Parent).Parent).Parent).Parent).Parent).Parent).Parent).Parent).Parent).DataContext as ControlsViewModel;
97+
var controlViewModel = (sender as Avalonia.Controls.Control)?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.Parent?.DataContext as ControlsViewModel;
9698
controlViewModel.OpenDialog(_control, SetMarker);
9799
}
98100
}

IPR.Control.Panel/IPR.Control.Panel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<SignAssembly>False</SignAssembly>
1212
<PackageIcon>ipr-logo.jpg</PackageIcon>
1313
<ApplicationManifest>app.manifest</ApplicationManifest>
14-
<VersionPrefix>0.1.0</VersionPrefix>
14+
<VersionPrefix>0.2.0</VersionPrefix>
1515
</PropertyGroup>
1616
<ItemGroup>
1717
<AvaloniaResource Include="Assets\**" />

IPR.Control.Panel/Models/Sensor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public double DefaultValue
6868
.Where(x => x.ParameterType == ParameterType.Value);
6969
if (!defaultValParameter.Any())
7070
return 0;// throw new ArgumentException("No default values found");
71-
if (defaultValParameter.Count() > 1)
72-
throw new ArgumentException("Only one default value allowed.");
71+
//if (defaultValParameter.Count() > 1)
72+
// throw new ArgumentException("Only one default value allowed.");
7373
return defaultValParameter.First().Value;
7474
}
7575
}

IPR.Control.Panel/Services/ControlService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ private async Task SetControlValues(CancellationToken token)
121121

122122
foreach (var control in controlsToUpdate)
123123
{
124-
if (control.ControllerType == ControllerType.Fixed)
125-
CheckAndSetControlFixedValue(control);
124+
//if (control.ControllerType == ControllerType.Fixed)
125+
// CheckAndSetControlFixedValue(control);
126126
if (control.ControllerType == ControllerType.Graph)
127127
CheckAndSetControlGraphValue(control);
128128
}

IPR.Control.Panel/ViewModels/GraphDialogViewViewModel.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Controls;
2+
using DynamicData;
23
using IPR.Control.Panel.Models;
34
using IPR.Control.Panel.Services;
45
using Prism.Commands;
@@ -10,6 +11,7 @@
1011
using System;
1112
using System.Collections.Generic;
1213
using System.Collections.ObjectModel;
14+
using System.ComponentModel.DataAnnotations;
1315
using System.Drawing;
1416
using System.Linq;
1517

@@ -61,7 +63,6 @@ public bool CanSave
6163
set => SetProperty(ref _canSave, value);
6264
}
6365

64-
private double[][] _coordinates;
6566
private List<DraggableMarkerPlot> _markers = new();
6667

6768
public GraphDialogViewViewModel(
@@ -123,6 +124,7 @@ public void RefreshPlot()
123124

124125
private void InitMarkers()
125126
{
127+
_markers = new();
126128
for (int i = 0; i < 3; i++)
127129
{
128130
var x = i switch
@@ -137,12 +139,12 @@ private void InitMarkers()
137139
marker.Dragged += Marker_Dragged;
138140
marker.DragXLimitMin = i switch
139141
{
140-
2 => (SelectedSensor?.MaxValue ?? 100),
142+
//2 => (SelectedSensor?.MinValue ?? 100),
141143
_ => 0
142144
};
143145
marker.DragXLimitMax = i switch
144146
{
145-
0 => 0,
147+
//0 => 0,
146148
_ => (SelectedSensor?.MaxValue ?? 100)
147149
};
148150
marker.DragYLimitMin = Control.MinValue;
@@ -198,6 +200,35 @@ private void Marker_Dragged(object? sender, EventArgs e)
198200
{
199201
var dragger = sender as DraggableMarkerPlot;
200202
dragger.Y = Math.Round(dragger.Y, 0);
203+
dragger.X = Math.Round(dragger.X, 0);
204+
205+
var index = _markers.IndexOf(dragger);
206+
if (index == -1)
207+
return;
208+
if(index == 0)
209+
{
210+
var next = _markers[index + 1];
211+
if (dragger.X >= next.X)
212+
dragger.X = next.X;
213+
}
214+
if (index > 0 && index < _markers.Count - 1)
215+
{
216+
var previous = _markers[index - 1];
217+
var next = _markers[index + 1];
218+
219+
if (dragger.X >= next.X)
220+
dragger.X = next.X;
221+
if (dragger.X <= previous.X)
222+
dragger.X = previous.X;
223+
224+
}
225+
if (index == _markers.Count - 1)
226+
{
227+
var previous = _markers[_markers.Count - 2];
228+
if (dragger.X <= previous.X)
229+
dragger.X = previous.X;
230+
}
231+
201232
RefreshSignal();
202233
}
203234

IPR.Drivers/Ring0/LinuxRing0.cs

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
using IPR.Drivers.Hardware;
2+
3+
namespace IPR.Drivers.Ring0
4+
{
5+
internal class LinuxRing0 : IRing0
6+
{
7+
public bool IsOpen { get; private set; }
8+
9+
public LinuxRing0()
10+
{
11+
Open();
12+
}
13+
14+
public bool Open()
15+
{
16+
IsOpen = CheckVersion();
17+
return IsOpen;
18+
}
19+
20+
private bool CheckVersion()
21+
{
22+
try
23+
{
24+
string rdResult = "";
25+
using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
26+
{
27+
proc.StartInfo.FileName = "rdmsr";
28+
proc.StartInfo.Arguments = "--version ";
29+
proc.StartInfo.UseShellExecute = false;
30+
proc.StartInfo.RedirectStandardOutput = true;
31+
proc.StartInfo.RedirectStandardError = true;
32+
proc.Start();
33+
34+
rdResult += proc.StandardOutput.ReadToEnd();
35+
rdResult += proc.StandardError.ReadToEnd();
36+
37+
proc.WaitForExit();
38+
}
39+
40+
string wrResult = "";
41+
using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
42+
{
43+
proc.StartInfo.FileName = "wrmsr";
44+
proc.StartInfo.Arguments = "--version ";
45+
proc.StartInfo.UseShellExecute = false;
46+
proc.StartInfo.RedirectStandardOutput = true;
47+
proc.StartInfo.RedirectStandardError = true;
48+
proc.Start();
49+
50+
wrResult += proc.StandardOutput.ReadToEnd();
51+
wrResult += proc.StandardError.ReadToEnd();
52+
53+
proc.WaitForExit();
54+
}
55+
56+
return !string.IsNullOrEmpty(rdResult) && !string.IsNullOrEmpty(wrResult)
57+
&& rdResult.Contains("version msr-tools") &&
58+
wrResult.Contains("version msr-tools");
59+
}
60+
catch (Exception e)
61+
{
62+
return false;
63+
}
64+
}
65+
66+
67+
68+
public bool ReadMsr(uint index, out uint eax, out uint edx)
69+
{
70+
eax = 0;
71+
edx = 0;
72+
if (!IsOpen)
73+
{
74+
return false;
75+
}
76+
77+
string rawresuld = "";
78+
using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
79+
{
80+
81+
proc.StartInfo.FileName = "rdmsr";
82+
proc.StartInfo.Arguments = "0x" + index.ToString("X");
83+
proc.StartInfo.UseShellExecute = false;
84+
proc.StartInfo.RedirectStandardOutput = true;
85+
proc.StartInfo.RedirectStandardError = true;
86+
proc.Start();
87+
88+
rawresuld += proc.StandardOutput.ReadToEnd().Replace(Environment.NewLine, "");
89+
rawresuld += proc.StandardError.ReadToEnd();
90+
91+
proc.WaitForExit();
92+
}
93+
94+
try
95+
{
96+
ulong result = Convert.ToUInt64(rawresuld, 16);
97+
edx = (uint)((result >> 32) & 0xFFFFFFFF);
98+
eax = (uint)(result & 0xFFFFFFFF);
99+
return true;
100+
}
101+
catch
102+
{
103+
return false;
104+
}
105+
}
106+
107+
public bool ReadMsr(uint index, out uint eax, out uint edx, GroupAffinity affinity)
108+
{
109+
GroupAffinity previousAffinity = ThreadAffinity.Set(affinity);
110+
bool result = ReadMsr(index, out eax, out edx);
111+
ThreadAffinity.Set(previousAffinity);
112+
return result;
113+
}
114+
115+
public bool WriteMsr(uint index, uint eax, uint edx)
116+
{
117+
if (!IsOpen)
118+
{
119+
return false;
120+
}
121+
122+
try
123+
{
124+
string rawresuld = "";
125+
using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
126+
{
127+
proc.StartInfo.FileName = "wrmsr";
128+
proc.StartInfo.Arguments = "0x" + index.ToString("X") + " " + "0x" + edx.ToString("x8") +
129+
eax.ToString("x8");
130+
proc.StartInfo.UseShellExecute = false;
131+
proc.StartInfo.RedirectStandardOutput = true;
132+
proc.StartInfo.RedirectStandardError = true;
133+
proc.Start();
134+
135+
136+
rawresuld += proc.StandardOutput.ReadToEnd().Replace(Environment.NewLine, "");
137+
rawresuld += proc.StandardError.ReadToEnd();
138+
139+
proc.WaitForExit();
140+
}
141+
142+
return string.IsNullOrEmpty(rawresuld);
143+
}
144+
catch
145+
{
146+
return false;
147+
}
148+
}
149+
150+
public byte ReadIoPort(uint port)
151+
{
152+
throw new NotImplementedException();
153+
}
154+
155+
public void WriteIoPort(uint port, byte value)
156+
{
157+
throw new NotImplementedException();
158+
}
159+
160+
public uint GetPciAddress(byte bus, byte device, byte function)
161+
{
162+
throw new NotImplementedException();
163+
}
164+
165+
public bool ReadPciConfig(uint pciAddress, uint regAddress, out uint value)
166+
{
167+
throw new NotImplementedException();
168+
}
169+
170+
public bool WritePciConfig(uint pciAddress, uint regAddress, uint value)
171+
{
172+
throw new NotImplementedException();
173+
}
174+
175+
public bool WaitPciBusMutex(int millisecondsTimeout)
176+
{
177+
throw new NotImplementedException();
178+
}
179+
180+
public void ReleasePciBusMutex()
181+
{
182+
throw new NotImplementedException();
183+
}
184+
185+
public bool WaitEcMutex(int millisecondsTimeout)
186+
{
187+
throw new NotImplementedException();
188+
}
189+
190+
public void ReleaseEcMutex()
191+
{
192+
throw new NotImplementedException();
193+
}
194+
195+
public bool WaitIsaBusMutex(int millisecondsTimeout)
196+
{
197+
throw new NotImplementedException();
198+
}
199+
200+
public void ReleaseIsaBusMutex()
201+
{
202+
throw new NotImplementedException();
203+
}
204+
205+
public void Close()
206+
{
207+
throw new NotImplementedException();
208+
}
209+
}
210+
}

IPR.Drivers/Ring0/Ring0.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ public class Ring0
77
private static readonly Lazy<IRing0> _Ring0 = new Lazy<IRing0>(() =>
88
{
99
if (Software.OperatingSystem.IsUnix)
10-
throw new NotImplementedException();
11-
return new WinRing0();
10+
return new LinuxRing0();
11+
else
12+
return new WinRing0();
1213
}, LazyThreadSafetyMode.ExecutionAndPublication);
1314
public static IRing0 Instance { get { return _Ring0.Value; } }
1415
}

0 commit comments

Comments
 (0)