mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2025-12-06 07:12:04 +01:00
Added $GPBOD
This commit is contained in:
parent
eef62be450
commit
93aa1d8192
67
src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs
Normal file
67
src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
//
|
||||
// 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>
|
||||
/// Bearing Origin to Destination
|
||||
/// </summary>
|
||||
[NmeaMessageType(Type = "GPBOD")]
|
||||
public class Gpbod : NmeaMessage
|
||||
{
|
||||
protected override void LoadMessage(string[] message)
|
||||
{
|
||||
if (message[0].Length > 0)
|
||||
TrueBearing = double.Parse(message[0], CultureInfo.InvariantCulture);
|
||||
else
|
||||
TrueBearing = double.NaN;
|
||||
if (message[2].Length > 0)
|
||||
MagneticBearing = double.Parse(message[2], CultureInfo.InvariantCulture);
|
||||
else
|
||||
MagneticBearing = double.NaN;
|
||||
if (message.Length > 4 && !string.IsNullOrEmpty(message[4]))
|
||||
DestinationID = message[4];
|
||||
if (message.Length > 5 && !string.IsNullOrEmpty(message[5]))
|
||||
OriginID = message[5];
|
||||
}
|
||||
/// <summary>
|
||||
/// True Bearing from start to destination
|
||||
/// </summary>
|
||||
public double TrueBearing { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Magnetic Bearing from start to destination
|
||||
/// </summary>
|
||||
public double MagneticBearing { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of origin
|
||||
/// </summary>
|
||||
public string OriginID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of destination
|
||||
/// </summary>
|
||||
public string DestinationID { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ namespace NmeaParser.Nmea.Gps
|
|||
SVsInView = int.Parse(message[2]);
|
||||
|
||||
List<SatelitteVehicle> svs = new List<SatelitteVehicle>();
|
||||
for (int i = 3; i < 18; i+=4)
|
||||
for (int i = 3; i < message.Length - 4; i += 4)
|
||||
{
|
||||
if (message[i].Length == 0)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ namespace NmeaParser
|
|||
if (lineEnd > -1)
|
||||
{
|
||||
line = message.Substring(0, lineEnd).Trim();
|
||||
message = message.Substring(lineEnd).Trim();
|
||||
message = message.Substring(lineEnd);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
<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\GPBOD.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGSV.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGSA.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Nmea\Gps\GPGGA.cs" />
|
||||
|
|
|
|||
|
|
@ -263,5 +263,46 @@ namespace NmeaParser.Tests
|
|||
Assert.AreEqual(145.1226666666666666667, gll.Longitude);
|
||||
Assert.AreEqual(TimeSpan.Zero, gll.FixTime);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpbod_Empty()
|
||||
{
|
||||
string input = "$GPBOD,,T,,M,,*47";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpbod));
|
||||
Gpbod bod = (Gpbod)msg;
|
||||
Assert.AreEqual(double.NaN, bod.TrueBearing, "TrueBearing");
|
||||
Assert.AreEqual(double.NaN, bod.MagneticBearing, "MagneticBearing");
|
||||
Assert.IsNull(bod.OriginID, "OriginID");
|
||||
Assert.IsNull(bod.DestinationID, "DestinationID");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpbod_GoToMode()
|
||||
{
|
||||
string input = "$GPBOD,099.3,T,105.6,M,POINTB,*48";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpbod));
|
||||
Gpbod bod = (Gpbod)msg;
|
||||
Assert.AreEqual(99.3, bod.TrueBearing, "TrueBearing");
|
||||
Assert.AreEqual(105.6, bod.MagneticBearing, "MagneticBearing");
|
||||
Assert.AreEqual("POINTB", bod.DestinationID, "DestinationID");
|
||||
Assert.IsNull(bod.OriginID, "OriginID");
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestGpbod()
|
||||
{
|
||||
string input = "$GPBOD,097.0,T,103.2,M,POINTB,POINTA*4A";
|
||||
var msg = NmeaMessage.Parse(input);
|
||||
Assert.IsInstanceOfType(msg, typeof(Gpbod));
|
||||
Gpbod bod = (Gpbod)msg;
|
||||
Assert.AreEqual(97d, bod.TrueBearing, "TrueBearing");
|
||||
Assert.AreEqual(103.2, bod.MagneticBearing, "MagneticBearing");
|
||||
Assert.AreEqual("POINTB", bod.DestinationID, "DestinationID");
|
||||
Assert.AreEqual("POINTA", bod.OriginID, "OriginID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue