From ee7d6ce1c72f0fdea0a05ecf6cba35d0f77f6e12 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Mon, 11 Mar 2019 23:31:11 -0700 Subject: [PATCH] Fixes #53 --- src/NmeaParser/Nmea/Gsv.cs | 12 ++++++----- .../NmeaParser.Tests/NmeaMessages.cs | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/NmeaParser/Nmea/Gsv.cs b/src/NmeaParser/Nmea/Gsv.cs index dfd6730..f4a67b9 100644 --- a/src/NmeaParser/Nmea/Gsv.cs +++ b/src/NmeaParser/Nmea/Gsv.cs @@ -98,8 +98,10 @@ namespace NmeaParser.Nmea internal SatelliteVehicle(string[] message, int startIndex) { PrnNumber = int.Parse(message[startIndex], CultureInfo.InvariantCulture); - Elevation = double.Parse(message[startIndex + 1], CultureInfo.InvariantCulture); - Azimuth = double.Parse(message[startIndex + 2], CultureInfo.InvariantCulture); + if (double.TryParse(message[startIndex + 1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double e)) + Elevation = e; + if (double.TryParse(message[startIndex + 2], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double a)) + Azimuth = a; int snr = -1; if (int.TryParse(message[startIndex + 3], out snr)) SignalToNoiseRatio = snr; @@ -111,15 +113,15 @@ namespace NmeaParser.Nmea /// /// Elevation in degrees, 90 maximum /// - public double Elevation { get; } + public double Elevation { get; } = double.NaN; /// /// Azimuth, degrees from true north, 000 to 359 /// - public double Azimuth { get; } + public double Azimuth { get; } = double.NaN; /// /// Signal-to-Noise ratio, 0-99 dB (-1 when not tracking) /// - public int SignalToNoiseRatio { get; } + public int SignalToNoiseRatio { get; } = -1; /// /// Satellite system diff --git a/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs b/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs index 4baa579..5a46943 100644 --- a/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs +++ b/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs @@ -343,6 +343,26 @@ namespace NmeaParser.Tests Assert.AreEqual(0, gsv.SVs.Count); } + + [TestMethod] + [WorkItem(53)] + public void TestGpgsv_MissingElevationAndAzimuth() + { + string msgstr = "$GPGSV,3,1,12,02,06,225,16,04,,,40,05,65,251,27,07,40,057,43,0*51"; + var msg = NmeaMessage.Parse(msgstr); + Assert.IsInstanceOfType(msg, typeof(Gsv)); + Gsv gsv = (Gsv)msg; + Assert.AreEqual(3, gsv.TotalMessages); + Assert.AreEqual(1, gsv.MessageNumber); + Assert.AreEqual(12, gsv.SVsInView); + Assert.IsNotNull(gsv.SVs); + Assert.AreEqual(4, gsv.SVs.Count); + Assert.AreEqual(4, gsv.SVs[1].PrnNumber); + Assert.IsTrue(double.IsNaN(gsv.SVs[1].Elevation)); + Assert.IsTrue(double.IsNaN(gsv.SVs[1].Azimuth)); + Assert.AreEqual(40, gsv.SVs[1].SignalToNoiseRatio); + } + [TestMethod] public void TestGpgll() {