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

View file

@ -58,8 +58,8 @@ namespace SampleApp.WinDesktop
if (currentDevice != null) if (currentDevice != null)
{ {
currentDevice.MessageReceived -= device_MessageReceived; currentDevice.MessageReceived -= device_MessageReceived;
if(currentDevice.IsOpen) if (currentDevice.IsOpen)
await currentDevice.CloseAsync(); await currentDevice.CloseAsync();
currentDevice.Dispose(); currentDevice.Dispose();
} }
output.Text = ""; output.Text = "";
@ -69,7 +69,7 @@ namespace SampleApp.WinDesktop
gpgsaView.Message = null; gpgsaView.Message = null;
gpgllView.Message = null; gpgllView.Message = null;
pgrmeView.Message = null; pgrmeView.Message = null;
satView.GsvMessages = null; satView.GsvMessage = null;
//Start new device //Start new device
currentDevice = device; currentDevice = device;
currentDevice.MessageReceived += device_MessageReceived; currentDevice.MessageReceived += device_MessageReceived;
@ -82,8 +82,7 @@ namespace SampleApp.WinDesktop
((NmeaParser.SerialPortDevice)device).Port.PortName, ((NmeaParser.SerialPortDevice)device).Port.PortName,
((NmeaParser.SerialPortDevice)device).Port.BaudRate); ((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) private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
{ {
@ -96,8 +95,7 @@ namespace SampleApp.WinDesktop
if (args.Message is NmeaParser.Nmea.Gsv gpgsv) if (args.Message is NmeaParser.Nmea.Gsv gpgsv)
{ {
gsvMessages[gpgsv.TalkerId] = gpgsv; satView.GsvMessage = gpgsv;
satView.GsvMessages = gsvMessages.Values;
} }
else if (args.Message is NmeaParser.Nmea.Rmc) else if (args.Message is NmeaParser.Nmea.Rmc)
gprmcView.Message = args.Message as 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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SampleApp.WinDesktop" xmlns:local="clr-namespace:SampleApp.WinDesktop"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"> d:DesignHeight="300" d:DesignWidth="300">
<Grid Height="100"> <Grid Height="100">
<Grid > <Grid >
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Path Stroke="Black" StrokeThickness="1" <Path Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4" Grid.RowSpan="4" Grid.ColumnSpan="4"
Stretch="Fill" 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" /> 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> </Grid>
<ItemsControl x:Name="satellites" <ItemsControl x:Name="satellites"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" /> <StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.Resources>
<DataTemplate> <local:SatelliteVechicleColorConverter x:Key="conv" />
<Border Height="{Binding SignalToNoiseRatio}" </ItemsControl.Resources>
Background="CornflowerBlue" <ItemsControl.ItemTemplate>
BorderBrush="Black" <DataTemplate>
Margin="0,0,10,0" Width="20" <StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Left">
BorderThickness="1" <TextBlock Text="{Binding PrnNumber}"
ToolTip="{Binding SignalToNoiseRatio}" FontWeight="Bold"
VerticalAlignment="Bottom"> HorizontalAlignment="Center" >
<TextBlock Text="{Binding PrnNumber}" <TextBlock.Foreground>
Foreground="White" FontWeight="Bold" <SolidColorBrush Color="{Binding Converter={StaticResource conv}}" />
HorizontalAlignment="Center" /> </TextBlock.Foreground>
</Border> </TextBlock>
</DataTemplate> <Border Height="{Binding SignalToNoiseRatio, FallbackValue=10}"
</ItemsControl.ItemTemplate> BorderBrush="Black"
</ItemsControl> Margin="5,0" Width="20"
</Grid> 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> </UserControl>

View file

@ -25,23 +25,22 @@ namespace SampleApp.WinDesktop
InitializeComponent(); InitializeComponent();
} }
public IEnumerable<NmeaParser.Nmea.Gsv> GsvMessages public NmeaParser.Nmea.Gsv GsvMessage
{ {
get { return (IEnumerable<NmeaParser.Nmea.Gsv>)GetValue(GsvMessagesProperty); } get { return (NmeaParser.Nmea.Gsv)GetValue(GsvMessageProperty); }
set { SetValue(GsvMessagesProperty, value); } set { SetValue(GsvMessageProperty, value); }
} }
// Using a DependencyProperty as the backing store for GpgsvMessages. This enables animation, styling, binding, etc... public static readonly DependencyProperty GsvMessageProperty =
public static readonly DependencyProperty GsvMessagesProperty = DependencyProperty.Register(nameof(GsvMessage), typeof(NmeaParser.Nmea.Gsv), typeof(SatelliteSnr), new PropertyMetadata(null, OnGpgsvMessagePropertyChanged));
DependencyProperty.Register("GsvMessages", typeof(IEnumerable<NmeaParser.Nmea.Gsv>), typeof(SatelliteSnr), new PropertyMetadata(null, OnGpgsvMessagesChanged));
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>; var gsv = e.NewValue as NmeaParser.Nmea.Gsv;
if (sats == null) if (gsv == null)
(d as SatelliteSnr).satellites.ItemsSource = null; (d as SatelliteSnr).satellites.ItemsSource = null;
else 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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SampleApp.WinDesktop" xmlns:local="clr-namespace:SampleApp.WinDesktop"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"> d:DesignHeight="300" d:DesignWidth="300">
<Grid> <Grid>
<Grid Opacity=".5" Margin="10"> <Grid Opacity=".5" Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Ellipse Stroke="Black" StrokeThickness="1" <Ellipse Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4" Grid.RowSpan="4" Grid.ColumnSpan="4"
Fill="White" Fill="White"
> >
</Ellipse> </Ellipse>
<Ellipse Stroke="Black" StrokeThickness="1" <Ellipse Stroke="Black" StrokeThickness="1"
Grid.Row="1" Grid.Column="1" Grid.Row="1" Grid.Column="1"
Grid.RowSpan="2" Grid.ColumnSpan="2"> Grid.RowSpan="2" Grid.ColumnSpan="2">
</Ellipse> </Ellipse>
<Path Stroke="Black" StrokeThickness="1" <Path Stroke="Black" StrokeThickness="1"
Grid.RowSpan="4" Grid.ColumnSpan="4" Grid.RowSpan="4" Grid.ColumnSpan="4"
Stretch="Fill" Stretch="Fill"
Data="M0,1 L 2,1 M 1,0 L 1,2" /> Data="M0,1 L 2,1 M 1,0 L 1,2" />
</Grid> </Grid>
<ItemsControl x:Name="satellites" Margin="10" <ItemsControl x:Name="satellites" Margin="10"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel> <ItemsControl.Resources>
<ItemsPanelTemplate> <local:SatelliteVechicleColorConverter x:Key="conv" />
<Grid /> </ItemsControl.Resources>
</ItemsPanelTemplate> <ItemsControl.ItemsPanel>
</ItemsControl.ItemsPanel> <ItemsPanelTemplate>
<ItemsControl.ItemTemplate> <Grid />
<DataTemplate> </ItemsPanelTemplate>
<local:PolarPlacementItem </ItemsControl.ItemsPanel>
Azimuth="{Binding Azimuth}" <ItemsControl.ItemTemplate>
Elevation="{Binding Elevation}" > <DataTemplate>
<Canvas Width="8" Height="8"> <local:PolarPlacementItem
<Ellipse Fill="CornflowerBlue" Azimuth="{Binding Azimuth}"
Width="8" Height="8" > Elevation="{Binding Elevation}" >
<Ellipse.ToolTip> <Canvas Width="8" Height="8">
<StackPanel> <Ellipse Stroke="Black" StrokeThickness="1"
<TextBlock Text="{Binding Azimuth, StringFormat=Azimuth: {0}}" /> Width="8" Height="8" >
<TextBlock Text="{Binding Elevation, StringFormat=Elevation: {0}}" /> <Ellipse.Fill>
<TextBlock Text="{Binding SignalToNoiseRatio, StringFormat=SNR: {0}}" /> <SolidColorBrush Color="{Binding Converter={StaticResource conv}}" />
</StackPanel> </Ellipse.Fill>
</Ellipse.ToolTip> <Ellipse.ToolTip>
</Ellipse> <StackPanel>
<TextBlock Text="{Binding PrnNumber}" Margin="8,-8" /> <TextBlock Text="{Binding Azimuth, StringFormat=Azimuth: {0}}" />
</Canvas> <TextBlock Text="{Binding Elevation, StringFormat=Elevation: {0}}" />
</local:PolarPlacementItem> <TextBlock Text="{Binding SignalToNoiseRatio, StringFormat=SNR: {0}}" />
</DataTemplate> </StackPanel>
</ItemsControl.ItemTemplate> </Ellipse.ToolTip>
</ItemsControl> </Ellipse>
</Grid> <TextBlock Text="{Binding PrnNumber}" Margin="8,-8" />
</Canvas>
</local:PolarPlacementItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl> </UserControl>

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -25,23 +26,23 @@ namespace SampleApp.WinDesktop
InitializeComponent(); InitializeComponent();
} }
public IEnumerable<NmeaParser.Nmea.Gsv> GsvMessages public NmeaParser.Nmea.Gsv GsvMessage
{ {
get { return (IEnumerable<NmeaParser.Nmea.Gsv>)GetValue(GsvMessagesProperty); } get { return (NmeaParser.Nmea.Gsv)GetValue(GsvMessageProperty); }
set { SetValue(GsvMessagesProperty, value); } set { SetValue(GsvMessageProperty, value); }
} }
public static readonly DependencyProperty GsvMessagesProperty = public static readonly DependencyProperty GsvMessageProperty =
DependencyProperty.Register("GsvMessages", typeof(IEnumerable<NmeaParser.Nmea.Gsv>), typeof(SatelliteView), new PropertyMetadata(null, OnGsvMessagesChanged)); 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>; var gsv = e.NewValue as NmeaParser.Nmea.Gsv;
if (sats == null) if (gsv == null)
(d as SatelliteView).satellites.ItemsSource = null; (d as SatelliteView).satellites.ItemsSource = null;
else else
(d as SatelliteView).satellites.ItemsSource = sats.SelectMany(s => s.SVs); (d as SatelliteView).satellites.ItemsSource = gsv.SVs;
} }
} }
public class PolarPlacementItem : ContentControl 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();
}
}
}