diff --git a/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs b/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs new file mode 100644 index 0000000..1013d8c --- /dev/null +++ b/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs @@ -0,0 +1,79 @@ +// +// 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.Garmin +{ + /// + /// Altitude Information + /// + [NmeaMessageType(Type = "PGRMZ")] + public class Pgrmz : NmeaMessage + { + public enum AltitudeUnit + { + Unknown, + Feet + } + public enum PositionFixDimension : int + { + /// + /// No fix + /// + None = 0, + /// + /// 2D Fix + /// + UserAltitude = 2, + /// + /// 3D Fix + /// + GpsAltitude = 3 + } + protected override void LoadMessage(string[] message) + { + if (message[0].Length > 0) + Altitude = double.Parse(message[0], CultureInfo.InvariantCulture); + else + Altitude = double.NaN; + Unit = message[1] == "f" ? AltitudeUnit.Feet : AltitudeUnit.Unknown; + int dim = -1; + if (message[2].Length == 1 && int.TryParse(message[2], out dim)) + FixDimension = (PositionFixDimension)dim; + } + + /// + /// Estimated horizontal position error in meters (HPE) + /// + public double Altitude { get; private set; } + + /// + /// Horizontal Error unit ('M' for Meters) + /// + public AltitudeUnit Unit { get; private set; } + + /// + /// Estimated vertical position error in meters (VPE) + /// + public PositionFixDimension FixDimension { get; private set; } + } +} diff --git a/src/NmeaParser.Shared/NmeaParser.Shared.projitems b/src/NmeaParser.Shared/NmeaParser.Shared.projitems index f482a6b..fd8fb05 100644 --- a/src/NmeaParser.Shared/NmeaParser.Shared.projitems +++ b/src/NmeaParser.Shared/NmeaParser.Shared.projitems @@ -11,6 +11,7 @@ + diff --git a/src/NmeaParser.Tests/NmeaMessages.cs b/src/NmeaParser.Tests/NmeaMessages.cs index e1f4506..9ccc97e 100644 --- a/src/NmeaParser.Tests/NmeaMessages.cs +++ b/src/NmeaParser.Tests/NmeaMessages.cs @@ -304,5 +304,31 @@ namespace NmeaParser.Tests Assert.AreEqual("POINTB", bod.DestinationID, "DestinationID"); Assert.AreEqual("POINTA", bod.OriginID, "OriginID"); } + + + [TestMethod] + public void TestPgrmz_Empty() + { + string input = "$PGRMZ,,,*7E"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(NmeaParser.Nmea.Gps.Garmin.Pgrmz)); + var rmz = (NmeaParser.Nmea.Gps.Garmin.Pgrmz)msg; + Assert.AreEqual(double.NaN, rmz.Altitude, "Altitude"); + Assert.AreEqual(NmeaParser.Nmea.Gps.Garmin.Pgrmz.AltitudeUnit.Unknown, rmz.Unit, "Unit"); + Assert.AreEqual(NmeaParser.Nmea.Gps.Garmin.Pgrmz.PositionFixDimension.None, rmz.FixDimension, "FixDimension"); + } + + [TestMethod] + public void TestPgrmz() + { + string input = "$PGRMZ,93,f,3*21"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(NmeaParser.Nmea.Gps.Garmin.Pgrmz)); + var rmz = (NmeaParser.Nmea.Gps.Garmin.Pgrmz)msg; + Assert.AreEqual(93d, rmz.Altitude, "Altitude"); + Assert.AreEqual(NmeaParser.Nmea.Gps.Garmin.Pgrmz.AltitudeUnit.Feet, rmz.Unit, "Unit"); + Assert.AreEqual(NmeaParser.Nmea.Gps.Garmin.Pgrmz.PositionFixDimension.GpsAltitude, rmz.FixDimension, "FixDimension"); + } + } }