diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml.cs b/src/SampleApp.WinDesktop/MainWindow.xaml.cs index ebf88ba..b4da0e6 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml.cs +++ b/src/SampleApp.WinDesktop/MainWindow.xaml.cs @@ -16,6 +16,7 @@ namespace SampleApp.WinDesktop { private Queue messages = new Queue(101); public static NmeaParser.NmeaDevice currentDevice; + public static GnssMonitor monitor; //Dialog for browsing to nmea log files private Microsoft.Win32.OpenFileDialog nmeaOpenFileDialog = new Microsoft.Win32.OpenFileDialog() @@ -58,7 +59,7 @@ namespace SampleApp.WinDesktop if (gnssMonitorView.Monitor != null) { gnssMonitorView.Monitor.LocationChanged -= Monitor_LocationChanged; - gnssMonitorView.Monitor = null; + gnssMonitorView.Monitor = monitor = null; } mapplot.Clear(); } @@ -78,8 +79,6 @@ namespace SampleApp.WinDesktop MessagePanel.Children.Remove(child); } currentDevice.MessageReceived += device_MessageReceived; - view2d.NmeaDevice = device; - view3d.NmeaDevice = device; if (device is NmeaParser.NmeaFileDevice) currentDeviceInfo.Text = string.Format("NmeaFileDevice( file={0} )", ((NmeaParser.NmeaFileDevice)device).FileName); @@ -90,8 +89,10 @@ namespace SampleApp.WinDesktop ((NmeaParser.SerialPortDevice)device).Port.BaudRate); } await device.OpenAsync(); - gnssMonitorView.Monitor = new GnssMonitor(device); + gnssMonitorView.Monitor = monitor = new GnssMonitor(device); gnssMonitorView.Monitor.LocationChanged += Monitor_LocationChanged; + view2d.GnssMonitor = monitor; + view3d.GnssMonitor = monitor; } private void Monitor_LocationChanged(object sender, EventArgs e) diff --git a/src/SampleApp.WinDesktop/NmeaLocationDataSource.cs b/src/SampleApp.WinDesktop/NmeaLocationDataSource.cs index 3422b8d..bb42e57 100644 --- a/src/SampleApp.WinDesktop/NmeaLocationDataSource.cs +++ b/src/SampleApp.WinDesktop/NmeaLocationDataSource.cs @@ -31,7 +31,7 @@ namespace SampleApp.WinDesktop /// /// The NMEA device to monitor /// Whether starting this datasource also controls the underlying NMEA device - public NmeaLocationDataSource(NmeaParser.NmeaDevice device, bool startStopDevice = true) : this(new GnssMonitor(device), startStopDevice) + public NmeaLocationDataSource(NmeaParser.NmeaDevice device, bool startStopDevice = true) : this(MainWindow.monitor, startStopDevice) { } diff --git a/src/SampleApp.WinDesktop/View2D.xaml.cs b/src/SampleApp.WinDesktop/View2D.xaml.cs index ab4a152..eb14d2c 100644 --- a/src/SampleApp.WinDesktop/View2D.xaml.cs +++ b/src/SampleApp.WinDesktop/View2D.xaml.cs @@ -37,22 +37,22 @@ namespace SampleApp.WinDesktop mapView.LocationDisplay.IsEnabled = IsVisible; } - public NmeaDevice NmeaDevice + public NmeaParser.Gnss.GnssMonitor GnssMonitor { - get { return (NmeaDevice)GetValue(NmeaDeviceProperty); } - set { SetValue(NmeaDeviceProperty, value); } + get { return (NmeaParser.Gnss.GnssMonitor)GetValue(GnssMonitorProperty); } + set { SetValue(GnssMonitorProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... - public static readonly DependencyProperty NmeaDeviceProperty = - DependencyProperty.Register(nameof(NmeaDevice), typeof(NmeaDevice), typeof(View2D), new PropertyMetadata(null, OnNmeaDevicePropertyChanged)); + public static readonly DependencyProperty GnssMonitorProperty = + DependencyProperty.Register(nameof(GnssMonitor), typeof(NmeaParser.Gnss.GnssMonitor), typeof(View2D), new PropertyMetadata(null, OnGnssMonitorPropertyChanged)); - private static void OnNmeaDevicePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnGnssMonitorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - ((View2D)d).InitNmeaProvider(e.OldValue as NmeaDevice, e.NewValue as NmeaDevice); + ((View2D)d).InitNmeaProvider(e.OldValue as NmeaParser.Gnss.GnssMonitor, e.NewValue as NmeaParser.Gnss.GnssMonitor); } - private void InitNmeaProvider(NmeaDevice oldDevice, NmeaDevice newDevice) + private void InitNmeaProvider(NmeaParser.Gnss.GnssMonitor oldDevice, NmeaParser.Gnss.GnssMonitor newDevice) { mapView.LocationDisplay.IsEnabled = false; if (newDevice != null) diff --git a/src/SampleApp.WinDesktop/View3D.xaml.cs b/src/SampleApp.WinDesktop/View3D.xaml.cs index 2e21fec..36fdccd 100644 --- a/src/SampleApp.WinDesktop/View3D.xaml.cs +++ b/src/SampleApp.WinDesktop/View3D.xaml.cs @@ -37,20 +37,21 @@ namespace SampleApp.WinDesktop if(IsVisible) { graphic3D.Geometry = null; - if (NmeaDevice != null) - NmeaDevice.MessageReceived += NmeaDevice_MessageReceived; + if (GnssMonitor != null) + GnssMonitor.LocationChanged += GnssMonitor_LocationChanged; } else { - if (NmeaDevice != null) - NmeaDevice.MessageReceived -= NmeaDevice_MessageReceived; + if (GnssMonitor != null) + GnssMonitor.LocationChanged -= GnssMonitor_LocationChanged; } } - private void NmeaDevice_MessageReceived(object sender, NmeaMessageReceivedEventArgs e) + private void GnssMonitor_LocationChanged(object sender, EventArgs e) { - if (e.Message is Rmc rmc) - UpdateLocation(rmc.Latitude, rmc.Longitude, rmc.Course); + var monitor = (NmeaParser.Gnss.GnssMonitor)sender; + if (monitor.IsFixValid) + UpdateLocation(monitor.Latitude, monitor.Longitude, monitor.Course); } private Graphic graphic3D; @@ -107,15 +108,14 @@ namespace SampleApp.WinDesktop } } - public NmeaDevice NmeaDevice + public NmeaParser.Gnss.GnssMonitor GnssMonitor { - get { return (NmeaDevice)GetValue(NmeaDeviceProperty); } - set { SetValue(NmeaDeviceProperty, value); } + get { return (NmeaParser.Gnss.GnssMonitor)GetValue(GnssMonitorProperty); } + set { SetValue(GnssMonitorProperty, value); } } - // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... - public static readonly DependencyProperty NmeaDeviceProperty = - DependencyProperty.Register(nameof(NmeaDevice), typeof(NmeaDevice), typeof(View3D), new PropertyMetadata(null)); + public static readonly DependencyProperty GnssMonitorProperty = + DependencyProperty.Register(nameof(GnssMonitor), typeof(NmeaParser.Gnss.GnssMonitor), typeof(View3D), new PropertyMetadata(null)); } }