mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2026-01-20 15:40:16 +01:00
Reuse gnss monitor instance in sample app
This commit is contained in:
parent
ffefe05c53
commit
43fedd2b3f
|
|
@ -16,6 +16,7 @@ namespace SampleApp.WinDesktop
|
|||
{
|
||||
private Queue<string> messages = new Queue<string>(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)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace SampleApp.WinDesktop
|
|||
/// </summary>
|
||||
/// <param name="device">The NMEA device to monitor</param>
|
||||
/// <param name="startStopDevice">Whether starting this datasource also controls the underlying NMEA device</param>
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue