From d5b89fef5fdbdfcbd4148a5c46bce664ee8d3585 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Thu, 16 Jan 2020 21:48:59 -0800 Subject: [PATCH] Added RMA message --- src/NmeaParser/Nmea/Rma.cs | 168 +++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/NmeaParser/Nmea/Rma.cs diff --git a/src/NmeaParser/Nmea/Rma.cs b/src/NmeaParser/Nmea/Rma.cs new file mode 100644 index 0000000..b4a7b68 --- /dev/null +++ b/src/NmeaParser/Nmea/Rma.cs @@ -0,0 +1,168 @@ +// ******************************************************************************* +// * 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.Nmea +{ + /// + /// Recommended minimum specific Loran-C Data + /// + /// + /// Position, course and speed data provided by a Loran-C receiver. Time differences A and B are those used in computing latitude/longitude. + /// This sentence is transmitted at intervals not exceeding 2-seconds and is always accompanied by when a destination waypoint is active. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprmb")] + [NmeaMessageType("--RMA")] + public class Rma : NmeaMessage + { + /// + /// Positioning system status field + /// + public enum PositioningStatus + { + /// + /// Data not valid + /// + Invalid = 0, + /// + /// Autonomous + /// + Autonomous, + /// + /// Differential + /// + Differential + } + + /// + /// Positioning system mode indicator + /// + public enum PositioningMode + { + /// + /// Data not valid + /// + NotValid = 0, + /// + /// Autonomous mode + /// + Autonomous, + /// + /// Differential mode + /// + Differential, + /// + /// Estimated (dead reckoning) mode + /// + Estimated, + /// + /// Manual input mode + /// + Manual, + /// + /// Simulator mode + /// + Simulator, + } + /// + /// Initializes a new instance of the class. + /// + /// The message type + /// The NMEA message values. + public Rma(string type, string[] message) : base(type, message) + { + if (message == null || message.Length < 12) + throw new ArgumentException("Invalid RMA", "message"); + + Status = message[0] == "A" ? PositioningStatus.Autonomous : (message[0] == "D" ? PositioningStatus.Differential : PositioningStatus.Invalid); + Latitude = NmeaMessage.StringToLatitude(message[1], message[2]); + Longitude = NmeaMessage.StringToLongitude(message[3], message[4]); + if (double.TryParse(message[5], NumberStyles.Float, CultureInfo.InvariantCulture, out double tmp)) + TimeDifferenceA = TimeSpan.FromMilliseconds(tmp / 1000); + if (double.TryParse(message[6], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) + TimeDifferenceB = TimeSpan.FromMilliseconds(tmp / 1000); + if (double.TryParse(message[7], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) + Speed = tmp; + else + Speed = double.NaN; + if (double.TryParse(message[8], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) + Course = tmp; + else + Course = double.NaN; + if (double.TryParse(message[9], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp)) + MagneticVariation = tmp * (message[10] == "E" ? -1 : 1); + else + MagneticVariation = double.NaN; + + switch (message[11]) + { + case "A": Mode = PositioningMode.Autonomous; break; + case "D": Mode = PositioningMode.Autonomous; break; + case "E": Mode = PositioningMode.Estimated; break; + case "M": Mode = PositioningMode.Manual; break; + case "S": Mode = PositioningMode.Simulator; break; + case "N": + default: + Mode = PositioningMode.Autonomous; break; + } + } + + /// + /// Positioning system status + /// + public PositioningStatus Status { get; } + + /// + /// Latitude + /// + public double Latitude { get; } + + /// + /// Longitude + /// + public double Longitude { get; } + + /// + /// Time difference A + /// + public TimeSpan TimeDifferenceA { get; } + + /// + /// Time difference B + /// + public TimeSpan TimeDifferenceB { get; } + + /// + /// Speed over ground in knots. + /// + public double Speed { get; } + + /// + /// Course over ground in degrees from true north + /// + public double Course { get; } + + /// + /// Magnetic variation in degrees. + /// + public double MagneticVariation { get; } + + /// + /// Positioning system mode indicator + /// + public PositioningMode Mode { get; } + } +}