From 4bbd7fa54cab262c5108dc9482de7190938cdd68 Mon Sep 17 00:00:00 2001 From: mort5161 Date: Mon, 28 Jul 2014 16:38:45 -0700 Subject: [PATCH] Added satellite view to desktop sample --- src/SampleApp.WinDesktop/MainWindow.xaml | 36 ++++++- src/SampleApp.WinDesktop/MainWindow.xaml.cs | 17 +++- .../SampleApp.WinDesktop.csproj | 14 +++ src/SampleApp.WinDesktop/SatelliteSnr.xaml | 54 +++++++++++ src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs | 49 ++++++++++ src/SampleApp.WinDesktop/SatelliteView.xaml | 72 ++++++++++++++ .../SatelliteView.xaml.cs | 97 +++++++++++++++++++ 7 files changed, 335 insertions(+), 4 deletions(-) create mode 100644 src/SampleApp.WinDesktop/SatelliteSnr.xaml create mode 100644 src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs create mode 100644 src/SampleApp.WinDesktop/SatelliteView.xaml create mode 100644 src/SampleApp.WinDesktop/SatelliteView.xaml.cs diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml b/src/SampleApp.WinDesktop/MainWindow.xaml index c0b6ab6..78f3dd1 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml +++ b/src/SampleApp.WinDesktop/MainWindow.xaml @@ -1,10 +1,40 @@  - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml.cs b/src/SampleApp.WinDesktop/MainWindow.xaml.cs index 83e99f1..0fbcc95 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml.cs +++ b/src/SampleApp.WinDesktop/MainWindow.xaml.cs @@ -25,14 +25,29 @@ namespace SampleApp.WinDesktop InitializeComponent(); var device = new NmeaParser.NmeaFileDevice("NmeaSampleData.txt"); device.MessageReceived += device_MessageReceived; - device.OpenAsync(); + var _ = device.OpenAsync(); } + Dictionary gpgsvList = new Dictionary(); private void device_MessageReceived(NmeaParser.NmeaDevice sender, NmeaParser.Nmea.NmeaMessage args) { Dispatcher.BeginInvoke((Action) delegate() { output.Text += args.MessageType + ": " + args.ToString() + '\n'; + output.Select(output.Text.Length - 1, 0); //scroll to bottom + + //Merge all gpgsv satellite messages + if(args is NmeaParser.Nmea.Gps.Gpgsv) + { + var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args; + if(gpgsv.MessageNumber == 1) + { + gpgsvList = new Dictionary(); //first one. Replace list + } + gpgsvList[gpgsv.MessageNumber] = gpgsv; + if(gpgsv.MessageNumber == gpgsv.TotalMessages) + satView.GpgsvMessages = gpgsvList.Values; + } }); } } diff --git a/src/SampleApp.WinDesktop/SampleApp.WinDesktop.csproj b/src/SampleApp.WinDesktop/SampleApp.WinDesktop.csproj index 46e6987..eca9dce 100644 --- a/src/SampleApp.WinDesktop/SampleApp.WinDesktop.csproj +++ b/src/SampleApp.WinDesktop/SampleApp.WinDesktop.csproj @@ -53,6 +53,12 @@ MSBuild:Compile Designer + + SatelliteSnr.xaml + + + SatelliteView.xaml + MSBuild:Compile Designer @@ -65,6 +71,14 @@ MainWindow.xaml Code + + MSBuild:Compile + Designer + + + Designer + MSBuild:Compile + diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml b/src/SampleApp.WinDesktop/SatelliteSnr.xaml new file mode 100644 index 0000000..6e83f33 --- /dev/null +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs b/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs new file mode 100644 index 0000000..7ae600b --- /dev/null +++ b/src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SampleApp.WinDesktop +{ + /// + /// Interaction logic for SatelliteView.xaml + /// + public partial class SatelliteSnr : UserControl + { + public SatelliteSnr() + { + InitializeComponent(); + } + + + + public IEnumerable GpgsvMessages + { + get { return (IEnumerable)GetValue(GpgsvMessagesProperty); } + set { SetValue(GpgsvMessagesProperty, value); } + } + + // Using a DependencyProperty as the backing store for GpgsvMessages. This enables animation, styling, binding, etc... + public static readonly DependencyProperty GpgsvMessagesProperty = + DependencyProperty.Register("GpgsvMessages", typeof(IEnumerable), typeof(SatelliteSnr), new PropertyMetadata(null, OnGpgsvMessagesChanged)); + + private static void OnGpgsvMessagesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var sats = e.NewValue as IEnumerable; + if (sats == null) + (d as SatelliteSnr).satellites.ItemsSource = null; + else + (d as SatelliteSnr).satellites.ItemsSource = sats.SelectMany(s => s.SVs); + } + } +} diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml b/src/SampleApp.WinDesktop/SatelliteView.xaml new file mode 100644 index 0000000..a2a95cb --- /dev/null +++ b/src/SampleApp.WinDesktop/SatelliteView.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs new file mode 100644 index 0000000..afe5c41 --- /dev/null +++ b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SampleApp.WinDesktop +{ + /// + /// Interaction logic for SatelliteView.xaml + /// + public partial class SatelliteView : UserControl + { + public SatelliteView() + { + InitializeComponent(); + } + + + + public IEnumerable GpgsvMessages + { + get { return (IEnumerable)GetValue(GpgsvMessagesProperty); } + set { SetValue(GpgsvMessagesProperty, value); } + } + + // Using a DependencyProperty as the backing store for GpgsvMessages. This enables animation, styling, binding, etc... + public static readonly DependencyProperty GpgsvMessagesProperty = + DependencyProperty.Register("GpgsvMessages", typeof(IEnumerable), typeof(SatelliteView), new PropertyMetadata(null, OnGpgsvMessagesChanged)); + + private static void OnGpgsvMessagesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var sats = e.NewValue as IEnumerable; + if (sats == null) + (d as SatelliteView).satellites.ItemsSource = null; + else + (d as SatelliteView).satellites.ItemsSource = sats.SelectMany(s => s.SVs); + } + } + public class PolarPlacementItem : ContentControl + { + public PolarPlacementItem() + { + HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; + VerticalAlignment = System.Windows.VerticalAlignment.Stretch; + } + protected override Size ArrangeOverride(Size arrangeBounds) + { + double az = (Azimuth - 90) / 180 * Math.PI; + double e = (90 - Elevation) / 90; + double X = Math.Cos(az) * e; + double Y = Math.Sin(az) * e; + X = arrangeBounds.Width * .5 * X; + Y = arrangeBounds.Height * .5 * Y; + RenderTransform = new TranslateTransform(X, Y); + return base.ArrangeOverride(arrangeBounds); + } + + public double Azimuth + { + get { return (double)GetValue(AzimuthProperty); } + set { SetValue(AzimuthProperty, value); } + } + + public static readonly DependencyProperty AzimuthProperty = + DependencyProperty.Register("Azimuth", typeof(double), typeof(PolarPlacementItem), new PropertyMetadata(0d, OnAzimuthPropertyChanged)); + + private static void OnAzimuthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as PolarPlacementItem).InvalidateArrange(); + } + + public double Elevation + { + get { return (double)GetValue(ElevationProperty); } + set { SetValue(ElevationProperty, value); } + } + + public static readonly DependencyProperty ElevationProperty = + DependencyProperty.Register("Elevation", typeof(double), typeof(PolarPlacementItem), new PropertyMetadata(0d, OnElevationPropertyChanged)); + + private static void OnElevationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as PolarPlacementItem).InvalidateArrange(); + } + + } +}