diff --git a/src/NmeaParser/Nmea/Dpt.cs b/src/NmeaParser/Nmea/Dpt.cs new file mode 100644 index 00000000..00286116 --- /dev/null +++ b/src/NmeaParser/Nmea/Dpt.cs @@ -0,0 +1,71 @@ +// ******************************************************************************* +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * 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.Globalization; + +namespace NmeaParser.Messages +{ + /// + /// Water depth relative to the transducer, the depth offset of the transducer, and maximum depth that the sounder can detect a sea-bed (all in metres only). + /// Positive offsets provide distance from the transducer to the water line. Negative offsets provide distance from the transducer to the keel. + /// Not all NMEA 0183 devices that output this sentence can have their depth offset changed. In this case, the depth offset will always be zero, or not included. + /// NMEA 0183 v2.0 sentences will not include the maximum depth range value at all, as it was added in v3.0. + /// + /// + /// + /// Format: $xxDPT,DATA_METRES,OFFSET_METRES, MAXIMUM_METRES*hh + /// 1.: Data + /// 2.: Offset + /// 3.: Maximum + /// + /// + /// Depth + /// + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "SdDpt")] + [NmeaMessageType("--DPT")] + public class Dpt : NmeaMessage + { + /// + /// Initializes a new instance of the class. + /// + /// The message type + /// The NMEA message values. + public Dpt(string type, string[] message) : base(type, message) + { + if (message == null || message.Length < 3) + throw new ArgumentException("Invalid Dpt", "message"); + + DepthMeters = double.Parse(message[0], CultureInfo.InvariantCulture); + DepthOffsetMeters = double.Parse(message[1], CultureInfo.InvariantCulture); + MaxDepthRangeMeters = double.Parse(message[2], CultureInfo.InvariantCulture); + } + + /// + /// Depth, in meters + /// + public double DepthMeters { get; } + + /// + /// Depth offset, in meters + /// + public double DepthOffsetMeters { get; } + + /// + /// Maximum depth range, in meters + /// + public double MaxDepthRangeMeters { get; } + } +} \ No newline at end of file diff --git a/src/NmeaParser/Nmea/Hdt.cs b/src/NmeaParser/Nmea/Hdt.cs new file mode 100644 index 00000000..8aebaf21 --- /dev/null +++ b/src/NmeaParser/Nmea/Hdt.cs @@ -0,0 +1,64 @@ +// ******************************************************************************* +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * 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.Globalization; + +namespace NmeaParser.Messages +{ + /// + /// Heading from True North + /// + /// + /// + /// 1.: Heading in degrees + /// 2.: Indicates heading relative to True North + /// + /// + /// Actual vessel heading in degrees True produced by any device or system producing true heading + /// + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "HeHdt")] + [NmeaMessageType("--HDT")] + public class Hdt : NmeaMessage + { + /// + /// Initializes a new instance of the class. + /// + /// The message type + /// The NMEA message values. + public Hdt(string type, string[] message) : base(type, message) + { + if (message == null || message.Length < 2) + throw new ArgumentException("Invalid Hdt", "message"); + + // Extract the heading in degrees + HeadingInDeg = double.TryParse(message[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var heading) + ? heading + : double.NaN; + + HeadingRelToTrueNorth = message[1] == "T"; + } + + /// + /// Heading in degrees + /// + public double HeadingInDeg { get; } + + /// + /// T: Indicates heading relative to True North + /// + public bool HeadingRelToTrueNorth { get; } + } +} \ No newline at end of file diff --git a/src/NmeaParser/Nmea/Xdr.cs b/src/NmeaParser/Nmea/Xdr.cs new file mode 100644 index 00000000..c65c60c5 --- /dev/null +++ b/src/NmeaParser/Nmea/Xdr.cs @@ -0,0 +1,71 @@ +// ******************************************************************************* +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * 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; + +namespace NmeaParser.Messages +{ + /// + /// Measurement data from transducers that measure physical quantities such as + /// temperature, force, pressure, frequency, angular or linear displacement, etc. + /// Four fields 'Type-Data-Units-ID' + /// + /// + /// + /// 1.: Transducer type + /// 2.: Measurement data + /// 3.: units of measure + /// 4.: transducer ID + /// + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xdr")] + [NmeaMessageType("--XDR")] + public class Xdr : NmeaMessage + { + /// + /// Initializes a new instance of the class. + /// + /// The message type + /// The NMEA message values. + public Xdr(string type, string[] message) : base(type, message) + { + if (message == null || message.Length < 4) + throw new ArgumentException("Invalid Xdr", "message"); + Type = message[0]; + Data = StringToDouble(message[1]); + Unit = message[2]; + ID = message[3]; + } + + /// + /// Transducer Type + /// + public string Type { get; } + + /// + /// Measurement data + /// + public double Data { get; } + + /// + /// Unit of measure + /// + public string Unit { get; } + + /// + /// ID + /// + public string ID { get; } + } +} \ No newline at end of file diff --git a/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs b/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs index b6cbc1cb..50ed8cdd 100644 --- a/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs +++ b/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs @@ -124,6 +124,18 @@ public void IgnoreChecksum() Assert.ThrowsException(() => NmeaMessage.Parse(input, ignoreChecksum: false)); } + [TestMethod] + public void TestDPT() + { + string input = "$--DPT,149.5,000.5,1000.0*7F"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(Dpt)); + Dpt dpt = (Dpt)msg; + Assert.AreEqual(149.5, dpt.DepthMeters); + Assert.AreEqual(0.5, dpt.DepthOffsetMeters); + Assert.AreEqual(1000, dpt.MaxDepthRangeMeters); + } + [TestMethod] public void TestGprma() { @@ -296,6 +308,30 @@ public void TestGPGGA_Empty() Assert.AreEqual(-1, gga.DgpsStationId); } + [TestMethod] + public void TestHEHDT() + { + const string input = "$HEHDT,13.37,T*29"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(Hdt)); + Hdt hdt = (Hdt)msg; + Assert.AreEqual(13.37, hdt.HeadingInDeg); + Assert.IsTrue(hdt.HeadingRelToTrueNorth); + } + + [TestMethod] + public void TestKMXDR() + { + string input = "$KMXDR,P,123.4,M,DEPTH*32"; + var msg = NmeaMessage.Parse(input); + Assert.IsInstanceOfType(msg, typeof(Xdr)); + Xdr xdr = (Xdr)msg; + Assert.AreEqual("P", xdr.Type); + Assert.AreEqual(123.4, xdr.Data); + Assert.AreEqual("M", xdr.Unit); + Assert.AreEqual("DEPTH", xdr.ID); + } + [TestMethod] public void TestPtlna() {