From 3678abc2c6e6846a6fc8f32a4765d5d8905389f7 Mon Sep 17 00:00:00 2001 From: Joachim Spange Date: Thu, 30 Jan 2025 14:16:55 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20XDR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/NmeaParser/Nmea/Xdr.cs | 71 +++++++++++++++++++ .../NmeaParser.Tests/NmeaMessages.cs | 13 ++++ 2 files changed, 84 insertions(+) create mode 100644 src/NmeaParser/Nmea/Xdr.cs diff --git a/src/NmeaParser/Nmea/Xdr.cs b/src/NmeaParser/Nmea/Xdr.cs new file mode 100644 index 0000000..c65c60c --- /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 446ab4a..8b9b4bf 100644 --- a/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs +++ b/src/UnitTests/NmeaParser.Tests/NmeaMessages.cs @@ -320,6 +320,19 @@ namespace NmeaParser.Tests 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() {