diff --git a/src/SampleApp.WinDesktop/GpggaControl.xaml.cs b/src/SampleApp.WinDesktop/GpggaControl.xaml.cs
index 61e24fe..9eaec0a 100644
--- a/src/SampleApp.WinDesktop/GpggaControl.xaml.cs
+++ b/src/SampleApp.WinDesktop/GpggaControl.xaml.cs
@@ -1,4 +1,4 @@
-using NmeaParser.Nmea.Gps;
+using NmeaParser.Nmea;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -26,13 +26,13 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
- public Gpgga Message
+ public Gga Message
{
- get { return (Gpgga)GetValue(GpggaProperty); }
+ get { return (Gga)GetValue(GpggaProperty); }
set { SetValue(GpggaProperty, value); }
}
public static readonly DependencyProperty GpggaProperty =
- DependencyProperty.Register("Message", typeof(Gpgga), typeof(GpggaControl), new PropertyMetadata(null));
+ DependencyProperty.Register("Message", typeof(Gga), typeof(GpggaControl), new PropertyMetadata(null));
}
}
diff --git a/src/SampleApp.WinDesktop/GpgllControl.xaml.cs b/src/SampleApp.WinDesktop/GpgllControl.xaml.cs
index e0ed3d5..92fd640 100644
--- a/src/SampleApp.WinDesktop/GpgllControl.xaml.cs
+++ b/src/SampleApp.WinDesktop/GpgllControl.xaml.cs
@@ -1,4 +1,4 @@
-using NmeaParser.Nmea.Gps;
+using NmeaParser.Nmea;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -26,13 +26,13 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
- public Gpgll Message
+ public Gll Message
{
- get { return (Gpgll)GetValue(MessageProperty); }
+ get { return (Gll)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public static readonly DependencyProperty MessageProperty =
- DependencyProperty.Register("Message", typeof(Gpgll), typeof(GpgllControl), new PropertyMetadata(null));
+ DependencyProperty.Register("Message", typeof(Gll), typeof(GpgllControl), new PropertyMetadata(null));
}
}
diff --git a/src/SampleApp.WinDesktop/GpgsaControl.xaml.cs b/src/SampleApp.WinDesktop/GpgsaControl.xaml.cs
index 2ceb34a..239a8b9 100644
--- a/src/SampleApp.WinDesktop/GpgsaControl.xaml.cs
+++ b/src/SampleApp.WinDesktop/GpgsaControl.xaml.cs
@@ -1,4 +1,4 @@
-using NmeaParser.Nmea.Gps;
+using NmeaParser.Nmea;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -26,13 +26,13 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
- public Gpgsa Message
+ public Gsa Message
{
- get { return (Gpgsa)GetValue(GpgsaProperty); }
+ get { return (Gsa)GetValue(GpgsaProperty); }
set { SetValue(GpgsaProperty, value); }
}
public static readonly DependencyProperty GpgsaProperty =
- DependencyProperty.Register("Message", typeof(Gpgsa), typeof(GpgsaControl), new PropertyMetadata(null));
+ DependencyProperty.Register("Message", typeof(Gsa), typeof(GpgsaControl), new PropertyMetadata(null));
}
}
diff --git a/src/SampleApp.WinDesktop/GprmcControl.xaml.cs b/src/SampleApp.WinDesktop/GprmcControl.xaml.cs
index 8fe2035..b1b579f 100644
--- a/src/SampleApp.WinDesktop/GprmcControl.xaml.cs
+++ b/src/SampleApp.WinDesktop/GprmcControl.xaml.cs
@@ -1,4 +1,4 @@
-using NmeaParser.Nmea.Gps;
+using NmeaParser.Nmea;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -26,13 +26,13 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
- public Gprmc Message
+ public Rmc Message
{
- get { return (Gprmc)GetValue(MessageProperty); }
+ get { return (Rmc)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public static readonly DependencyProperty MessageProperty =
- DependencyProperty.Register("Message", typeof(Gprmc), typeof(GprmcControl), new PropertyMetadata(null));
+ DependencyProperty.Register("Message", typeof(Rmc), typeof(GprmcControl), new PropertyMetadata(null));
}
}
diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml.cs b/src/SampleApp.WinDesktop/MainWindow.xaml.cs
index f7efa7a..cfebfff 100644
--- a/src/SampleApp.WinDesktop/MainWindow.xaml.cs
+++ b/src/SampleApp.WinDesktop/MainWindow.xaml.cs
@@ -52,12 +52,14 @@ namespace SampleApp.WinDesktop
/// Unloads the current device, and opens the next device
///
///
- private void StartDevice(NmeaParser.NmeaDevice device)
+ private async void StartDevice(NmeaParser.NmeaDevice device)
{
//Clean up old device
if (currentDevice != null)
{
currentDevice.MessageReceived -= device_MessageReceived;
+ if(currentDevice.IsOpen)
+ await currentDevice.CloseAsync();
currentDevice.Dispose();
}
output.Text = "";
@@ -100,17 +102,17 @@ namespace SampleApp.WinDesktop
satView.GsvMessages = gsvMessages.SelectMany(m=>m.Value);
}
}
- if (args.Message is NmeaParser.Nmea.Gps.Gprmc)
- gprmcView.Message = args.Message as NmeaParser.Nmea.Gps.Gprmc;
- else if (args.Message is NmeaParser.Nmea.Gps.Gpgga)
- gpggaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgga;
- else if (args.Message is NmeaParser.Nmea.Gps.Gpgsa)
- gpgsaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgsa;
- else if (args.Message is NmeaParser.Nmea.Gps.Gpgll)
- gpgllView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgll;
+ else if (args.Message is NmeaParser.Nmea.Rmc)
+ gprmcView.Message = args.Message as NmeaParser.Nmea.Rmc;
+ else if (args.Message is NmeaParser.Nmea.Gga)
+ gpggaView.Message = args.Message as NmeaParser.Nmea.Gga;
+ else if (args.Message is NmeaParser.Nmea.Gsa)
+ gpgsaView.Message = args.Message as NmeaParser.Nmea.Gsa;
+ else if (args.Message is NmeaParser.Nmea.Gll)
+ gpgllView.Message = args.Message as NmeaParser.Nmea.Gll;
else if (args.Message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
pgrmeView.Message = args.Message as NmeaParser.Nmea.Gps.Garmin.Pgrme;
- else if (args.Message is NmeaParser.Nmea.UnknownMessage)
+ else
{
var ctrl = MessagePanel.Children.OfType().Where(c => c.Message.MessageType == args.Message.MessageType).FirstOrDefault();
if(ctrl == null)
@@ -121,11 +123,7 @@ namespace SampleApp.WinDesktop
};
MessagePanel.Children.Add(ctrl);
}
- ctrl.Message = args.Message as NmeaParser.Nmea.UnknownMessage;
- }
- else
- {
- //
+ ctrl.Message = args.Message;
}
});
}
@@ -145,10 +143,17 @@ namespace SampleApp.WinDesktop
//Creates a serial port device from the selected settings
private void ConnectToSerialButton_Click(object sender, RoutedEventArgs e)
{
- var portName = serialPorts.Text as string;
- var baudRate = int.Parse(baudRates.Text);
- var device = new NmeaParser.SerialPortDevice(new System.IO.Ports.SerialPort(portName, baudRate));
- StartDevice(device);
+ try
+ {
+ var portName = serialPorts.Text as string;
+ var baudRate = int.Parse(baudRates.Text);
+ var device = new NmeaParser.SerialPortDevice(new System.IO.Ports.SerialPort(portName, baudRate));
+ StartDevice(device);
+ }
+ catch(System.Exception ex)
+ {
+ MessageBox.Show("Error connecting: " + ex.Message);
+ }
}
//Attempts to perform an auto discovery of serial ports
diff --git a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs
index 2848b2c..efc4767 100644
--- a/src/SampleApp.WinDesktop/SatelliteView.xaml.cs
+++ b/src/SampleApp.WinDesktop/SatelliteView.xaml.cs
@@ -25,8 +25,6 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
-
-
public IEnumerable GsvMessages
{
get { return (IEnumerable)GetValue(GsvMessagesProperty); }
diff --git a/src/SampleApp.WinDesktop/UnknownMessageControl.xaml b/src/SampleApp.WinDesktop/UnknownMessageControl.xaml
index 6bdf9d6..dcedb54 100644
--- a/src/SampleApp.WinDesktop/UnknownMessageControl.xaml
+++ b/src/SampleApp.WinDesktop/UnknownMessageControl.xaml
@@ -7,10 +7,10 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
-
+
-
+
diff --git a/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs b/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs
index 8ff11d0..06506df 100644
--- a/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs
+++ b/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs
@@ -28,13 +28,51 @@ namespace SampleApp.WinDesktop
InitializeComponent();
}
- public UnknownMessage Message
+ public NmeaMessage Message
{
- get { return (UnknownMessage)GetValue(MessageProperty); }
+ get { return (NmeaMessage)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public static readonly DependencyProperty MessageProperty =
- DependencyProperty.Register("Message", typeof(NmeaParser.Nmea.UnknownMessage), typeof(UnknownMessageControl), new PropertyMetadata(null));
- }
+ DependencyProperty.Register("Message", typeof(NmeaMessage), typeof(UnknownMessageControl), new PropertyMetadata(null, OnMessagePropertyChanged));
+
+ private static void OnMessagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var ctrl = (UnknownMessageControl)d;
+
+ if (e.NewValue == null || e.NewValue is UnknownMessage && !(e.OldValue is UnknownMessage))
+ {
+ ctrl.HeaderPanel.Background = new SolidColorBrush(Colors.LightGray);
+ }
+ else if ((e.OldValue == null || e.OldValue is UnknownMessage) && !(e.NewValue is UnknownMessage))
+ {
+ ctrl.HeaderPanel.Background = new SolidColorBrush(Colors.CornflowerBlue);
+ }
+ if (e.NewValue == null)
+ ctrl.Values.ItemsSource = null;
+ else if (e.NewValue is UnknownMessage unk)
+ ctrl.Values.ItemsSource = unk.Values;
+ else
+ {
+ var props = e.NewValue.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).Where(p => !p.CanWrite);
+ List values = new List();
+ foreach (var prop in props.OrderBy(t => t.Name))
+ {
+ if (prop.Name == nameof(NmeaMessage.MessageType) || prop.Name == nameof(NmeaMessage.Checksum))
+ continue;
+ var value = prop.GetValue(e.NewValue);
+ if (!(value is string) && value is System.Collections.IEnumerable arr)
+ {
+ var str = "[" + string.Join(",", arr.OfType