Skip to content

Commit

Permalink
Merge pull request #10 from GhostwareDev/development
Browse files Browse the repository at this point in the history
Doing a new release
  • Loading branch information
kevingoos authored Apr 7, 2017
2 parents 5686c99 + bdb1e65 commit c6ab45d
Show file tree
Hide file tree
Showing 20 changed files with 515 additions and 178 deletions.
15 changes: 15 additions & 0 deletions NMEAParser/Ghostware.NMEAParser/Enums/SatelliteFixType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ghostware.NMEAParser.Enums
{
public enum SatelliteFixType
{
NoFix,
TwoDFix,
ThreeDFix
}
}
20 changes: 18 additions & 2 deletions NMEAParser/Ghostware.NMEAParser/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Ghostware.NMEAParser.Extensions
{
public static class StringExtensions
{
private const string Pattern = @"(\d{2})(\d{2})(\d{2})";
private const string Pattern = @"(\d{2})(\d{2})(\d{2})[.\d{2}]?";

public static TimeSpan ToTimeSpan(this string inputString)
{
var regexMatch = Regex.Match(inputString, Pattern);
return regexMatch.Groups.Count == 0 ? TimeSpan.Zero : new TimeSpan(int.Parse(regexMatch.Groups[0].Value), int.Parse(regexMatch.Groups[1].Value), int.Parse(regexMatch.Groups[2].Value));
return regexMatch.Groups.Count == 0 ? TimeSpan.Zero : new TimeSpan(0, int.Parse(regexMatch.Groups[1].Value), int.Parse(regexMatch.Groups[2].Value), int.Parse(regexMatch.Groups[3].Value));
}

public static double ToCoordinates(this string inputString, string cardinalDirection, CoordinateType coordinateType)
Expand Down Expand Up @@ -40,5 +40,21 @@ public static double ToDouble(this string inputString)
{
return !string.IsNullOrEmpty(inputString) ? double.Parse(inputString, CultureInfo.InvariantCulture) : double.NaN;
}

public static float ToFloat(this string inputString)
{
return !string.IsNullOrEmpty(inputString) ? float.Parse(inputString, CultureInfo.InvariantCulture) : float.NaN;
}

public static bool ToBoolean(this string inputString, string validValue)
{
return inputString == validValue;
}

public static string RemoveAfter(this string inputString, string charValue)
{
var index = inputString.IndexOf(charValue, StringComparison.Ordinal);
return index > 0 ? inputString.Substring(0, index) : inputString;
}
}
}
3 changes: 3 additions & 0 deletions NMEAParser/Ghostware.NMEAParser/Ghostware.NMEAParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Enums\CoordinateType.cs" />
<Compile Include="Enums\SatelliteFixType.cs" />
<Compile Include="Enums\GpsFixQuality.cs" />
<Compile Include="Exceptions\UnknownTypeException.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="NmeaConstants.cs" />
<Compile Include="NMEAMessages\GpgsaMessage.cs" />
<Compile Include="NMEAMessages\GprmcMessage.cs" />
<Compile Include="NMEAMessages\GpvtgMessage.cs" />
<Compile Include="NmeaParser.cs" />
<Compile Include="NMEAMessages\GpggaMessage.cs" />
<Compile Include="NMEAMessages\Base\NmeaMessage.cs" />
Expand Down
28 changes: 21 additions & 7 deletions NMEAParser/Ghostware.NMEAParser/Ghostware.NMEAParser.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@
<package >
<metadata>
<id>Ghostware.NMEAParser</id>
<version>1.0.3</version>
<version>1.0.5</version>
<title>Ghostware.NMEAParser</title>
<authors>Ghosttje</authors>
<authors>Kevin Goos</authors>
<owners>Ghostware</owners>
<projectUrl>https://github.com/GhostwareDev/NMEAParser</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A library for parsing NMEA messages in C# classes.</description>
<releaseNotes>
v1.0.5:
--------
- Added GPGSA and GPVTG messages
- Most doubles are now floats
- Fix some bugs
- Made unittests

v1.0.4:
--------
- Fix for calculating latitude and longitude

v1.0.3:
--------
- Now the parser gives null back instead of an exception when it not an nmea exception.
- Now the parser gives null back instead of an exception when it not an nmea exception

v1.0.2:
--------
- Fixed parsing latitude and longitude (using degrees).
- Fixed parsing latitude and longitude (using degrees)

v1.0.1:
--------
- Fixed exception namespace.
- Fixed exception namespace

v1.0.0:
--------
- Initial start of the project.
- Initial start of the project
</releaseNotes>
<copyright>Copyright 2016</copyright>
<copyright>Copyright © Ghostware 2016</copyright>
<tags>GPSD</tags>
</metadata>
</package>
20 changes: 10 additions & 10 deletions NMEAParser/Ghostware.NMEAParser/NMEAMessages/GpggaMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public class GpggaMessage : NmeaMessage
/// <summary>
/// Horizontal dilution of position
/// </summary>
public double Hdop { get; set; }
public float Hdop { get; set; }

/// <summary>
/// Altitude, Meters, above mean sea level
/// </summary>
public double Altitude { get; set; }
public float Altitude { get; set; }

/// <summary>
/// Altitude units ('M' for Meters)
Expand All @@ -69,14 +69,14 @@ public class GpggaMessage : NmeaMessage
/// <summary>
/// Height of geoid (mean sea level) above WGS84
/// </summary>
public double HeightOfGeoId { get; set; }
public float HeightOfGeoId { get; set; }

public string HeightOfGeoIdUnits { get; set; }

/// <summary>
/// Time in seconds since last DGPS update
/// </summary>
public TimeSpan? TimeSpanSinceDgpsUpdate { get; set; }
public int TimeSpanSinceDgpsUpdate { get; set; }

/// <summary>
/// DGPS station ID number
Expand All @@ -98,20 +98,20 @@ public override void Parse(string[] messageParts)
Longitude = messageParts[4].ToCoordinates(messageParts[5], CoordinateType.Longitude);
FixQuality = (GpsFixQuality)Enum.Parse(typeof(GpsFixQuality), messageParts[6]);
NumberOfSatellites = messageParts[7].ToInteger();
Hdop = messageParts[8].ToDouble();
Altitude = messageParts[9].ToDouble();
Hdop = messageParts[8].ToFloat();
Altitude = messageParts[9].ToFloat();
AltitudeUnits = messageParts[10];
HeightOfGeoId = messageParts[11].ToDouble();
HeightOfGeoId = messageParts[11].ToFloat();
HeightOfGeoIdUnits = messageParts[12];
//TimeSpanSinceDgpsUpdate = !string.IsNullOrEmpty(messageParts[12]) ? TimeSpan.Parse(messageParts[12]) : TimeSpan.Zero;
DgpsStationId = messageParts[13].ToInteger();
TimeSpanSinceDgpsUpdate = messageParts[13].ToInteger();
DgpsStationId = messageParts[14].ToInteger();
}

#endregion

public override string ToString()
{
return $"Latitude {Latitude} - Longitude {Longitude}";
return $"Latitude {Latitude} - Longitude {Longitude} - Hoogte {Altitude}";
}
}
}
92 changes: 92 additions & 0 deletions NMEAParser/Ghostware.NMEAParser/NMEAMessages/GpgsaMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using Ghostware.NMEAParser.Enums;
using Ghostware.NMEAParser.Extensions;
using Ghostware.NMEAParser.NMEAMessages.Base;

namespace Ghostware.NMEAParser.NMEAMessages
{
public class GpgsaMessage : NmeaMessage
{
#region Description

// $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39

// Where:
// GSA Satellite status
// A Auto selection of 2D or 3D fix(M = manual)
// 3 3D fix - values include: 1 = no fix
// 2 = 2D fix
// 3 = 3D fix
// 04,05... PRNs of satellites used for fix(space for 12)
// 2.5 PDOP(dilution of precision)
// 1.3 Horizontal dilution of precision(HDOP)
// 2.1 Vertical dilution of precision(VDOP)
// *39 the checksum data, always begins with*

#endregion

#region Properties

/// <summary>
/// Auto selection of 2D or 3D fix(M = manual)
/// </summary>
public bool GpsStatusAuto { get; set; }

/// <summary>
/// 3D fix - values include: 1 = no fix
// 2 = 2D fix
// 3 = 3D fix
/// </summary>
public SatelliteFixType SatelliteFix { get; set; }

/// <summary>
/// PRNs of satellites used for fix(space for 12)
/// </summary>
public string Pnrs { get; set; }

/// <summary>
/// PDOP(dilution of precision)
/// </summary>
public float Pdop { get; set; }


/// <summary>
/// Horizontal dilution of precision(HDOP)
/// </summary>
public float Hdop { get; set; }

/// <summary>
/// Vertical dilution of precision(VDOP)
/// </summary>
public float Vdop { get; set; }

#endregion

#region Message parsing

public override void Parse(string[] messageParts)
{
if (messageParts == null || messageParts.Length < 9)
{
throw new ArgumentException("Invalid GPGSA message");
}
GpsStatusAuto = messageParts[1].ToBoolean("A");
SatelliteFix = (SatelliteFixType)Enum.Parse(typeof(SatelliteFixType), messageParts[2]);
for (var i = 0 + 3; i < 12 + 3; i++)
{
Pnrs += $"{messageParts[i]},";
}

Pdop = messageParts[15].ToFloat();
Hdop = messageParts[16].ToFloat();
Vdop = messageParts[17].ToFloat();
}

#endregion

public override string ToString()
{
return $"Status {GpsStatusAuto} - Satellite Fix Type {SatelliteFix}";
}
}
}
22 changes: 14 additions & 8 deletions NMEAParser/Ghostware.NMEAParser/NMEAMessages/GprmcMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public class GprmcMessage : NmeaMessage
/// <summary>
/// Speed over the ground in knots
/// </summary>
public double Speed { get; set; }
public float Speed { get; set; }

