NmeaParser/src/SampleApp.WinDesktop/MainWindow.xaml.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2014-07-25 21:21:07 +02:00
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
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Queue<string> messages = new Queue<string>(101);
2014-07-25 21:21:07 +02:00
public MainWindow()
{
InitializeComponent();
var device = new NmeaParser.NmeaFileDevice("NmeaSampleData.txt");
device.MessageReceived += device_MessageReceived;
2014-07-29 01:38:45 +02:00
var _ = device.OpenAsync();
2014-07-25 21:21:07 +02:00
}
private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
2014-07-25 21:21:07 +02:00
{
Dispatcher.BeginInvoke((Action) delegate()
{
messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
if (messages.Count > 100) messages.Dequeue(); //Keep message queue at 100
output.Text = string.Join("\n", messages.ToArray());
2014-07-29 01:38:45 +02:00
output.Select(output.Text.Length - 1, 0); //scroll to bottom
if(args.Message is NmeaParser.Nmea.Gps.Gpgsv)
2014-07-29 01:38:45 +02:00
{
var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args.Message;
if(args.IsMultipart && args.MessageParts != null)
satView.GpgsvMessages = args.MessageParts.OfType<NmeaParser.Nmea.Gps.Gpgsv>();
2014-07-29 01:38:45 +02:00
}
2014-07-25 21:21:07 +02:00
});
}
}
}