mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2025-12-06 07:12:04 +01:00
Fixes #42
This commit is contained in:
parent
e9ea4ef1c3
commit
a648721ba8
64
src/NmeaParser/Nmea/Gps/GPVTG.cs
Normal file
64
src/NmeaParser/Nmea/Gps/GPVTG.cs
Normal file
|
|
@ -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.Text;
|
||||
|
||||
namespace NmeaParser.Nmea.Gps
|
||||
{
|
||||
/// <summary>
|
||||
/// Course over ground and ground speed
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "GPVTG")]
|
||||
[NmeaMessageType("GPVTG")]
|
||||
public class Gpvtg : NmeaMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when the message is being loaded.
|
||||
/// </summary>
|
||||
/// <param name="message">The NMEA message values.</param>
|
||||
protected override void OnLoadMessage(string[] message)
|
||||
{
|
||||
if (message == null || message.Length < 7)
|
||||
throw new ArgumentException("Invalid Gpvtg", "message");
|
||||
TrueCourseOverGround = NmeaMessage.StringToDouble(message[0]);
|
||||
MagneticCourseOverGround = NmeaMessage.StringToDouble(message[2]);
|
||||
SpeedInKnots = NmeaMessage.StringToDouble(message[4]);
|
||||
SpeedInKph = NmeaMessage.StringToDouble(message[6]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Course over ground relative to true north
|
||||
/// </summary>
|
||||
public double TrueCourseOverGround { get; private set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// Course over ground relative to magnetic north
|
||||
/// </summary>
|
||||
public double MagneticCourseOverGround { get; private set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// Speed over ground in knots
|
||||
/// </summary>
|
||||
public double SpeedInKnots { get; private set; } = double.NaN;
|
||||
|
||||
/// <summary>
|
||||
/// Speed over ground in kilometers/hour
|
||||
/// </summary>
|
||||
public double SpeedInKph { get; private set; } = double.NaN;
|
||||
}
|
||||
}
|
||||
|
|
@ -588,5 +588,31 @@ namespace NmeaParser.Tests
|
|||
Assert.AreEqual(0.020, gst.SigmaLongitudeError);
|
||||
Assert.AreEqual(0.031, gst.SigmaHeightError);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpvtg()
|
||||
{
|
||||
string input = "$GPVTG,103.85,T,92.79,M,0.14,N,0.25,K,D*1E";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpvtg));
|
||||
Gpvtg vtg = (Gpvtg)msg;
|
||||
Assert.AreEqual(103.85, vtg.TrueCourseOverGround);
|
||||
Assert.AreEqual(92.79, vtg.MagneticCourseOverGround);
|
||||
Assert.AreEqual(0.14, vtg.SpeedInKnots);
|
||||
Assert.AreEqual(0.25, vtg.SpeedInKph);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpvtg_Empty()
|
||||
{
|
||||
string input = "$GPVTG,,T,,M,0.00,N,0.00,K*4E";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpvtg));
|
||||
Gpvtg vtg = (Gpvtg)msg;
|
||||
Assert.IsTrue(double.IsNaN(vtg.TrueCourseOverGround));
|
||||
Assert.IsTrue(double.IsNaN(vtg.MagneticCourseOverGround));
|
||||
Assert.AreEqual(0.0, vtg.SpeedInKnots);
|
||||
Assert.AreEqual(0.0, vtg.SpeedInKph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue