Skip to content

Commit 12caaea

Browse files
committed
Signal strength diagramm added
1 parent 2c82385 commit 12caaea

5 files changed

Lines changed: 125 additions & 11 deletions

File tree

‎Source/NETworkManager/Resources/Localization/Strings.Designer.cs‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Source/NETworkManager/Resources/Localization/Strings.resx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,4 +2367,7 @@ $$hostname$$ --&gt; Hostname</value>
23672367
<data name="NoWiFiNetworksFound" xml:space="preserve">
23682368
<value>No WiFi networks found!</value>
23692369
</data>
2370+
<data name="Channels" xml:space="preserve">
2371+
<value>Channels</value>
2372+
</data>
23702373
</root>

‎Source/NETworkManager/ViewModels/WiFiViewModel.cs‎

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NETworkManager.Models.Network;
1+
using LiveCharts;
2+
using LiveCharts.Wpf;
3+
using NETworkManager.Models.Network;
24
using NETworkManager.Models.Settings;
35
using NETworkManager.Utilities;
46
using System;
@@ -111,6 +113,13 @@ public WiFiNetworkInfo SelectedNetwork
111113
OnPropertyChanged();
112114
}
113115
}
116+
117+
public SeriesCollection Radio1Series { get; set; } = new SeriesCollection();
118+
public string[] Radio1Labels { get; set; } = new string[] { " ", " ", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", " ", " " };
119+
public SeriesCollection Radio2Series { get; set; } = new SeriesCollection();
120+
public string[] Radio2Labels { get; set; }
121+
public Func<double, string> FormatterdBm { get; set; } = value => $"- {value} dBm";
122+
114123
#endregion
115124

116125
#region Constructor, load settings
@@ -128,6 +137,43 @@ public WiFiViewModel()
128137
_isLoading = false;
129138
}
130139

140+
private ChartValues<double> GetDefaultValues()
141+
{
142+
ChartValues<double> values = new ChartValues<double>();
143+
144+
for (int i = 0; i < 17; i++)
145+
values.Add(-1);
146+
147+
return values;
148+
}
149+
150+
private void AddNetworkToRadio1Chart(WiFiNetworkInfo network)
151+
{
152+
int channel = WiFi.GetChannelFromChannelFrequency(network.ChannelCenterFrequencyInKilohertz);
153+
154+
int index = channel + 1;
155+
156+
ChartValues<double> values = GetDefaultValues();
157+
158+
values[index - 2] = 0;
159+
values[index - 1] = network.NetworkRssiInDecibelMilliwatts / 2 * -1;
160+
values[index] = network.NetworkRssiInDecibelMilliwatts * -1;
161+
values[index + 1] = network.NetworkRssiInDecibelMilliwatts / 2 * -1;
162+
values[index + 2] = 0;
163+
164+
Radio1Series.Add(new LineSeries
165+
{
166+
Title = network.SSID,
167+
Values = values,
168+
PointGeometry = null
169+
});
170+
}
171+
172+
private void AddNetworkToRadio2Chart(WiFiNetworkInfo network)
173+
{
174+
175+
}
176+
131177
private void LoadSettings()
132178
{
133179

@@ -147,7 +193,7 @@ private void ReloadAdapterAction()
147193
public ICommand ScanNetworksCommand => new RelayCommand(p => ScanNetworksAction(), ScanNetworks_CanExecute);
148194

149195
private bool ScanNetworks_CanExecute(object obj) => !IsNetworksLoading;
150-
196+
151197

152198
private void ScanNetworksAction()
153199
{
@@ -200,18 +246,22 @@ private async void ScanNetworks(WiFiAdapter adapter)
200246
{
201247
IsNetworksLoading = true;
202248

203-
try
204-
{
205-
Networks.Clear();
249+
Networks.Clear();
206250

207-
IEnumerable<WiFiNetworkInfo> networks = await WiFi.GetNetworksAsync(adapter);
251+
Radio1Series.Clear();
252+
Radio2Series.Clear();
208253

209-
foreach (var network in networks)
210-
Networks.Add(network);
211-
}
212-
catch (Exception ex)
254+
IEnumerable<WiFiNetworkInfo> networks = await WiFi.GetNetworksAsync(adapter);
255+
256+
foreach (var network in networks)
213257
{
214-
MessageBox.Show("Error...", ex.Message);
258+
Networks.Add(network);
259+
260+
if (WiFi.ConvertChannelFrequencyToGigahertz(network.ChannelCenterFrequencyInKilohertz) < 5) // 2.4 GHz
261+
AddNetworkToRadio1Chart(network);
262+
else
263+
AddNetworkToRadio2Chart(network);
264+
215265
}
216266

217267
IsNetworksLoading = false;

‎Source/NETworkManager/Views/NetworkInterfaceView.xaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@
373373
</TextBlock.Style>
374374
</TextBlock>
375375
<liveChart:CartesianChart Grid.Row="2" Series="{Binding Series}" Margin="0,0,0,20">
376+
<liveChart:CartesianChart.DataTooltip>
377+
<liveChart:DefaultTooltip Background="Transparent" />
378+
</liveChart:CartesianChart.DataTooltip>
376379
<liveChart:CartesianChart.AxisX>
377380
<liveChart:Axis LabelFormatter="{Binding FormatterDate}">
378381
<liveChart:Axis.Separator>

‎Source/NETworkManager/Views/WiFiView.xaml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1010
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
1111
xmlns:mahAppsControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
12+
xmlns:liveChart="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
1213
xmlns:loadingIndicators="clr-namespace:LoadingIndicators.WPF;assembly=LoadingIndicators.WPF"
1314
mc:Ignorable="d"
1415
d:DataContext="{d:DesignInstance viewModels:WiFiViewModel}">
@@ -375,5 +376,53 @@
375376
</StackPanel>
376377
</Grid>
377378
</TabItem>
379+
<TabItem Header="{x:Static localization:Strings.Channels}">
380+
<Grid Margin="10">
381+
<Grid.RowDefinitions>
382+
<RowDefinition Height="Auto" />
383+
<RowDefinition Height="*" />
384+
<RowDefinition Height="20" />
385+
<RowDefinition Height="Auto" />
386+
<RowDefinition Height="*" />
387+
</Grid.RowDefinitions>
388+
<TextBlock Grid.Row="0" Text="2.4 GHz" Style="{StaticResource HeaderTextBlock}" />
389+
<liveChart:CartesianChart Grid.Row="1" Series="{Binding Radio1Series}" >
390+
<liveChart:CartesianChart.DataTooltip>
391+
<liveChart:DefaultTooltip SelectionMode="OnlySender" Background="Transparent" />
392+
</liveChart:CartesianChart.DataTooltip>
393+
<liveChart:CartesianChart.AxisX>
394+
<liveChart:Axis Title="Channel" Labels="{Binding Radio1Labels}">
395+
<liveChart:Axis.Separator>
396+
<liveChart:Separator Step="1" StrokeThickness="0" />
397+
</liveChart:Axis.Separator>
398+
</liveChart:Axis>
399+
</liveChart:CartesianChart.AxisX>
400+
<liveChart:CartesianChart.AxisY>
401+
<liveChart:Axis Title="Signal strength" MinValue="0" LabelFormatter="{Binding FormatterdBm}">
402+
<liveChart:Axis.Separator>
403+
<liveChart:Separator StrokeThickness="1" Stroke="{DynamicResource GrayBrush8}" StrokeDashArray="10" />
404+
</liveChart:Axis.Separator>
405+
</liveChart:Axis>
406+
</liveChart:CartesianChart.AxisY>
407+
</liveChart:CartesianChart>
408+
<TextBlock Grid.Row="3" Text="5 GHz" Style="{StaticResource HeaderTextBlock}" />
409+
<!--<liveChart:CartesianChart Grid.Row="4" Series="{Binding Radio1Series}">
410+
<liveChart:CartesianChart.AxisX>
411+
<liveChart:Axis Title="Channel" Labels="{Binding Radio1Labels}">
412+
<liveChart:Axis.Separator>
413+
<liveChart:Separator Step="1" StrokeThickness="0" />
414+
</liveChart:Axis.Separator>
415+
</liveChart:Axis>
416+
</liveChart:CartesianChart.AxisX>
417+
<liveChart:CartesianChart.AxisY>
418+
<liveChart:Axis Title="Signal strength" MinValue="0" LabelFormatter="{Binding FormatterdBm}">
419+
<liveChart:Axis.Separator>
420+
<liveChart:Separator StrokeThickness="1" Stroke="{DynamicResource GrayBrush8}" StrokeDashArray="10" />
421+
</liveChart:Axis.Separator>
422+
</liveChart:Axis>
423+
</liveChart:CartesianChart.AxisY>
424+
</liveChart:CartesianChart>-->
425+
</Grid>
426+
</TabItem>
378427
</TabControl>
379428
</UserControl>

0 commit comments

Comments
 (0)