mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2025-12-06 07:12:04 +01:00
Added GPGLL
This commit is contained in:
parent
4bbd7fa54c
commit
79e6523d0d
64
src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs
Normal file
64
src/NmeaParser.Shared/Nmea/Gps/GPGLL.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.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NmeaParser.Nmea.Gps
|
||||
{
|
||||
/// <summary>
|
||||
/// Geographic position, latitude / longitude
|
||||
/// </summary>
|
||||
[NmeaMessageType(Type = "GPGLL")]
|
||||
public class Gpgll : NmeaMessage
|
||||
{
|
||||
protected override void LoadMessage(string[] message)
|
||||
{
|
||||
var time = message[0];
|
||||
Latitude = NmeaMessage.StringToLatitude(message[0], message[1]);
|
||||
Longitude = NmeaMessage.StringToLongitude(message[2], message[3]);
|
||||
if (message.Length >= 5 && message[4].Length == 6) //Some older GPS doesn't broadcast fix time
|
||||
{
|
||||
FixTime = new TimeSpan(int.Parse(message[4].Substring(0, 2)),
|
||||
int.Parse(message[4].Substring(2, 2)),
|
||||
int.Parse(message[4].Substring(4, 2)));
|
||||
}
|
||||
DataActive = (message.Length < 6 || message[5] == "A");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Latitude
|
||||
/// </summary>
|
||||
public double Latitude { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Longitude
|
||||
/// </summary>
|
||||
public double Longitude { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Time since last DGPS update
|
||||
/// </summary>
|
||||
public TimeSpan FixTime { get; set; }
|
||||
|
||||
public bool DataActive { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)NmeaDevice.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)NmeaFileDevice.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\Garmin\PGRME.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGLL.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGSV.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGSA.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGGA.cs" />
|
||||
|
|
|
|||
|
|
@ -237,5 +237,31 @@ namespace NmeaParser.Tests
|
|||
Assert.IsNotNull(gsv.SVs);
|
||||
Assert.AreEqual(0, gsv.SVs.Length);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpgll()
|
||||
{
|
||||
string input = "$GPGLL,4916.45,N,12311.12,W,225444,A,*1D";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpgll));
|
||||
Gpgll gll = (Gpgll)msg;
|
||||
Assert.IsTrue(gll.DataActive);
|
||||
Assert.AreEqual(49.2741666666666666667, gll.Latitude);
|
||||
Assert.AreEqual(-123.18533333333333333, gll.Longitude);
|
||||
Assert.AreEqual(new TimeSpan(22,54,44), gll.FixTime);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpgll_NoFixTime_OrActiveIndicator()
|
||||
{
|
||||
string input = "$GPGLL,3751.65,S,14507.36,E*77";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpgll));
|
||||
Gpgll gll = (Gpgll)msg;
|
||||
Assert.IsTrue(gll.DataActive);
|
||||
Assert.AreEqual(-37.860833333333333333, gll.Latitude);
|
||||
Assert.AreEqual(145.1226666666666666667, gll.Longitude);
|
||||
Assert.AreEqual(TimeSpan.Zero, gll.FixTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue