Improved satellite view

This commit is contained in:
Morten 2020-01-16 11:58:22 -08:00
parent ca02c614b9
commit ce7aec70cf
6 changed files with 175 additions and 134 deletions

View file

@ -39,7 +39,7 @@
<local:SatelliteView MaxWidth="{Binding ActualHeight, ElementName=satView}"
Grid.Column="1" x:Name="satView" />
<local:SatelliteSnr Grid.Row="1"
GsvMessages="{Binding GsvMessages, ElementName=satView}" />
GsvMessage="{Binding GsvMessage, ElementName=satView}" />
</Grid>
</TabItem>
<TabItem Header="Messages">

View file

@ -58,8 +58,8 @@ namespace SampleApp.WinDesktop
if (currentDevice != null)
{
currentDevice.MessageReceived -= device_MessageReceived;
if(currentDevice.IsOpen)
await currentDevice.CloseAsync();
if (currentDevice.IsOpen)
await currentDevice.CloseAsync();
currentDevice.Dispose();
}
output.Text = "";
@ -69,7 +69,7 @@ namespace SampleApp.WinDesktop
gpgsaView.Message = null;
gpgllView.Message = null;
pgrmeView.Message = null;
satView.GsvMessages = null;
satView.GsvMessage = null;
//Start new device
currentDevice = device;
currentDevice.MessageReceived += device_MessageReceived;
@ -82,8 +82,7 @@ namespace SampleApp.WinDesktop
((NmeaParser.SerialPortDevice)device).Port.PortName,
((NmeaParser.SerialPortDevice)device).Port.BaudRate);
}
}
Dictionary<NmeaParser.Nmea.Talker, NmeaParser.Nmea.Gsv> gsvMessages = new Dictionary<NmeaParser.Nmea.Talker, NmeaParser.Nmea.Gsv>();
}
private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
{
@ -96,8 +95,7 @@ namespace SampleApp.WinDesktop
if (args.Message is NmeaParser.Nmea.Gsv gpgsv)
{
gsvMessages[gpgsv.TalkerId] = gpgsv;
satView.GsvMessages = gsvMessages.Values;
satView.GsvMessage = gpgsv;
}
else if (args.Message is NmeaParser.Nmea.Rmc)
gprmcView.Message = args.Message as NmeaParser.Nmea.Rmc;

View file

@ -3,53 +3,64 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SampleApp.WinDesktop"
xmlns:local="clr-namespace:SampleApp.WinDesktop"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Height="100">
<Grid Height="100">
<Grid >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Path Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4"
Stretch="Fill"
Data="M0,0 L 1,0 M 0,1 L 1,1 M 0,2 L 1,2 M 0,3 L 1,3 M 0,4 L 1,4" />
</Grid>
<ItemsControl x:Name="satellites"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Height="{Binding SignalToNoiseRatio}"
Background="CornflowerBlue"
BorderBrush="Black"
Margin="0,0,10,0" Width="20"
BorderThickness="1"
ToolTip="{Binding SignalToNoiseRatio}"
VerticalAlignment="Bottom">
<TextBlock Text="{Binding PrnNumber}"
Foreground="White" FontWeight="Bold"
HorizontalAlignment="Center" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<Path Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4"
Stretch="Fill"
Data="M0,0 L 1,0 M 0,1 L 1,1 M 0,2 L 1,2 M 0,3 L 1,3 M 0,4 L 1,4" />
</Grid>
<ItemsControl x:Name="satellites"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Resources>
<local:SatelliteVechicleColorConverter x:Key="conv" />
</ItemsControl.Resources>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Left">
<TextBlock Text="{Binding PrnNumber}"
FontWeight="Bold"
HorizontalAlignment="Center" >
<TextBlock.Foreground>
<SolidColorBrush Color="{Binding Converter={StaticResource conv}}" />
</TextBlock.Foreground>
</TextBlock>
<Border Height="{Binding SignalToNoiseRatio, FallbackValue=10}"
BorderBrush="Black"
Margin="5,0" Width="20"
BorderThickness="1"
ToolTip="{Binding SignalToNoiseRatio}"
VerticalAlignment="Bottom">
<Border.Background>
<SolidColorBrush Color="{Binding Converter={StaticResource conv}}" />
</Border.Background>
</Border>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>

View file

@ -25,23 +25,22 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
public IEnumerable<NmeaParser.Nmea.Gsv> GsvMessages
public NmeaParser.Nmea.Gsv GsvMessage
{
get { return (IEnumerable<NmeaParser.Nmea.Gsv>)GetValue(GsvMessagesProperty); }
set { SetValue(GsvMessagesProperty, value); }
get { return (NmeaParser.Nmea.Gsv)GetValue(GsvMessageProperty); }
set { SetValue(GsvMessageProperty, value); }
}
// Using a DependencyProperty as the backing store for GpgsvMessages. This enables animation, styling, binding, etc...
public static readonly DependencyProperty GsvMessagesProperty =
DependencyProperty.Register("GsvMessages", typeof(IEnumerable<NmeaParser.Nmea.Gsv>), typeof(SatelliteSnr), new PropertyMetadata(null, OnGpgsvMessagesChanged));
public static readonly DependencyProperty GsvMessageProperty =
DependencyProperty.Register(nameof(GsvMessage), typeof(NmeaParser.Nmea.Gsv), typeof(SatelliteSnr), new PropertyMetadata(null, OnGpgsvMessagePropertyChanged));
private static void OnGpgsvMessagesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnGpgsvMessagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var sats = e.NewValue as IEnumerable<NmeaParser.Nmea.Gsv>;
if (sats == null)
var gsv = e.NewValue as NmeaParser.Nmea.Gsv;
if (gsv == null)
(d as SatelliteSnr).satellites.ItemsSource = null;
else
(d as SatelliteSnr).satellites.ItemsSource = sats.SelectMany(s => s.SVs);
(d as SatelliteSnr).satellites.ItemsSource = gsv.SVs;
}
}
}

View file

@ -3,70 +3,76 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SampleApp.WinDesktop"
xmlns:local="clr-namespace:SampleApp.WinDesktop"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid Opacity=".5" Margin="10">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Ellipse Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4"
Fill="White"
>
</Ellipse>
<Ellipse Stroke="Black" StrokeThickness="1"
Grid.Row="1" Grid.Column="1"
Grid.RowSpan="2" Grid.ColumnSpan="2">
<Grid Opacity=".5" Margin="10">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Ellipse Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4"
Fill="White"
>
</Ellipse>
<Ellipse Stroke="Black" StrokeThickness="1"
Grid.Row="1" Grid.Column="1"
Grid.RowSpan="2" Grid.ColumnSpan="2">
</Ellipse>
</Ellipse>
<Path Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4"
Stretch="Fill"
Data="M0,1 L 2,1 M 1,0 L 1,2" />
</Grid>
<ItemsControl x:Name="satellites" Margin="10"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:PolarPlacementItem
Azimuth="{Binding Azimuth}"
Elevation="{Binding Elevation}" >
<Canvas Width="8" Height="8">
<Ellipse Fill="CornflowerBlue"
Width="8" Height="8" >
<Ellipse.ToolTip>
<StackPanel>
<TextBlock Text="{Binding Azimuth, StringFormat=Azimuth: {0}}" />
<TextBlock Text="{Binding Elevation, StringFormat=Elevation: {0}}" />
<TextBlock Text="{Binding SignalToNoiseRatio, StringFormat=SNR: {0}}" />
</StackPanel>
</Ellipse.ToolTip>
</Ellipse>
<TextBlock Text="{Binding PrnNumber}" Margin="8,-8" />
</Canvas>
</local:PolarPlacementItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
<Path Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4"
Stretch="Fill"
Data="M0,1 L 2,1 M 1,0 L 1,2" />
</Grid>
<ItemsControl x:Name="satellites" Margin="10"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ItemsControl.Resources>
<local:SatelliteVechicleColorConverter x:Key="conv" />
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:PolarPlacementItem
Azimuth="{Binding Azimuth}"
Elevation="{Binding Elevation}" >
<Canvas Width="8" Height="8">
<Ellipse Stroke="Black" StrokeThickness="1"
Width="8" Height="8" >
<Ellipse.Fill>
<SolidColorBrush Color="{Binding Converter={StaticResource conv}}" />
</Ellipse.Fill>
<Ellipse.ToolTip>
<StackPanel>
<TextBlock Text="{Binding Azimuth, StringFormat=Azimuth: {0}}" />
<TextBlock Text="{Binding Elevation, StringFormat=Elevation: {0}}" />
<TextBlock Text="{Binding SignalToNoiseRatio, StringFormat=SNR: {0}}" />
</StackPanel>
</Ellipse.ToolTip>
</Ellipse>
<TextBlock Text="{Binding PrnNumber}" Margin="8,-8" />
</Canvas>
</local:PolarPlacementItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -25,23 +26,23 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
public IEnumerable<NmeaParser.Nmea.Gsv> GsvMessages
public NmeaParser.Nmea.Gsv GsvMessage
{
get { return (IEnumerable<NmeaParser.Nmea.Gsv>)GetValue(GsvMessagesProperty); }
set { SetValue(GsvMessagesProperty, value); }
get { return (NmeaParser.Nmea.Gsv)GetValue(GsvMessageProperty); }
set { SetValue(GsvMessageProperty, value); }
}
public static readonly DependencyProperty GsvMessagesProperty =
DependencyProperty.Register("GsvMessages", typeof(IEnumerable<NmeaParser.Nmea.Gsv>), typeof(SatelliteView), new PropertyMetadata(null, OnGsvMessagesChanged));
public static readonly DependencyProperty GsvMessageProperty =
DependencyProperty.Register(nameof(GsvMessage), typeof(NmeaParser.Nmea.Gsv), typeof(SatelliteView), new PropertyMetadata(null, OnGsvMessagePropertyChanged));
private static void OnGsvMessagesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnGsvMessagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var sats = e.NewValue as IEnumerable<NmeaParser.Nmea.Gsv>;
if (sats == null)
var gsv = e.NewValue as NmeaParser.Nmea.Gsv;
if (gsv == null)
(d as SatelliteView).satellites.ItemsSource = null;
else
(d as SatelliteView).satellites.ItemsSource = sats.SelectMany(s => s.SVs);
}
(d as SatelliteView).satellites.ItemsSource = gsv.SVs;
}
}
public class PolarPlacementItem : ContentControl
{
@ -91,4 +92,30 @@ namespace SampleApp.WinDesktop
}
}
}
public class SatelliteVechicleColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is NmeaParser.Nmea.SatelliteVehicle sv)
{
byte alpha = (byte)(sv.SignalToNoiseRatio <= 0 ? 80 : 255);
switch (sv.TalkerId)
{
case NmeaParser.Nmea.Talker.GlobalPositioningSystem: return Color.FromArgb(alpha, 255, 0, 0);
case NmeaParser.Nmea.Talker.GalileoPositioningSystem: return Color.FromArgb(alpha, 0, 255, 0);
case NmeaParser.Nmea.Talker.GlonassReceiver: return Color.FromArgb(255, 0, 0, alpha);
case NmeaParser.Nmea.Talker.GlobalNavigationSatelliteSystem: return Color.FromArgb(alpha, 0, 0, 0);
default: return Colors.CornflowerBlue;
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}