mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2025-12-06 07:12:04 +01:00
Fixed GPGGA message parsing
This commit is contained in:
parent
027ba1fbe3
commit
189b10d376
|
|
@ -24,7 +24,7 @@ using System.Threading.Tasks;
|
|||
namespace NmeaParser.Nmea.Gps
|
||||
{
|
||||
/// <summary>
|
||||
/// Recommended Minimum
|
||||
/// Global Positioning System Fix Data
|
||||
/// </summary>
|
||||
[NmeaMessageType(Type = "GPGGA")]
|
||||
public class Gpgga : NmeaMessage
|
||||
|
|
@ -58,10 +58,16 @@ namespace NmeaParser.Nmea.Gps
|
|||
AltitudeUnits = message[9];
|
||||
HeightOfGeoid = double.Parse(message[10], CultureInfo.InvariantCulture);
|
||||
HeightOfGeoidUnits = message[11];
|
||||
if (message[12].Length > 0)
|
||||
TimeSinceLastDgpsUpdate = TimeSpan.FromSeconds(int.Parse(message[12], CultureInfo.InvariantCulture));
|
||||
if (message[0].Length == 6)
|
||||
{
|
||||
TimeSinceLastDgpsUpdate = new TimeSpan(int.Parse(message[0].Substring(0, 2)),
|
||||
int.Parse(message[0].Substring(2, 2)),
|
||||
int.Parse(message[0].Substring(4, 2)));
|
||||
}
|
||||
if (message[13].Length > 0)
|
||||
DgpsStationID = int.Parse(message[13], CultureInfo.InvariantCulture);
|
||||
else
|
||||
DgpsStationID = -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -30,13 +30,35 @@ namespace NmeaParser.Tests
|
|||
[TestMethod]
|
||||
public void TestGprmc()
|
||||
{
|
||||
string input = "$GPRMC,123519,A,4807.038,S,01131.000,W,022.4,084.4,230313,003.1,W*6E";
|
||||
string input = "$GPRMC,123519,A,4807.038,S,01131.000,W,022.4,084.4,230313,003.1,W*6A";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gprmc));
|
||||
Gprmc rmc = (Gprmc)msg;
|
||||
Assert.AreEqual(new DateTime(23, 03, 2013, 12, 35, 19, DateTimeKind.Utc), rmc.FixTime);
|
||||
Assert.AreEqual(new DateTime(2013, 03, 23, 12, 35, 19, DateTimeKind.Utc), rmc.FixTime);
|
||||
Assert.AreEqual(-48.1173, rmc.Latitude);
|
||||
Assert.AreEqual(-11.516666666666667, rmc.Longitude, 0.0000000001);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpgga()
|
||||
{
|
||||
string input = "$GPGGA,235236,3925.9479,N,11945.9211,W,1,10,0.8,1378.0,M,-22.1,M,,*46";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpgga));
|
||||
Gpgga gga = (Gpgga)msg;
|
||||
Assert.AreEqual(new TimeSpan(23, 52, 36), gga.TimeSinceLastDgpsUpdate);
|
||||
Assert.AreEqual(39.432465, gga.Latitude);
|
||||
Assert.AreEqual(-119.7653516666666667, gga.Longitude, 0.0000000001);
|
||||
Assert.AreEqual(NmeaParser.Nmea.Gps.Gpgga.FixQuality.GpsFix, gga.Quality);
|
||||
Assert.AreEqual(10, gga.NumberOfSatellites);
|
||||
Assert.AreEqual(.8, gga.Hdop);
|
||||
Assert.AreEqual(1378, gga.Altitude);
|
||||
Assert.AreEqual("M", gga.AltitudeUnits);
|
||||
Assert.AreEqual(-22.1, gga.HeightOfGeoid);
|
||||
Assert.AreEqual("M", gga.HeightOfGeoidUnits);
|
||||
Assert.AreEqual(-1, gga.DgpsStationID);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestPtlna()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue