-
-
Notifications
You must be signed in to change notification settings - Fork 91
Support additional nmea messages #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SpangeJ
wants to merge
9
commits into
dotMorten:main
Choose a base branch
from
SpangeJ:support_additional_nmea_messages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a60ceb
✨ HDT
b79651c
✨ DPT
128a8b1
✨ Support PTNL parent NMEA message
647ff9f
✨ Parse date and time (mmddyy and hhmmss.sss) format to UTC DateTime(…
4015932
✨ PRNL,GGK
edb9f23
✅ Skip checksum test for PTNL,GGK as it fails TODO
3678abc
✨ XDR
531fe94
✨ AML,SVM
eb9904e
⏪️ evert PTNL,GGK and AML,SVM
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| { | ||
| /// <summary> | ||
| /// 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. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Format: $xxDPT,DATA_METRES,OFFSET_METRES, MAXIMUM_METRES*hh | ||
| /// 1.: Data | ||
| /// 2.: Offset | ||
| /// 3.: Maximum | ||
| /// </para> | ||
| /// <para> | ||
| /// Depth | ||
| /// </para> | ||
| /// </remarks> | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "SdDpt")] | ||
| [NmeaMessageType("--DPT")] | ||
| public class Dpt : NmeaMessage | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="Dpt"/> class. | ||
| /// </summary> | ||
| /// <param name="type">The message type</param> | ||
| /// <param name="message">The NMEA message values.</param> | ||
| 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); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Depth, in meters | ||
| /// </summary> | ||
| public double DepthMeters { get; } | ||
|
|
||
| /// <summary> | ||
| /// Depth offset, in meters | ||
| /// </summary> | ||
| public double DepthOffsetMeters { get; } | ||
|
|
||
| /// <summary> | ||
| /// Maximum depth range, in meters | ||
| /// </summary> | ||
| public double MaxDepthRangeMeters { get; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| { | ||
| /// <summary> | ||
| /// Heading from True North | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// 1.: Heading in degrees | ||
| /// 2.: Indicates heading relative to True North | ||
| /// </para> | ||
| /// <para> | ||
| /// Actual vessel heading in degrees True produced by any device or system producing true heading | ||
| /// </para> | ||
| /// </remarks> | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "HeHdt")] | ||
| [NmeaMessageType("--HDT")] | ||
| public class Hdt : NmeaMessage | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="Hdt"/> class. | ||
| /// </summary> | ||
| /// <param name="type">The message type</param> | ||
| /// <param name="message">The NMEA message values.</param> | ||
| 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"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Heading in degrees | ||
| /// </summary> | ||
| public double HeadingInDeg { get; } | ||
|
|
||
| /// <summary> | ||
| /// T: Indicates heading relative to True North | ||
| /// </summary> | ||
| public bool HeadingRelToTrueNorth { get; } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| { | ||
| /// <summary> | ||
| /// 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' | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// 1.: Transducer type | ||
| /// 2.: Measurement data | ||
| /// 3.: units of measure | ||
| /// 4.: transducer ID | ||
| /// </para> | ||
| /// </remarks> | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xdr")] | ||
| [NmeaMessageType("--XDR")] | ||
| public class Xdr : NmeaMessage | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="Xdr"/> class. | ||
| /// </summary> | ||
| /// <param name="type">The message type</param> | ||
| /// <param name="message">The NMEA message values.</param> | ||
| 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]; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Transducer Type | ||
| /// </summary> | ||
| public string Type { get; } | ||
|
|
||
| /// <summary> | ||
| /// Measurement data | ||
| /// </summary> | ||
| public double Data { get; } | ||
|
|
||
| /// <summary> | ||
| /// Unit of measure | ||
| /// </summary> | ||
| public string Unit { get; } | ||
|
|
||
| /// <summary> | ||
| /// ID | ||
| /// </summary> | ||
| public string ID { get; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,18 @@ public void IgnoreChecksum() | |
| Assert.ThrowsException<ArgumentException>(() => NmeaMessage.Parse(input, ignoreChecksum: false)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void TestDPT() | ||
| { | ||
| string input = "$--DPT,149.5,000.5,1000.0*7F"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really how a real world message looks with the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, my data looks like that. |
||
| 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() | ||
| { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the NMEA spec HDT is a deprecated message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you which me to revert it?
I can just create it locally in my project if you think it should not be part of this library.