mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2025-12-06 07:12:04 +01:00
Added $PGRMZ
This commit is contained in:
parent
93aa1d8192
commit
c5c07e15ae
79
src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs
Normal file
79
src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs
Normal file
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Altitude Information
|
||||
/// </summary>
|
||||
[NmeaMessageType(Type = "PGRMZ")]
|
||||
public class Pgrmz : NmeaMessage
|
||||
{
|
||||
public enum AltitudeUnit
|
||||
{
|
||||
Unknown,
|
||||
Feet
|
||||
}
|
||||
public enum PositionFixDimension : int
|
||||
{
|
||||
/// <summary>
|
||||
/// No fix
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// 2D Fix
|
||||
/// </summary>
|
||||
UserAltitude = 2,
|
||||
/// <summary>
|
||||
/// 3D Fix
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Estimated horizontal position error in meters (HPE)
|
||||
/// </summary>
|
||||
public double Altitude { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal Error unit ('M' for Meters)
|
||||
/// </summary>
|
||||
public AltitudeUnit Unit { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Estimated vertical position error in meters (VPE)
|
||||
/// </summary>
|
||||
public PositionFixDimension FixDimension { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)NmeaDevice.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)NmeaFileDevice.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\Garmin\PGRMZ.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\Garmin\PGRME.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGLL.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPBOD.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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue