From 79e6523d0da84fe9243bb52b17ddc8cf65da13b4 Mon Sep 17 00:00:00 2001 From: mort5161 Date: Mon, 28 Jul 2014 16:51:48 -0700 Subject: [PATCH] Added GPGLL --- src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs | 64 +++++++++++++++++++ .../NmeaParser.Shared.projitems | 1 + src/NmeaParser.Tests/NmeaMessages.cs | 26 ++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs b/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs new file mode 100644 index 0000000..e460e82 --- /dev/null +++ b/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs @@ -0,0 +1,64 @@ +// +// Copyright (c) 2014 Morten Nielsen +// +// Licensed under the Microsoft Public License (Ms-PL) (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://opensource.org/licenses/Ms-PL.html +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NmeaParser.Nmea.Gps +{ + /// + /// Geographic position, latitude / longitude + /// + [NmeaMessageType(Type = "GPGLL")] + public class Gpgll : NmeaMessage + { + protected override void LoadMessage(string[] message) + { + var time = message[0]; + Latitude = NmeaMessage.StringToLatitude(message[0], message[1]); + Longitude = NmeaMessage.StringToLongitude(message[2], message[3]); + if (message.Length >= 5 && message[4].Length == 6) //Some older GPS doesn't broadcast fix time + { + FixTime = new TimeSpan(int.Parse(message[4].Substring(0, 2)), + int.Parse(message[4].Substring(2, 2)), + int.Parse(message[4].Substring(4, 2))); + } + DataActive = (message.Length < 6 || message[5] == "A"); + } + + /// + /// Latitude + /// + public double Latitude { get; private set; } + + /// + /// Longitude + /// + public double Longitude { get; private set; } + + /// + /// Time since last DGPS update + /// + public TimeSpan FixTime { get; set; } + + public bool DataActive { get; set; } + + } +} diff --git a/src/NmeaParser.Shared/NmeaParser.Shared.projitems b/src/NmeaParser.Shared/NmeaParser.Shared.projitems index d6ab5da..085cf0b 100644 --- a/src/NmeaParser.Shared/NmeaParser.Shared.projitems +++ b/src/NmeaParser.Shared/NmeaParser.Shared.projitems @@ -12,6 +12,7 @@ + diff --git a/src/NmeaParser.Tests/NmeaMessages.cs b/src/NmeaParser.Tests/NmeaMessages.cs index 429a69a..48fc655 100644 --- a/src/NmeaParser.Tests/NmeaMessages.cs +++ b/src/NmeaParser.Tests/NmeaMessages.cs @@ -237,5 +237,31 @@ namespace NmeaParser.Tests Assert.IsNotNull(gsv.SVs); Assert.AreEqual(0, gsv.SVs.Length); } + + [TestMethod] + public void TestGpgll() + { + string input = "$GPGLL,4916.45,N,12311.12,W,225444,A,*1D"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(Gpgll)); + Gpgll gll = (Gpgll)msg; + Assert.IsTrue(gll.DataActive); + Assert.AreEqual(49.2741666666666666667, gll.Latitude); + Assert.AreEqual(-123.18533333333333333, gll.Longitude); + Assert.AreEqual(new TimeSpan(22,54,44), gll.FixTime); + } + + [TestMethod] + public void TestGpgll_NoFixTime_OrActiveIndicator() + { + string input = "$GPGLL,3751.65,S,14507.36,E*77"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(Gpgll)); + Gpgll gll = (Gpgll)msg; + Assert.IsTrue(gll.DataActive); + Assert.AreEqual(-37.860833333333333333, gll.Latitude); + Assert.AreEqual(145.1226666666666666667, gll.Longitude); + Assert.AreEqual(TimeSpan.Zero, gll.FixTime); + } } }