From daa6cedd0520cf61f653de3a19f5a4004cc6935d Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Tue, 28 Jul 2020 19:46:50 -0700 Subject: [PATCH] Better handle display multiple systems for GSV --- src/SampleApp.WinDesktop/MainWindow.xaml | 3 +- src/SampleApp.WinDesktop/MainWindow.xaml.cs | 6 ++-- src/SampleApp.WinDesktop/SatelliteSnr.xaml | 2 +- src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs | 28 +++++++++---------- .../SatelliteView.xaml.cs | 27 +++++++++--------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml b/src/SampleApp.WinDesktop/MainWindow.xaml index 8fdc921..d693e8f 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml +++ b/src/SampleApp.WinDesktop/MainWindow.xaml @@ -39,8 +39,7 @@ - + diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml.cs b/src/SampleApp.WinDesktop/MainWindow.xaml.cs index 3abce34..84aa06c 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml.cs +++ b/src/SampleApp.WinDesktop/MainWindow.xaml.cs @@ -61,7 +61,8 @@ namespace SampleApp.WinDesktop gpgsaView.Message = null; gpgllView.Message = null; pgrmeView.Message = null; - satView.GsvMessage = null; + satView.ClearGsv(); + satSnr.ClearGsv(); //Start new device currentDevice = device; currentDevice.MessageReceived += device_MessageReceived; @@ -89,7 +90,8 @@ namespace SampleApp.WinDesktop if (args.Message is NmeaParser.Messages.Gsv gpgsv) { - satView.GsvMessage = gpgsv; + satView.SetGsv(gpgsv); + satSnr.SetGsv(gpgsv); } else if (args.Message is NmeaParser.Messages.Rmc) gprmcView.Message = args.Message as NmeaParser.Messages.Rmc; diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml b/src/SampleApp.WinDesktop/SatelliteSnr.xaml index 7eaf2dd..410b701 100644 --- a/src/SampleApp.WinDesktop/SatelliteSnr.xaml +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml @@ -48,7 +48,7 @@ - messages = new Dictionary(); + public void SetGsv(Gsv message) { - get { return (NmeaParser.Messages.Gsv)GetValue(GsvMessageProperty); } - set { SetValue(GsvMessageProperty, value); } + messages[message.TalkerId] = message; + UpdateSatellites(); + } + public void ClearGsv() + { + messages.Clear(); + UpdateSatellites(); } - public static readonly DependencyProperty GsvMessageProperty = - DependencyProperty.Register(nameof(GsvMessage), typeof(NmeaParser.Messages.Gsv), typeof(SatelliteSnr), new PropertyMetadata(null, OnGpgsvMessagePropertyChanged)); - - private static void OnGpgsvMessagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private void UpdateSatellites() { - var gsv = e.NewValue as NmeaParser.Messages.Gsv; - if (gsv == null) - (d as SatelliteSnr).satellites.ItemsSource = null; - else - (d as SatelliteSnr).satellites.ItemsSource = gsv.SVs; + satellites.ItemsSource = messages.Values.SelectMany(g => g.SVs); } } } diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs index 487d472..c4351df 100644 --- a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs +++ b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs @@ -27,23 +27,21 @@ namespace SampleApp.WinDesktop { InitializeComponent(); } - - public Gsv GsvMessage + Dictionary messages = new Dictionary(); + public void SetGsv(Gsv message) { - get { return (Gsv)GetValue(GsvMessageProperty); } - set { SetValue(GsvMessageProperty, value); } + messages[message.TalkerId] = message; + UpdateSatellites(); + } + public void ClearGsv() + { + messages.Clear(); + UpdateSatellites(); } - public static readonly DependencyProperty GsvMessageProperty = - DependencyProperty.Register(nameof(GsvMessage), typeof(Gsv), typeof(SatelliteView), new PropertyMetadata(null, OnGsvMessagePropertyChanged)); - - private static void OnGsvMessagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private void UpdateSatellites() { - var gsv = e.NewValue as Gsv; - if (gsv == null) - (d as SatelliteView).satellites.ItemsSource = null; - else - (d as SatelliteView).satellites.ItemsSource = gsv.SVs; + satellites.ItemsSource = messages.Values.SelectMany(g => g.SVs); } } public class PolarPlacementItem : ContentControl @@ -107,7 +105,8 @@ namespace SampleApp.WinDesktop { case Talker.GlobalPositioningSystem: return Color.FromArgb(alpha, 255, 0, 0); case Talker.GalileoPositioningSystem: return Color.FromArgb(alpha, 0, 255, 0); - case Talker.GlonassReceiver: return Color.FromArgb(255, 0, 0, alpha); + case Talker.GlonassReceiver: return Color.FromArgb(alpha, 0, 0, 255); + case Talker.BeiDouNavigationSatelliteSystem : return Color.FromArgb(alpha, 0, 255, 255); case Talker.GlobalNavigationSatelliteSystem: return Color.FromArgb(alpha, 0, 0, 0); default: return Colors.CornflowerBlue; }