diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml b/src/SampleApp.WinDesktop/MainWindow.xaml index 6b98303..7e5f61d 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml +++ b/src/SampleApp.WinDesktop/MainWindow.xaml @@ -39,7 +39,7 @@ + GsvMessage="{Binding GsvMessage, ElementName=satView}" /> diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml.cs b/src/SampleApp.WinDesktop/MainWindow.xaml.cs index 126ffdb..352f5fb 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml.cs +++ b/src/SampleApp.WinDesktop/MainWindow.xaml.cs @@ -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 gsvMessages = new Dictionary(); + } 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; diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml b/src/SampleApp.WinDesktop/SatelliteSnr.xaml index 68bccbb..011c26d 100644 --- a/src/SampleApp.WinDesktop/SatelliteSnr.xaml +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml @@ -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"> - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs b/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs index 4e1b9bd..a241b46 100644 --- a/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs @@ -25,23 +25,22 @@ namespace SampleApp.WinDesktop InitializeComponent(); } - public IEnumerable GsvMessages + public NmeaParser.Nmea.Gsv GsvMessage { - get { return (IEnumerable)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), 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; - 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; } } } diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml b/src/SampleApp.WinDesktop/SatelliteView.xaml index 01446e5..66e0748 100644 --- a/src/SampleApp.WinDesktop/SatelliteView.xaml +++ b/src/SampleApp.WinDesktop/SatelliteView.xaml @@ -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"> - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs index efc4767..9b1705c 100644 --- a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs +++ b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs @@ -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 GsvMessages + public NmeaParser.Nmea.Gsv GsvMessage { - get { return (IEnumerable)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), 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; - 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(); + } + } +} \ No newline at end of file