From 41ddca8d0b0a2a3dda68fec86b7a66ef4d0c58a3 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Thu, 30 Jul 2020 19:57:17 -0700 Subject: [PATCH] Improve timestamp display --- src/NmeaParser/Nmea/NmeaMessage.cs | 2 +- .../UnknownMessageControl.xaml.cs | 12 ++++++++++-- .../NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/NmeaParser/Nmea/NmeaMessage.cs b/src/NmeaParser/Nmea/NmeaMessage.cs index 4e2bbf9..4f939b9 100644 --- a/src/NmeaParser/Nmea/NmeaMessage.cs +++ b/src/NmeaParser/Nmea/NmeaMessage.cs @@ -301,7 +301,7 @@ namespace NmeaParser.Messages /// /// /// This value is deduced from System.Diagnostics.Stopwatch.GetTimestamp() * 1000d / System.Diagnostics.Stopwatch.Frequency. - /// You can use it to calculate the age of the message in seconds by calculating the difference between the timestamp and the above expression + /// You can use it to calculate the age of the message in milliseconds by calculating the difference between the timestamp and the above expression /// public double Timestamp { get; } } diff --git a/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs b/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs index af54a6e..d609a9e 100644 --- a/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs +++ b/src/SampleApp.WinDesktop/UnknownMessageControl.xaml.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; @@ -48,7 +49,7 @@ namespace SampleApp.WinDesktop List values = new List(); foreach (var prop in props.OrderBy(t => t.Name)) { - if (prop.Name == nameof(NmeaMessage.MessageType) || prop.Name == nameof(NmeaMessage.Checksum)) + if (prop.Name == nameof(NmeaMessage.MessageType) || prop.Name == nameof(NmeaMessage.Checksum) || prop.Name == nameof(NmeaMessage.Timestamp)) continue; var value = prop.GetValue(e.NewValue); if (!(value is string) && value is System.Collections.IEnumerable arr) @@ -60,6 +61,13 @@ namespace SampleApp.WinDesktop } values.Add($"{prop.Name}: {value}"); } + if (e.NewValue is NmeaMessage msg) + { + var age = (System.Diagnostics.Stopwatch.GetTimestamp() * 1000d / System.Diagnostics.Stopwatch.Frequency) - msg.Timestamp; + values.Add($"Timestamp: " + DateTime.Now.AddMilliseconds(-age).TimeOfDay.ToString("h\\:mm\\:ss")); + } + //; + ctrl.Values.ItemsSource = values; } } diff --git a/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj b/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj index 7c7832d..f5561d2 100644 --- a/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj +++ b/src/UnitTests/NmeaParser.Tests.NET/NmeaParser.Tests.Net.csproj @@ -3,6 +3,7 @@ net451;netcoreapp3.1 false + 8.0