From 9c37a40bc0b36da3f57f23781b739b4b9351aa55 Mon Sep 17 00:00:00 2001 From: mort5161 Date: Fri, 14 Nov 2014 17:36:46 -0800 Subject: [PATCH] Addressed all code analysis warnings (note: Some minor breaking changes to follow naming guidelines) --- src/CustomDictionary.xml | 37 +++++++++ src/GlobalSuppressions.cs | Bin 0 -> 3620 bytes src/NmeaParser.Shared/BufferedStreamDevice.cs | 45 ++++++----- src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs | 13 ++-- src/NmeaParser.Shared/Nmea/Gps/GPGGA.cs | 23 ++++-- src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs | 12 +-- src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs | 36 +++++---- src/NmeaParser.Shared/Nmea/Gps/GPGSV.cs | 33 ++++---- src/NmeaParser.Shared/Nmea/Gps/GPRMB.cs | 20 +++-- src/NmeaParser.Shared/Nmea/Gps/GPRMC.cs | 18 +++-- src/NmeaParser.Shared/Nmea/Gps/GPRTE.cs | 17 +++-- .../Nmea/Gps/Garmin/PGRME.cs | 6 +- .../Nmea/Gps/Garmin/PGRMZ.cs | 6 +- .../Nmea/LaserRange/LaserRangeMessage.cs | 3 + .../Nmea/LaserRange/LaserTech/PLTIT.cs | 3 +- .../Nmea/LaserRange/Trimble/PTNLA.cs | 3 +- .../Nmea/LaserRange/Trimble/PTNLB.cs | 6 +- src/NmeaParser.Shared/Nmea/NmeaMessage.cs | 72 +++++++++--------- src/NmeaParser.Shared/Nmea/UnknownMessage.cs | 4 +- src/NmeaParser.Shared/NmeaDevice.cs | 21 +++-- src/NmeaParser.Shared/NmeaFileDevice.cs | 33 +++++--- .../Properties/AssemblyInfo.cs | 4 +- src/NmeaParser.Shared/StreamDevice.cs | 5 +- src/NmeaParser.Tests/DeviceTests.cs | 6 +- src/NmeaParser.Tests/NmeaMessages.cs | 56 +++++++------- .../NmeaParser.WinDesktop.csproj | 11 +++ .../NmeaParser.WinPhone.csproj | 11 +++ src/NmeaParser.WinStore/BluetoothDevice.cs | 2 + .../NmeaParser.WinStore.csproj | 12 +++ src/NmeaParser.sln | 8 +- src/SampleApp.WinDesktop/MainWindow.xaml.cs | 2 +- 31 files changed, 347 insertions(+), 181 deletions(-) create mode 100644 src/CustomDictionary.xml create mode 100644 src/GlobalSuppressions.cs diff --git a/src/CustomDictionary.xml b/src/CustomDictionary.xml new file mode 100644 index 0000000..1c8564a --- /dev/null +++ b/src/CustomDictionary.xml @@ -0,0 +1,37 @@ + + + + Nmea + + + Gps + + + Dgps + + + + + diff --git a/src/GlobalSuppressions.cs b/src/GlobalSuppressions.cs new file mode 100644 index 0000000000000000000000000000000000000000..e44cc61e8c32caff40db6501a76f58e34b5fe7ab GIT binary patch literal 3620 zcmeH~L2KJU5QXPl=zkD8wU9VX=qZpxNO4-IL#RzlDLtsR;;6CYU`Z+d^KHL3Ya!WA z3oX6`OmHOa%+9=h`(`!z_4CM%EV7Z^T4p78H(Y0yau=R!MpK*c{LPm9zpyz^vY%UF z3BF4_f^UT_vYgQjTeZ4IHniIA`CBlrnvwPNNxL&gy`dT0Gn-R6#z?l)Fa0DrF6+LBk~V*U7SG7nk&sV00=o4*3tTk$Tc#VmD8BY>3Okh@l1IBU zwmZfHa{-U`zu9-Gq_wta{-&{@p_=Fwk(Biw>_Kl0x_C=*(T3(?pV=_n#oD5X?VaP> zRByvXpRB5sxWi~=CQY{A!Hp9 zyRFUOd*#^@yLOxST7bA2?b&XMWfEew_J{cOB|-!n=5{_kYv7-m~g6=e%Wg zdi1%geMG%@=yjf+mXGZ<9mc>|uzDGWC)oLg7clzSem(H})iM4zF8+ieDkpKVy literal 0 HcmV?d00001 diff --git a/src/NmeaParser.Shared/BufferedStreamDevice.cs b/src/NmeaParser.Shared/BufferedStreamDevice.cs index 30b3209..b230f26 100644 --- a/src/NmeaParser.Shared/BufferedStreamDevice.cs +++ b/src/NmeaParser.Shared/BufferedStreamDevice.cs @@ -32,10 +32,16 @@ namespace NmeaParser BufferedStream m_stream; int m_readSpeed; /// - /// + /// Initializes a new instance of the class. + /// + protected BufferedStreamDevice() : this(200) + { + } + /// + /// Initializes a new instance of the class. /// /// The time to wait between each line being read in milliseconds - protected BufferedStreamDevice( int readSpeed = 200) + protected BufferedStreamDevice(int readSpeed) { m_readSpeed = readSpeed; } @@ -44,6 +50,7 @@ namespace NmeaParser /// Gets the stream to perform buffer reads on. /// /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] protected abstract Task GetStreamAsync(); /// @@ -74,8 +81,8 @@ namespace NmeaParser private class BufferedStream : Stream { StreamReader m_sr; - byte[] buffer = new byte[0]; - System.Threading.Timer timer; + byte[] m_buffer = new byte[0]; + System.Threading.Timer m_timer; object lockObj = new object(); /// /// Initializes a new instance of the class. @@ -85,7 +92,7 @@ namespace NmeaParser public BufferedStream(StreamReader stream, int readSpeed) { m_sr = stream; - timer = new System.Threading.Timer(OnRead, null, 0, readSpeed); //add a new line to buffer every 100 ms + m_timer = new System.Threading.Timer(OnRead, null, 0, readSpeed); //add a new line to buffer every 100 ms } private void OnRead(object state) { @@ -97,10 +104,10 @@ namespace NmeaParser var bytes = Encoding.UTF8.GetBytes(line); lock (lockObj) { - byte[] newBuffer = new byte[buffer.Length + bytes.Length]; - buffer.CopyTo(newBuffer, 0); - bytes.CopyTo(newBuffer, buffer.Length); - buffer = newBuffer; + byte[] newBuffer = new byte[m_buffer.Length + bytes.Length]; + m_buffer.CopyTo(newBuffer, 0); + bytes.CopyTo(newBuffer, m_buffer.Length); + m_buffer = newBuffer; } } /// @@ -162,19 +169,19 @@ namespace NmeaParser { lock (lockObj) { - if (this.buffer.Length <= count) + if (this.m_buffer.Length <= count) { - int length = this.buffer.Length; - this.buffer.CopyTo(buffer, 0); - this.buffer = new byte[0]; + int length = this.m_buffer.Length; + this.m_buffer.CopyTo(buffer, 0); + this.m_buffer = new byte[0]; return length; } else { - Array.Copy(this.buffer, buffer, count); - byte[] newBuffer = new byte[this.buffer.Length - count]; - Array.Copy(this.buffer, count, newBuffer, 0, newBuffer.Length); - this.buffer = newBuffer; + Array.Copy(this.m_buffer, buffer, count); + byte[] newBuffer = new byte[this.m_buffer.Length - count]; + Array.Copy(this.m_buffer, count, newBuffer, 0, newBuffer.Length); + this.m_buffer = newBuffer; return count; } } @@ -203,7 +210,7 @@ namespace NmeaParser } /// - /// Writes the specified buffer. + /// Writes the specified buffer to the device. /// /// The buffer. /// The offset. @@ -222,7 +229,7 @@ namespace NmeaParser { base.Dispose(disposing); m_sr.Dispose(); - timer.Dispose(); + m_timer.Dispose(); } } } diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs b/src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs index b53d84b..0e9c1b6 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPBOD.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps /// /// Bearing Origin to Destination /// - [NmeaMessageType(Type = "GPBOD")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpbod")] + [NmeaMessageType("GPBOD")] public class Gpbod : NmeaMessage { /// @@ -35,6 +36,8 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 3) + throw new ArgumentException("Invalid GPBOD", "message"); if (message[0].Length > 0) TrueBearing = double.Parse(message[0], CultureInfo.InvariantCulture); else @@ -44,9 +47,9 @@ namespace NmeaParser.Nmea.Gps else MagneticBearing = double.NaN; if (message.Length > 4 && !string.IsNullOrEmpty(message[4])) - DestinationID = message[4]; + DestinationId = message[4]; if (message.Length > 5 && !string.IsNullOrEmpty(message[5])) - OriginID = message[5]; + OriginId = message[5]; } /// /// True Bearing from start to destination @@ -61,11 +64,11 @@ namespace NmeaParser.Nmea.Gps /// /// Name of origin /// - public string OriginID { get; set; } + public string OriginId { get; set; } /// /// Name of destination /// - public string DestinationID { get; set; } + public string DestinationId { get; set; } } } diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPGGA.cs b/src/NmeaParser.Shared/Nmea/Gps/GPGGA.cs index 62b6420..b35f0b9 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPGGA.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPGGA.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps /// /// Global Positioning System Fix Data /// - [NmeaMessageType(Type = "GPGGA")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpgga")] + [NmeaMessageType("GPGGA")] public class Gpgga : NmeaMessage { /// @@ -39,12 +40,16 @@ namespace NmeaParser.Nmea.Gps /// GPS GpsFix = 1, /// Differential GPS + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dgps")] DgpsFix = 2, /// Precise Positioning Service + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pps")] PpsFix = 3, /// Real Time Kinematic (Fixed) + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rtk")] Rtk = 4, /// Real Time Kinematic (Floating) + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rtk")] FloatRtk = 5, /// Estimated Estimated = 6, @@ -60,7 +65,8 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { - var time = message[0]; + if (message == null || message.Length < 14) + throw new ArgumentException("Invalid GPGGA", "message"); Latitude = NmeaMessage.StringToLatitude(message[1], message[2]); Longitude = NmeaMessage.StringToLongitude(message[3], message[4]); Quality = (FixQuality)int.Parse(message[5], CultureInfo.InvariantCulture); @@ -72,14 +78,14 @@ namespace NmeaParser.Nmea.Gps HeightOfGeoidUnits = message[11]; 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))); + TimeSinceLastDgpsUpdate = new TimeSpan(int.Parse(message[0].Substring(0, 2), CultureInfo.InvariantCulture), + int.Parse(message[0].Substring(2, 2), CultureInfo.InvariantCulture), + int.Parse(message[0].Substring(4, 2), CultureInfo.InvariantCulture)); } if (message[13].Length > 0) - DgpsStationID = int.Parse(message[13], CultureInfo.InvariantCulture); + DgpsStationId = int.Parse(message[13], CultureInfo.InvariantCulture); else - DgpsStationID = -1; + DgpsStationId = -1; } /// @@ -105,6 +111,7 @@ namespace NmeaParser.Nmea.Gps /// /// Horizontal Dilution of Precision /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hdop")] public double Hdop { get; private set; } /// @@ -135,6 +142,6 @@ namespace NmeaParser.Nmea.Gps /// /// DGPS Station ID Number /// - public int DgpsStationID { get; set; } + public int DgpsStationId { get; set; } } } diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs b/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs index 148974a..07e2b56 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPGLL.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps /// /// Geographic position, latitude / longitude /// - [NmeaMessageType(Type = "GPGLL")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpgll")] + [NmeaMessageType("GPGLL")] public class Gpgll : NmeaMessage { /// @@ -35,14 +36,15 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { - var time = message[0]; + if (message == null || message.Length < 4) + throw new ArgumentException("Invalid GPGLL", "message"); 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))); + FixTime = new TimeSpan(int.Parse(message[4].Substring(0, 2), CultureInfo.InvariantCulture), + int.Parse(message[4].Substring(2, 2), CultureInfo.InvariantCulture), + int.Parse(message[4].Substring(4, 2), CultureInfo.InvariantCulture)); } DataActive = (message.Length < 6 || message[5] == "A"); } diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs b/src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs index f90d048..648fc11 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPGSA.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps /// /// Global Positioning System Fix Data /// - [NmeaMessageType(Type = "GPGSA")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpgsa")] + [NmeaMessageType("GPGSA")] public class Gpgsa : NmeaMessage { /// @@ -46,6 +47,7 @@ namespace NmeaParser.Nmea.Gps /// /// Fix Mode /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Justification = "Enum values matches NMEA spec")] public enum Mode : int { /// @@ -55,11 +57,11 @@ namespace NmeaParser.Nmea.Gps /// /// 2D Fix /// - _2D = 2, + Fix2D = 2, /// /// 3D Fix /// - _3D = 3 + Fix3D = 3 } /// @@ -68,8 +70,11 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 17) + throw new ArgumentException("Invalid GPGSA", "message"); + GpsMode = message[0] == "A" ? ModeSelection.Auto : ModeSelection.Manual; - FixMode = (Mode)int.Parse(message[1]); + FixMode = (Mode)int.Parse(message[1], CultureInfo.InvariantCulture); List svs = new List(); for (int i = 2; i < 14; i++) @@ -82,19 +87,19 @@ namespace NmeaParser.Nmea.Gps double tmp; if (double.TryParse(message[14], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) - PDop = tmp; + Pdop = tmp; else - PDop = double.NaN; + Pdop = double.NaN; if (double.TryParse(message[15], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) - HDop = tmp; + Hdop = tmp; else - HDop = double.NaN; + Hdop = double.NaN; if (double.TryParse(message[16], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) - VDop = tmp; + Vdop = tmp; else - VDop = double.NaN; + Vdop = double.NaN; } /// @@ -110,21 +115,24 @@ namespace NmeaParser.Nmea.Gps /// /// IDs of SVs used in position fix /// - public int[] SVs { get; private set; } + public IReadOnlyList SVs { get; private set; } /// /// Dilution of precision /// - public double PDop { get; private set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pdop")] + public double Pdop { get; private set; } /// /// Horizontal dilution of precision /// - public double HDop { get; private set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Hdop")] + public double Hdop { get; private set; } /// /// Vertical dilution of precision /// - public double VDop { get; private set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Vdop")] + public double Vdop { get; private set; } } } diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPGSV.cs b/src/NmeaParser.Shared/Nmea/Gps/GPGSV.cs index 023fda8..bd47247 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPGSV.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPGSV.cs @@ -26,8 +26,10 @@ namespace NmeaParser.Nmea.Gps /// /// GPS Satellites in view /// - [NmeaMessageType(Type = "GPGSV")] - public sealed class Gpgsv : NmeaMessage, IMultiPartMessage + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpgsv")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] + [NmeaMessageType("GPGSV")] + public sealed class Gpgsv : NmeaMessage, IMultiPartMessage { /// /// Called when the message is being loaded. @@ -35,17 +37,20 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { - TotalMessages = int.Parse(message[0]); - MessageNumber = int.Parse(message[1]); - SVsInView = int.Parse(message[2]); + if (message == null || message.Length < 3) + throw new ArgumentException("Invalid GPGSV", "message"); + + TotalMessages = int.Parse(message[0], CultureInfo.InvariantCulture); + MessageNumber = int.Parse(message[1], CultureInfo.InvariantCulture); + SVsInView = int.Parse(message[2], CultureInfo.InvariantCulture); - List svs = new List(); + List svs = new List(); for (int i = 3; i < message.Length - 4; i += 4) { if (message[i].Length == 0) continue; else - svs.Add(new SatelitteVehicle(message, i)); + svs.Add(new SatelliteVehicle(message, i)); } this.SVs = svs.ToArray(); } @@ -68,13 +73,13 @@ namespace NmeaParser.Nmea.Gps /// /// Dilution of precision /// - public SatelitteVehicle[] SVs { get; private set; } + public IReadOnlyList SVs { get; private set; } /// /// Returns an enumerator that iterates through the collection. /// - /// A System.Collections.Generic.IEnumerator{SatelitteVehicle} that can be used to iterate through the collection. - public IEnumerator GetEnumerator() + /// A System.Collections.Generic.IEnumerator{SatelliteVehicle} that can be used to iterate through the collection. + public IEnumerator GetEnumerator() { foreach(var sv in SVs) yield return sv; @@ -93,11 +98,11 @@ namespace NmeaParser.Nmea.Gps /// /// Satellite vehicle /// - public sealed class SatelitteVehicle + public sealed class SatelliteVehicle { - internal SatelitteVehicle(string[] message, int startIndex) + internal SatelliteVehicle(string[] message, int startIndex) { - PrnNumber = int.Parse(message[startIndex]); + PrnNumber = int.Parse(message[startIndex], CultureInfo.InvariantCulture); Elevation = double.Parse(message[startIndex+1], CultureInfo.InvariantCulture); Azimuth = double.Parse(message[startIndex + 2], CultureInfo.InvariantCulture); int snr = -1; @@ -155,10 +160,12 @@ namespace NmeaParser.Nmea.Gps /// /// WAAS - Wide Area Augmentation System /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Waas")] Waas, /// /// GLONASS - Globalnaya navigatsionnaya sputnikovaya sistema /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Glonass")] Glonass } } diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPRMB.cs b/src/NmeaParser.Shared/Nmea/Gps/GPRMB.cs index 86bd850..edb11f4 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPRMB.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPRMB.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps /// /// Recommended minimum navigation information /// - [NmeaMessageType(Type = "GPRMB")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprmb")] + [NmeaMessageType("GPRMB")] public class Gprmb : NmeaMessage { /// @@ -35,9 +36,9 @@ namespace NmeaParser.Nmea.Gps public enum DataStatus { /// - /// OK + /// Ok /// - OK, + Ok, /// /// Warning /// @@ -49,7 +50,10 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { - Status = message[0] == "A" ? DataStatus.OK : Gprmb.DataStatus.Warning; + if (message == null || message.Length < 13) + throw new ArgumentException("Invalid GPRMB", "message"); + + Status = message[0] == "A" ? DataStatus.Ok : Gprmb.DataStatus.Warning; double tmp; if (double.TryParse(message[1], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) { @@ -62,9 +66,9 @@ namespace NmeaParser.Nmea.Gps CrossTrackError = double.NaN; if(message[3].Length > 0) - OriginWaypointID = int.Parse(message[3], CultureInfo.InvariantCulture); + OriginWaypointId = int.Parse(message[3], CultureInfo.InvariantCulture); if (message[3].Length > 0) - DestinationWaypointID = int.Parse(message[4], CultureInfo.InvariantCulture); + DestinationWaypointId = int.Parse(message[4], CultureInfo.InvariantCulture); DestinationLatitude = NmeaMessage.StringToLatitude(message[5], message[6]); DestinationLongitude = NmeaMessage.StringToLongitude(message[7], message[8]); if (double.TryParse(message[9], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) @@ -95,12 +99,12 @@ namespace NmeaParser.Nmea.Gps /// /// Origin waypoint ID /// - public double OriginWaypointID { get; private set; } + public double OriginWaypointId { get; private set; } /// /// Destination waypoint ID /// - public double DestinationWaypointID { get; private set; } + public double DestinationWaypointId { get; private set; } /// /// Destination Latitude diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPRMC.cs b/src/NmeaParser.Shared/Nmea/Gps/GPRMC.cs index b0d3291..3455716 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPRMC.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPRMC.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps /// /// Recommended Minimum /// - [NmeaMessageType(Type = "GPRMC")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprmc")] + [NmeaMessageType("GPRMC")] public class Gprmc : NmeaMessage { /// @@ -35,14 +36,17 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 11) + throw new ArgumentException("Invalid GPRMC", "message"); + if (message[8].Length == 6 && message[0].Length == 6) { - FixTime = new DateTime(int.Parse(message[8].Substring(4, 2)) + 2000, - int.Parse(message[8].Substring(2, 2)), - int.Parse(message[8].Substring(0, 2)), - int.Parse(message[0].Substring(0, 2)), - int.Parse(message[0].Substring(2, 2)), - int.Parse(message[0].Substring(4, 2)), DateTimeKind.Utc); + FixTime = new DateTime(int.Parse(message[8].Substring(4, 2), CultureInfo.InvariantCulture) + 2000, + int.Parse(message[8].Substring(2, 2), CultureInfo.InvariantCulture), + int.Parse(message[8].Substring(0, 2), CultureInfo.InvariantCulture), + int.Parse(message[0].Substring(0, 2), CultureInfo.InvariantCulture), + int.Parse(message[0].Substring(2, 2), CultureInfo.InvariantCulture), + int.Parse(message[0].Substring(4, 2), CultureInfo.InvariantCulture), DateTimeKind.Utc); } Active = (message[1] == "A"); Latitude = NmeaMessage.StringToLatitude(message[2], message[3]); diff --git a/src/NmeaParser.Shared/Nmea/Gps/GPRTE.cs b/src/NmeaParser.Shared/Nmea/Gps/GPRTE.cs index 0e874a6..9048bb7 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/GPRTE.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/GPRTE.cs @@ -26,7 +26,9 @@ namespace NmeaParser.Nmea.Gps /// /// Routes /// - [NmeaMessageType(Type = "GPRTE")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprte")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] + [NmeaMessageType("GPRTE")] public sealed class Gprte : NmeaMessage, IMultiPartMessage { /// @@ -49,10 +51,13 @@ namespace NmeaParser.Nmea.Gps /// The NMEA message values. protected override void OnLoadMessage(string[] message) { - TotalMessages = int.Parse(message[0]); - MessageNumber = int.Parse(message[1]); + if (message == null || message.Length < 4) + throw new ArgumentException("Invalid GPRTE", "message"); + + TotalMessages = int.Parse(message[0], CultureInfo.InvariantCulture); + MessageNumber = int.Parse(message[1], CultureInfo.InvariantCulture); ListType = message[2] == "c" ? WaypointListType.CompleteWaypointsList : WaypointListType.RemainingWaypointsList; - RouteID = message[3]; + RouteId = message[3]; Waypoints = message.Skip(4).ToArray(); } @@ -74,12 +79,12 @@ namespace NmeaParser.Nmea.Gps /// /// Gets the route identifier. /// - public string RouteID { get; private set; } + public string RouteId { get; private set; } /// /// Waypoints /// - public string[] Waypoints { get; private set; } + public IReadOnlyList Waypoints { get; private set; } /// /// Returns an enumerator that iterates through the collection. diff --git a/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRME.cs b/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRME.cs index 34fd7da..4f7bcf7 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRME.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRME.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps.Garmin /// /// Recommended Minimum /// - [NmeaMessageType(Type = "PGRME")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pgrme")] + [NmeaMessageType("PGRME")] public class Pgrme : NmeaMessage { /// @@ -35,6 +36,9 @@ namespace NmeaParser.Nmea.Gps.Garmin /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 6) + throw new ArgumentException("Invalid PGRME", "message"); + HorizontalError = NmeaMessage.StringToDouble(message[0]); HorizontalErrorUnits = message[1]; VerticalError = NmeaMessage.StringToDouble(message[2]); diff --git a/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs b/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs index afdb658..ce5ad80 100644 --- a/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs +++ b/src/NmeaParser.Shared/Nmea/Gps/Garmin/PGRMZ.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.Gps.Garmin /// /// Altitude Information /// - [NmeaMessageType(Type = "PGRMZ")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pgrmz")] + [NmeaMessageType("PGRMZ")] public class Pgrmz : NmeaMessage { /// @@ -67,6 +68,9 @@ namespace NmeaParser.Nmea.Gps.Garmin /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 3) + throw new ArgumentException("Invalid PGRMZ", "message"); + if (message[0].Length > 0) Altitude = double.Parse(message[0], CultureInfo.InvariantCulture); else diff --git a/src/NmeaParser.Shared/Nmea/LaserRange/LaserRangeMessage.cs b/src/NmeaParser.Shared/Nmea/LaserRange/LaserRangeMessage.cs index 991625b..6edde48 100644 --- a/src/NmeaParser.Shared/Nmea/LaserRange/LaserRangeMessage.cs +++ b/src/NmeaParser.Shared/Nmea/LaserRange/LaserRangeMessage.cs @@ -35,6 +35,9 @@ namespace NmeaParser.Nmea.LaserRange /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 9) + throw new ArgumentException("Invalid Laser Range Message", "message"); + HorizontalVector = message[0]; HorizontalDistance = double.Parse(message[1], CultureInfo.InvariantCulture); HorizontalDistanceUnits = message[2][0]; diff --git a/src/NmeaParser.Shared/Nmea/LaserRange/LaserTech/PLTIT.cs b/src/NmeaParser.Shared/Nmea/LaserRange/LaserTech/PLTIT.cs index 65ade5c..aadbd95 100644 --- a/src/NmeaParser.Shared/Nmea/LaserRange/LaserTech/PLTIT.cs +++ b/src/NmeaParser.Shared/Nmea/LaserRange/LaserTech/PLTIT.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.LaserRange.LaserTech /// /// Laser Range /// - [NmeaMessageType(Type = "PLTIT")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pltit")] + [NmeaMessageType("PLTIT")] public class Pltit : LaserRangeMessage { } diff --git a/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLA.cs b/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLA.cs index 451ad8e..89a05c3 100644 --- a/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLA.cs +++ b/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLA.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.LaserRange.Trimble /// /// Burden finder /// - [NmeaMessageType(Type = "PTNLA")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ptnla")] + [NmeaMessageType("PTNLA")] public class Ptnla : LaserRangeMessage { } diff --git a/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLB.cs b/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLB.cs index e400b89..c10975a 100644 --- a/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLB.cs +++ b/src/NmeaParser.Shared/Nmea/LaserRange/Trimble/PTNLB.cs @@ -26,7 +26,8 @@ namespace NmeaParser.Nmea.LaserRange.Trimble /// /// Tree Measurement /// - [NmeaMessageType(Type = "PTNLB")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Ptnlb")] + [NmeaMessageType("PTNLB")] public class Ptnlb : NmeaMessage { /// @@ -35,6 +36,9 @@ namespace NmeaParser.Nmea.LaserRange.Trimble /// The NMEA message values. protected override void OnLoadMessage(string[] message) { + if (message == null || message.Length < 6) + throw new ArgumentException("Invalid PTNLB", "message"); + TreeHeight = message[0]; MeasuredTreeHeight = double.Parse(message[1], CultureInfo.InvariantCulture); MeasuredTreeHeightUnits = message[2][0]; diff --git a/src/NmeaParser.Shared/Nmea/NmeaMessage.cs b/src/NmeaParser.Shared/Nmea/NmeaMessage.cs index 0dfe955..47cfec8 100644 --- a/src/NmeaParser.Shared/Nmea/NmeaMessage.cs +++ b/src/NmeaParser.Shared/Nmea/NmeaMessage.cs @@ -27,12 +27,21 @@ namespace NmeaParser.Nmea /// /// Nmea message attribute type used on concrete implementations. /// - public class NmeaMessageTypeAttribute : Attribute + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public sealed class NmeaMessageTypeAttribute : Attribute { + /// + /// Initializes a new instance of the class. + /// + /// The type. + public NmeaMessageTypeAttribute(string nmeaType) + { + NmeaType = nmeaType; + } /// /// Gets or sets the NMEA message type. /// - public string Type { get; set; } + public string NmeaType { get; private set; } } /// @@ -51,6 +60,9 @@ namespace NmeaParser.Nmea /// public static NmeaMessage Parse(string message) { + if (string.IsNullOrEmpty(message)) + throw new ArgumentNullException("message"); + int checksum = -1; if (message[0] != '$') throw new ArgumentException("Invalid nmea message: Missing starting character '$'"); @@ -69,7 +81,7 @@ namespace NmeaParser.Nmea checksumTest ^= Convert.ToByte(message[i]); } if (checksum != checksumTest) - throw new ArgumentException(string.Format("Invalid nmea message: Checksum failure. Got {0:X2}, Expected {1:X2}", checksum, checksumTest)); + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid nmea message: Checksum failure. Got {0:X2}, Expected {1:X2}", checksum, checksumTest)); } string[] parts = message.Split(new char[] { ',' }); @@ -110,7 +122,7 @@ namespace NmeaParser.Nmea var pinfo = c.GetParameters(); if (pinfo.Length == 0) { - messageTypes.Add(attr.Type, c); + messageTypes.Add(attr.NmeaType, c); break; } } @@ -124,10 +136,10 @@ namespace NmeaParser.Nmea /// /// Gets the NMEA message parts. /// - protected string[] MessageParts { get; private set; } + protected IReadOnlyList MessageParts { get; private set; } /// - /// Gets the type id for the message. + /// Gets the NMEA type id for the message. /// public string MessageType { get; private set; } @@ -148,47 +160,37 @@ namespace NmeaParser.Nmea /// public override string ToString() { - return string.Format("${0},{1}", MessageType, string.Join(",", MessageParts)); + return string.Format(CultureInfo.InvariantCulture, "${0},{1}", MessageType, string.Join(",", MessageParts)); } internal static double StringToLatitude(string value, string ns) { - try - { - if (value.Length < 3) - return double.NaN; - double latitude = int.Parse(value.Substring(0, 2), CultureInfo.InvariantCulture) + double.Parse(value.Substring(2), CultureInfo.InvariantCulture) / 60; - if (ns == "S") - latitude *= -1; - return latitude; - } - catch { return double.NaN; } + if (value == null || value.Length < 3) + return double.NaN; + double latitude = int.Parse(value.Substring(0, 2), CultureInfo.InvariantCulture) + double.Parse(value.Substring(2), CultureInfo.InvariantCulture) / 60; + if (ns == "S") + latitude *= -1; + return latitude; } + internal static double StringToLongitude(string value, string ew) { - try - { - if (value.Length < 4) - return double.NaN; - double longitude = int.Parse(value.Substring(0, 3), CultureInfo.InvariantCulture) + double.Parse(value.Substring(3), CultureInfo.InvariantCulture) / 60; - if (ew == "W") - longitude *= -1; - return longitude; - } - catch { return double.NaN; } + if (value == null || value.Length < 4) + return double.NaN; + double longitude = int.Parse(value.Substring(0, 3), CultureInfo.InvariantCulture) + double.Parse(value.Substring(3), CultureInfo.InvariantCulture) / 60; + if (ew == "W") + longitude *= -1; + return longitude; } + internal static double StringToDouble(string value) { - try + double result = double.NaN; + if(value != null && double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result)) { - double result = double.NaN; - if(double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out result)) - { - return result; - } - return double.NaN; + return result; } - catch { return double.NaN; } + return double.NaN; } } } diff --git a/src/NmeaParser.Shared/Nmea/UnknownMessage.cs b/src/NmeaParser.Shared/Nmea/UnknownMessage.cs index bd228d8..5c20ced 100644 --- a/src/NmeaParser.Shared/Nmea/UnknownMessage.cs +++ b/src/NmeaParser.Shared/Nmea/UnknownMessage.cs @@ -28,9 +28,9 @@ namespace NmeaParser.Nmea public class UnknownMessage : NmeaMessage { /// - /// Gets the nmea value aarray. + /// Gets the nmea value array. /// - public string[] Values { get { return base.MessageParts; } } + public IReadOnlyList Values { get { return base.MessageParts; } } /// /// Called when the message is being loaded. /// diff --git a/src/NmeaParser.Shared/NmeaDevice.cs b/src/NmeaParser.Shared/NmeaDevice.cs index 1a7b312..5e8c119 100644 --- a/src/NmeaParser.Shared/NmeaDevice.cs +++ b/src/NmeaParser.Shared/NmeaDevice.cs @@ -58,6 +58,7 @@ namespace NmeaParser MultiPartMessageCache.Clear(); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "_")] private void StartParser() { var token = m_cts.Token; @@ -127,7 +128,7 @@ namespace NmeaParser { m_message += nmea; - var lineEnd = m_message.IndexOf("\n"); + var lineEnd = m_message.IndexOf("\n", StringComparison.Ordinal); if (lineEnd > -1) { line = m_message.Substring(0, lineEnd).Trim(); @@ -138,6 +139,7 @@ namespace NmeaParser ProcessMessage(line); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification="Must silently handle invalid/corrupt input")] private void ProcessMessage(string p) { try @@ -152,10 +154,10 @@ namespace NmeaParser private void OnMessageReceived(Nmea.NmeaMessage msg) { var args = new NmeaMessageReceivedEventArgs(msg); - if (msg is IMultiPartMessage) + var multi = msg as IMultiPartMessage; + if (multi != null) { - args.IsMultiPart = true; - var multi = (IMultiPartMessage)msg; + args.IsMultipart = true; if (MultiPartMessageCache.ContainsKey(msg.MessageType)) { var dic = MultiPartMessageCache[msg.MessageType]; @@ -202,12 +204,13 @@ namespace NmeaParser public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// /// Releases unmanaged and - optionally - managed resources. /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool force) + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) { if (m_stream != null) { @@ -217,6 +220,8 @@ namespace NmeaParser m_cts = null; } CloseStreamAsync(m_stream); + if (disposing && m_stream != null) + m_stream.Dispose(); m_stream = null; } } @@ -251,13 +256,13 @@ namespace NmeaParser /// /// true if this instance is multi part; otherwise, false. /// - public bool IsMultiPart { get; internal set; } + public bool IsMultipart { get; internal set; } /// /// Gets the message parts if this is a multi-part message and all message parts has been received. /// /// /// The message parts. /// - public Nmea.NmeaMessage[] MessageParts { get; internal set; } + public IReadOnlyList MessageParts { get; internal set; } } } diff --git a/src/NmeaParser.Shared/NmeaFileDevice.cs b/src/NmeaParser.Shared/NmeaFileDevice.cs index 9b72e76..00dc125 100644 --- a/src/NmeaParser.Shared/NmeaFileDevice.cs +++ b/src/NmeaParser.Shared/NmeaFileDevice.cs @@ -33,32 +33,47 @@ namespace NmeaParser #else string m_filename; #endif - int m_readSpeed; + /// /// Initializes a new instance of the class. /// - /// - /// The time to wait between each line being read in milliseconds + /// #if NETFX_CORE - public NmeaFileDevice(Windows.Storage.IStorageFile filename, int readSpeed = 200) : base(readSpeed) + public NmeaFileDevice(Windows.Storage.IStorageFile fileName) : this(fileName, 200) #else - public NmeaFileDevice(string filename, int readSpeed = 200) : base(readSpeed) + public NmeaFileDevice(string fileName) : this(fileName, 200) #endif { - m_filename = filename; - m_readSpeed = readSpeed; + m_filename = fileName; } + /// + /// Initializes a new instance of the class. + /// + /// + /// The time to wait between each line being read in milliseconds +#if NETFX_CORE + public NmeaFileDevice(Windows.Storage.IStorageFile fileName, int readSpeed) + : base(readSpeed) +#else + public NmeaFileDevice(string fileName, int readSpeed) : base(readSpeed) +#endif + { + m_filename = fileName; + } + /// /// Gets the stream to perform buffer reads on. /// /// +#if !NETFX_CORE + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")] +#endif protected override Task GetStreamAsync() { #if NETFX_CORE return m_filename.OpenStreamForReadAsync(); #else - var sr = System.IO.File.OpenRead(m_filename); - return Task.FromResult(sr); + return Task.FromResult(System.IO.File.OpenRead(m_filename)); #endif } } diff --git a/src/NmeaParser.Shared/Properties/AssemblyInfo.cs b/src/NmeaParser.Shared/Properties/AssemblyInfo.cs index 2d134f8..82d3419 100644 --- a/src/NmeaParser.Shared/Properties/AssemblyInfo.cs +++ b/src/NmeaParser.Shared/Properties/AssemblyInfo.cs @@ -24,6 +24,6 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1.0")] -[assembly: AssemblyFileVersion("1.3.1.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/src/NmeaParser.Shared/StreamDevice.cs b/src/NmeaParser.Shared/StreamDevice.cs index f137ff6..ce2d619 100644 --- a/src/NmeaParser.Shared/StreamDevice.cs +++ b/src/NmeaParser.Shared/StreamDevice.cs @@ -59,9 +59,10 @@ namespace NmeaParser /// /// Releases unmanaged and - optionally - managed resources. /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool force) + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool disposing) { + base.Dispose(disposing); if (m_stream != null) m_stream.Dispose(); m_stream = null; diff --git a/src/NmeaParser.Tests/DeviceTests.cs b/src/NmeaParser.Tests/DeviceTests.cs index c0bcb93..bfd953d 100644 --- a/src/NmeaParser.Tests/DeviceTests.cs +++ b/src/NmeaParser.Tests/DeviceTests.cs @@ -23,13 +23,13 @@ namespace NmeaParser.Tests count++; try { - Assert.IsTrue(e.IsMultiPart, "IsMultiPart"); + Assert.IsTrue(e.IsMultipart, "IsMultiPart"); Assert.IsInstanceOfType(e.Message, typeof(NmeaParser.Nmea.Gps.Gpgsv)); var msg = e.Message as NmeaParser.Nmea.Gps.Gpgsv; if (msg.TotalMessages == msg.MessageNumber) { Assert.IsNotNull(e.MessageParts); - Assert.AreEqual(e.MessageParts.Length, 3, "MessageParts.Length"); + Assert.AreEqual(e.MessageParts.Count, 3, "MessageParts.Length"); tcs.SetResult(true); } else @@ -60,7 +60,7 @@ namespace NmeaParser.Tests count++; try { - Assert.IsTrue(e.IsMultiPart, "IsMultiPart"); + Assert.IsTrue(e.IsMultipart, "IsMultiPart"); Assert.IsInstanceOfType(e.Message, typeof(NmeaParser.Nmea.Gps.Gpgsv)); var msg = e.Message as NmeaParser.Nmea.Gps.Gpgsv; Assert.IsNull(e.MessageParts); diff --git a/src/NmeaParser.Tests/NmeaMessages.cs b/src/NmeaParser.Tests/NmeaMessages.cs index 4f904f1..132beab 100644 --- a/src/NmeaParser.Tests/NmeaMessages.cs +++ b/src/NmeaParser.Tests/NmeaMessages.cs @@ -57,10 +57,10 @@ namespace NmeaParser.Tests Assert.AreEqual(double.NaN, rmb.CrossTrackError); Assert.AreEqual(double.NaN, rmb.DestinationLatitude); Assert.AreEqual(double.NaN, rmb.DestinationLongitude); - Assert.AreEqual(0, rmb.DestinationWaypointID); - Assert.AreEqual(0, rmb.OriginWaypointID); + Assert.AreEqual(0, rmb.DestinationWaypointId); + Assert.AreEqual(0, rmb.OriginWaypointId); Assert.AreEqual(double.NaN, rmb.RangeToDestination); - Assert.AreEqual(Gprmb.DataStatus.OK, rmb.Status); + Assert.AreEqual(Gprmb.DataStatus.Ok, rmb.Status); Assert.AreEqual(double.NaN, rmb.TrueBearing); Assert.AreEqual(double.NaN, rmb.Velocity); } @@ -72,10 +72,10 @@ namespace NmeaParser.Tests var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gprmb)); Gprmb rmb = (Gprmb)msg; - Assert.AreEqual(Gprmb.DataStatus.OK, rmb.Status); + Assert.AreEqual(Gprmb.DataStatus.Ok, rmb.Status); Assert.AreEqual(-.66, rmb.CrossTrackError); - Assert.AreEqual(3, rmb.OriginWaypointID); - Assert.AreEqual(4, rmb.DestinationWaypointID); + Assert.AreEqual(3, rmb.OriginWaypointId); + Assert.AreEqual(4, rmb.DestinationWaypointId); Assert.AreEqual(-49.287333333333333333, rmb.DestinationLatitude); Assert.AreEqual(-123.1595, rmb.DestinationLongitude); Assert.AreEqual(1.3, rmb.RangeToDestination); @@ -113,7 +113,7 @@ namespace NmeaParser.Tests Assert.AreEqual("M", gga.AltitudeUnits); Assert.AreEqual(-22.1, gga.HeightOfGeoid); Assert.AreEqual("M", gga.HeightOfGeoidUnits); - Assert.AreEqual(-1, gga.DgpsStationID); + Assert.AreEqual(-1, gga.DgpsStationId); } [TestMethod] @@ -156,15 +156,15 @@ namespace NmeaParser.Tests Assert.IsInstanceOfType(msg, typeof(Gpgsa)); Gpgsa gsa = (Gpgsa)msg; Assert.AreEqual(Gpgsa.ModeSelection.Auto, gsa.GpsMode); - Assert.AreEqual(Gpgsa.Mode._3D, gsa.FixMode); - Assert.AreEqual(4, gsa.SVs.Length); + Assert.AreEqual(Gpgsa.Mode.Fix3D, gsa.FixMode); + Assert.AreEqual(4, gsa.SVs.Count); Assert.AreEqual(16, gsa.SVs[0]); Assert.AreEqual(18, gsa.SVs[1]); Assert.AreEqual(22, gsa.SVs[2]); Assert.AreEqual(24, gsa.SVs[3]); - Assert.AreEqual(double.NaN, gsa.PDop); - Assert.AreEqual(double.NaN, gsa.HDop); - Assert.AreEqual(double.NaN, gsa.VDop); + Assert.AreEqual(double.NaN, gsa.Pdop); + Assert.AreEqual(double.NaN, gsa.Hdop); + Assert.AreEqual(double.NaN, gsa.Vdop); } [TestMethod] public void TestGpgsa() @@ -174,8 +174,8 @@ namespace NmeaParser.Tests Assert.IsInstanceOfType(msg, typeof(Gpgsa)); Gpgsa gsa = (Gpgsa)msg; Assert.AreEqual(Gpgsa.ModeSelection.Manual, gsa.GpsMode); - Assert.AreEqual(Gpgsa.Mode._2D, gsa.FixMode); - Assert.AreEqual(12, gsa.SVs.Length); + Assert.AreEqual(Gpgsa.Mode.Fix2D, gsa.FixMode); + Assert.AreEqual(12, gsa.SVs.Count); Assert.AreEqual(19, gsa.SVs[0]); Assert.AreEqual(28, gsa.SVs[1]); Assert.AreEqual(14, gsa.SVs[2]); @@ -188,9 +188,9 @@ namespace NmeaParser.Tests Assert.AreEqual(42, gsa.SVs[9]); Assert.AreEqual(43, gsa.SVs[10]); Assert.AreEqual(44, gsa.SVs[11]); - Assert.AreEqual(1.7, gsa.PDop); - Assert.AreEqual(1.0, gsa.HDop); - Assert.AreEqual(1.3, gsa.VDop); + Assert.AreEqual(1.7, gsa.Pdop); + Assert.AreEqual(1.0, gsa.Hdop); + Assert.AreEqual(1.3, gsa.Vdop); } [TestMethod] @@ -204,7 +204,7 @@ namespace NmeaParser.Tests Assert.AreEqual(3, gsv.MessageNumber); Assert.AreEqual(11, gsv.SVsInView); Assert.IsNotNull(gsv.SVs); - Assert.AreEqual(3, gsv.SVs.Length); + Assert.AreEqual(3, gsv.SVs.Count); var sv = gsv.SVs[0]; Assert.AreEqual(22, sv.PrnNumber); Assert.AreEqual(42, sv.Elevation); @@ -238,7 +238,7 @@ namespace NmeaParser.Tests Assert.AreEqual(1, gsv.MessageNumber); Assert.AreEqual(0, gsv.SVsInView); Assert.IsNotNull(gsv.SVs); - Assert.AreEqual(0, gsv.SVs.Length); + Assert.AreEqual(0, gsv.SVs.Count); } [TestMethod] @@ -277,8 +277,8 @@ namespace NmeaParser.Tests 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"); + Assert.IsNull(bod.OriginId, "OriginID"); + Assert.IsNull(bod.DestinationId, "DestinationID"); } [TestMethod] @@ -290,8 +290,8 @@ namespace NmeaParser.Tests 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"); + Assert.AreEqual("POINTB", bod.DestinationId, "DestinationID"); + Assert.IsNull(bod.OriginId, "OriginID"); } @@ -304,8 +304,8 @@ namespace NmeaParser.Tests 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"); + Assert.AreEqual("POINTB", bod.DestinationId, "DestinationID"); + Assert.AreEqual("POINTA", bod.OriginId, "OriginID"); } @@ -343,9 +343,9 @@ namespace NmeaParser.Tests Assert.AreEqual(2, gsv.TotalMessages); Assert.AreEqual(1, gsv.MessageNumber); Assert.AreEqual(NmeaParser.Nmea.Gps.Gprte.WaypointListType.CompleteWaypointsList, gsv.ListType); - Assert.AreEqual("0", gsv.RouteID); - Assert.AreEqual("0", gsv.RouteID); - Assert.AreEqual(9, gsv.Waypoints.Length); + Assert.AreEqual("0", gsv.RouteId); + Assert.AreEqual("0", gsv.RouteId); + Assert.AreEqual(9, gsv.Waypoints.Count); Assert.AreEqual("W3IWI", gsv.Waypoints[0]); Assert.AreEqual("32BKLD", gsv.Waypoints[4]); Assert.AreEqual("BW-198", gsv.Waypoints[8]); diff --git a/src/NmeaParser.WinDesktop/NmeaParser.WinDesktop.csproj b/src/NmeaParser.WinDesktop/NmeaParser.WinDesktop.csproj index 7ba312e..a02fec3 100644 --- a/src/NmeaParser.WinDesktop/NmeaParser.WinDesktop.csproj +++ b/src/NmeaParser.WinDesktop/NmeaParser.WinDesktop.csproj @@ -21,6 +21,8 @@ prompt 4 ..\Bin\Debug\NmeaParser.WinDesktop.xml + true + AllRules.ruleset pdbonly @@ -30,6 +32,7 @@ prompt 4 ..\Bin\Release\NmeaParser.WinDesktop.xml + true @@ -37,10 +40,18 @@ + + GlobalSuppressions.cs + + + + CustomDictionary.xml + + + + GlobalSuppressions.cs + BluetoothDevice.cs + + + CustomDictionary.xml + + 12.0 diff --git a/src/NmeaParser.WinStore/BluetoothDevice.cs b/src/NmeaParser.WinStore/BluetoothDevice.cs index 5c1878b..d343bfb 100644 --- a/src/NmeaParser.WinStore/BluetoothDevice.cs +++ b/src/NmeaParser.WinStore/BluetoothDevice.cs @@ -74,6 +74,8 @@ namespace NmeaParser /// protected override Task CloseStreamAsync(System.IO.Stream stream) { + if (stream == null) + throw new ArgumentNullException("stream"); stream.Dispose(); m_socket.Dispose(); m_socket = null; diff --git a/src/NmeaParser.WinStore/NmeaParser.WinStore.csproj b/src/NmeaParser.WinStore/NmeaParser.WinStore.csproj index 787a262..db82e0f 100644 --- a/src/NmeaParser.WinStore/NmeaParser.WinStore.csproj +++ b/src/NmeaParser.WinStore/NmeaParser.WinStore.csproj @@ -26,6 +26,8 @@ prompt 4 ..\bin\Debug\NmeaParser.WinStore.xml + AllRules.ruleset + true pdbonly @@ -35,14 +37,24 @@ prompt 4 ..\bin\Release\NmeaParser.WinStore.xml + true + + GlobalSuppressions.cs + + + + CustomDictionary.xml + Designer + + 12.0 diff --git a/src/NmeaParser.sln b/src/NmeaParser.sln index 942a4e7..ed57078 100644 --- a/src/NmeaParser.sln +++ b/src/NmeaParser.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NmeaParser.WinStore", "NmeaParser.WinStore\NmeaParser.WinStore.csproj", "{62A55887-10F5-40D2-9352-96246D1B11D3}" EndProject @@ -33,6 +33,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SampleApps", "SampleApps", "{A4B9D59A-C8C6-4199-A7F3-F3AF0C748281}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EBBFC7B-43E8-4478-9951-50C842991A9C}" + ProjectSection(SolutionItems) = preProject + CustomDictionary.xml = CustomDictionary.xml + GlobalSuppressions.cs = GlobalSuppressions.cs + EndProjectSection +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution NmeaParser.Shared\NmeaParser.Shared.projitems*{df711ab9-f14e-4f1f-b8f2-b6ddc4691554}*SharedItemsImports = 4 diff --git a/src/SampleApp.WinDesktop/MainWindow.xaml.cs b/src/SampleApp.WinDesktop/MainWindow.xaml.cs index b4e884f..7c3d096 100644 --- a/src/SampleApp.WinDesktop/MainWindow.xaml.cs +++ b/src/SampleApp.WinDesktop/MainWindow.xaml.cs @@ -42,7 +42,7 @@ namespace SampleApp.WinDesktop if(args.Message is NmeaParser.Nmea.Gps.Gpgsv) { var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args.Message; - if(args.IsMultiPart && args.MessageParts != null) + if(args.IsMultipart && args.MessageParts != null) satView.GpgsvMessages = args.MessageParts.OfType(); } });