/// <summary>
/// Track angle in degrees True
/// </summary>
public double Course { get; set; }
public float Course { get; set; }

/// <summary>
/// Date - 23rd of March 1994
Expand All @@ -57,7 +57,12 @@ public class GprmcMessage : NmeaMessage
/// <summary>
/// Magnetic Variation
/// </summary>
public double MagneticVariation { get; set; }
public float MagneticVariation { get; set; }

/// <summary>
/// Magnetic Variation Unit
/// </summary>
public string MagneticVariationUnit { get; set; }

#endregion

Expand All @@ -70,20 +75,21 @@ public override void Parse(string[] messageParts)
throw new ArgumentException("Invalid GPGGA message");
}
FixTime = messageParts[1].ToTimeSpan();
IsActive = messageParts[2] == "A";
IsActive = messageParts[2].ToBoolean("A");
Latitude = messageParts[3].ToCoordinates(messageParts[4], CoordinateType.Latitude);
Longitude = messageParts[5].ToCoordinates(messageParts[6], CoordinateType.Longitude);
Speed = messageParts[7].ToDouble();
Course = messageParts[8].ToDouble();
Speed = messageParts[7].ToFloat();
Course = messageParts[8].ToFloat();
UpdateDate = DateTime.ParseExact(messageParts[9], "ddMMyy", CultureInfo.InvariantCulture);
MagneticVariation = messageParts[10].ToDouble();
MagneticVariation = messageParts[10].ToFloat();
MagneticVariationUnit = messageParts[11];
}

#endregion

public override string ToString()
{
return $"Latitude {Latitude} - Longitude {Longitude}";
return $"Latitude {Latitude} - Longitude {Longitude} - Speed {Speed}";
}
}
}
69 changes: 69 additions & 0 deletions NMEAParser/Ghostware.NMEAParser/NMEAMessages/GpvtgMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using Ghostware.NMEAParser.Extensions;
using Ghostware.NMEAParser.NMEAMessages.Base;

namespace Ghostware.NMEAParser.NMEAMessages
{
public class GpvtgMessage : NmeaMessage
{
#region Description

// $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48

// where:
// VTG Track made good and ground speed
// 054.7,T True track made good(degrees)
// 034.4,M Magnetic track made good
// 005.5,N Ground speed, knots
// 010.2,K Ground speed, Kilometers per hour
// *48 Checksum

#endregion

#region Properties

/// <summary>
/// True track made good(degrees)
/// </summary>
public float TrackDegrees { get; set; }

/// <summary>
/// Magnetic track made good
/// </summary>
public float MagneticTrack { get; set; }

/// <summary>
/// Ground speed, knots
/// </summary>
public float GroundSpeetKnots { get; set; }

/// <summary>
/// Ground speed, Kilometers per hour
/// </summary>
public float GroundSpeed { get; set; }

#endregion

#region Message parsing

public override void Parse(string[] messageParts)
{
//$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K * 48
if (messageParts == null || messageParts.Length < 9)
{
throw new ArgumentException("Invalid GPVTG message");
}
TrackDegrees = messageParts[1].ToFloat();
MagneticTrack = messageParts[3].ToFloat();
GroundSpeetKnots = messageParts[5].ToFloat();
GroundSpeed = messageParts[7].ToFloat();
}

#endregion

public override string ToString()
{
return $"Speed {GroundSpeed} - Track level {TrackDegrees}";
}
}
}
Loading

0 comments on commit c6ab45d

Please sign in to comment.