Merge pull request #45 from ShutterQuick/feature/zda

Add ZDA message
This commit is contained in:
Morten Nielsen 2018-10-02 07:47:27 -07:00 committed by GitHub
commit 92ffe75ad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 0 deletions

View file

@ -0,0 +1,8 @@
namespace NmeaParser.Nmea.Glonass
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Glzda")]
[NmeaMessageType("GLZDA")]
public class Glzda : Zda
{
}
}

View file

@ -0,0 +1,8 @@
namespace NmeaParser.Nmea.Gnss
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gnzda")]
[NmeaMessageType("GNZDA")]
public class Gnzda : Zda
{
}
}

View file

@ -0,0 +1,8 @@
namespace NmeaParser.Nmea.Gps
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpzda")]
[NmeaMessageType("GPZDA")]
public class Gpzda : Zda
{
}
}

View file

@ -0,0 +1,38 @@
using System;
using System.Globalization;
namespace NmeaParser.Nmea
{
/// <summary>
/// Date and time of fix
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Zda")]
public abstract class Zda : 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?.Length != 6)
{
throw new ArgumentException("Invalid GNGST", nameof(message));
}
var time = StringToTimeSpan(message[0]);
var day = int.Parse(message[1], CultureInfo.InvariantCulture);
var month = int.Parse(message[2], CultureInfo.InvariantCulture);
var year = int.Parse(message[3], CultureInfo.InvariantCulture);
FixDateTime = new DateTime(year, month, day, time.Hours, time.Minutes,
time.Seconds, DateTimeKind.Utc);
// Index 4 and 5 is used to specify a local time zone.
// However I haven't come across any receiver that actually
// specify this, so we're just ignoring it.
}
public DateTime FixDateTime { get; private set; }
}
}

View file

@ -614,5 +614,35 @@ namespace NmeaParser.Tests
Assert.AreEqual(0.0, vtg.SpeedInKnots);
Assert.AreEqual(0.0, vtg.SpeedInKph);
}
[TestMethod]
public void TestGnzda()
{
var input = "$GNZDA,075451.00,02,10,2018,00,00*72";
var msg = NmeaMessage.Parse(input);
Assert.IsInstanceOfType(msg, typeof(Gnzda));
var zda = (Gnzda)msg;
Assert.AreEqual(new DateTime(2018, 10, 02, 07, 54, 51, 00, DateTimeKind.Utc), zda.FixDateTime);
}
[TestMethod]
public void TestGpzda()
{
var input = "$GPZDA,143042.00,25,08,2005,,*6E";
var msg = NmeaMessage.Parse(input);
Assert.IsInstanceOfType(msg, typeof(Gpzda));
var zda = (Gpzda)msg;
Assert.AreEqual(new DateTime(2005, 08, 25, 14, 30, 42, 00, DateTimeKind.Utc), zda.FixDateTime);
}
[TestMethod]
public void TestGlzda()
{
var input = "$GLZDA,225627.00,21,09,2015,00,00*70";
var msg = NmeaMessage.Parse(input);
Assert.IsInstanceOfType(msg, typeof(Glzda));
var zda = (Glzda)msg;
Assert.AreEqual(new DateTime(2015, 09, 21, 22, 56, 27, 00, DateTimeKind.Utc), zda.FixDateTime);
}
}
}