// // Copyright (c) 2014 Morten Nielsen // // Licensed under the Microsoft Public License (Ms-PL) (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://opensource.org/licenses/Ms-PL.html // // 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.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NmeaParser.Nmea.Gps { /// /// Recommended Minimum /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gprmc")] [NmeaMessageType("GPRMC")] public class Gprmc : NmeaMessage { /// /// Called when the message is being loaded. /// /// 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), 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]); Longitude = NmeaMessage.StringToLongitude(message[4], message[5]); Speed = NmeaMessage.StringToDouble(message[6]); Course = NmeaMessage.StringToDouble(message[7]); MagneticVariation = NmeaMessage.StringToDouble(message[9]); if (!double.IsNaN(MagneticVariation) && message[10] == "W") MagneticVariation *= -1; } /// /// Fix Time /// public DateTime FixTime { get; private set; } /// /// Gets a value whether the device is active /// public bool Active { get; private set; } /// /// Latitude /// public double Latitude { get; private set; } /// /// Longitude /// public double Longitude { get; private set; } /// /// Speed over the ground in knots /// public double Speed { get; private set; } /// /// Track angle in degrees True /// public double Course { get; private set; } /// /// Magnetic Variation /// public double MagneticVariation { get; private set; } } }