Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rmc"/> class.
        /// </summary>
        /// <param name="type">The message type</param>
        /// <param name="message">The NMEA message values.</param>
        public Rmc(string type, string[] message) : base(type, message)
        {
            if (message == null || message.Length < 11)
            {
                throw new ArgumentException("Invalid RMC", "message");
            }

            if (message[8].Length == 6 && message[0].Length >= 6)
            {
                FixTime = new DateTimeOffset(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),
                                             0, TimeSpan.Zero).AddSeconds(double.Parse(message[0].Substring(4), CultureInfo.InvariantCulture));
            }
            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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rma"/> class.
        /// </summary>
        /// <param name="type">The message type</param>
        /// <param name="message">The NMEA message values.</param>
        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;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rmb"/> class.
        /// </summary>
        /// <param name="type">The message type</param>
        /// <param name="message">The NMEA message values.</param>
        public Rmb(string type, string[] message) : base(type, message)
        {
            if (message == null || message.Length < 13)
            {
                throw new ArgumentException("Invalid RMB", "message");
            }

            Status = message[0] == "A" ? DataStatus.Ok : Rmb.DataStatus.Warning;
            double tmp;

            if (double.TryParse(message[1], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
            {
                CrossTrackError = tmp;

                if (message[2] == "L") //Steer left
                {
                    CrossTrackError *= -1;
                }
            }
            else
            {
                CrossTrackError = double.NaN;
            }

            if (message[3].Length > 0)
            {
                OriginWaypointId = int.Parse(message[3], CultureInfo.InvariantCulture);
            }
            if (message[3].Length > 0)
            {
                DestinationWaypointId = int.Parse(message[4], CultureInfo.InvariantCulture);
            }
            DestinationLatitude  = NmeaMessage.StringToLatitude(message[5], message[6]);
            DestinationLongitude = NmeaMessage.StringToLongitude(message[7], message[8]);
            if (double.TryParse(message[9], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
            {
                RangeToDestination = tmp;
            }
            else
            {
                RangeToDestination = double.NaN;
            }
            if (double.TryParse(message[10], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
            {
                TrueBearing = tmp;
            }
            else
            {
                TrueBearing = double.NaN;
            }
            if (double.TryParse(message[11], NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
            {
                Velocity = tmp;
            }
            else
            {
                Velocity = double.NaN;
            }
            Arrived = message[12] == "A";
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gll"/> class.
        /// </summary>
        /// <param name="type">The message type</param>
        /// <param name="message">The NMEA message values.</param>
        public Gll(string type, string[] message) : base(type, message)
        {
            if (message == null || message.Length < 4)
            {
                throw new ArgumentException("Invalid GLL", "message");
            }
            Latitude  = NmeaMessage.StringToLatitude(message[0], message[1]);
            Longitude = NmeaMessage.StringToLongitude(message[2], message[3]);
            if (message.Length >= 5) //Some older GPS doesn't broadcast fix time
            {
                FixTime = StringToTimeSpan(message[4]);
            }
            DataActive    = (message.Length < 6 || message[5] == "A");
            ModeIndicator = DataActive ? Mode.Autonomous : Mode.DataNotValid;
            if (message.Length > 6)
            {
                switch (message[6])
                {
                case "A": ModeIndicator = Mode.Autonomous; break;

                case "D": ModeIndicator = Mode.DataNotValid; break;

                case "E": ModeIndicator = Mode.EstimatedDeadReckoning; break;

                case "M": ModeIndicator = Mode.Manual; break;

                case "S": ModeIndicator = Mode.Simulator; break;

                case "N": ModeIndicator = Mode.DataNotValid; break;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gga"/> class.
        /// </summary>
        /// <param name="type">The message type</param>
        /// <param name="message">The NMEA message values.</param>
        public Gga(string type, string[] message) : base(type, message)
        {
            if (message == null || message.Length < 14)
            {
                throw new ArgumentException("Invalid GGA", "message");
            }
            FixTime            = StringToTimeSpan(message[0]);
            Latitude           = NmeaMessage.StringToLatitude(message[1], message[2]);
            Longitude          = NmeaMessage.StringToLongitude(message[3], message[4]);
            Quality            = (Gga.FixQuality) int.Parse(message[5], CultureInfo.InvariantCulture);
            NumberOfSatellites = int.Parse(message[6], CultureInfo.InvariantCulture);
            Hdop                   = NmeaMessage.StringToDouble(message[7]);
            Altitude               = NmeaMessage.StringToDouble(message[8]);
            AltitudeUnits          = message[9];
            GeoidalSeparation      = NmeaMessage.StringToDouble(message[10]);
            GeoidalSeparationUnits = message[11];
            var timeInSeconds = StringToDouble(message[12]);

            if (!double.IsNaN(timeInSeconds))
            {
                TimeSinceLastDgpsUpdate = TimeSpan.FromSeconds(timeInSeconds);
            }
            else
            {
                TimeSinceLastDgpsUpdate = TimeSpan.MaxValue;
            }
            if (message[13].Length > 0)
            {
                DgpsStationId = int.Parse(message[13], CultureInfo.InvariantCulture);
            }
            else
            {
                DgpsStationId = -1;
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vlw"/> class.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="message">The NMEA message values.</param>
 public Vlw(string type, string[] message) : base(type, message)
 {
     if (message == null || message.Length < 7)
     {
         throw new ArgumentException("Invalid VLW", "message");
     }
     WaterDistanceCumulative  = NmeaMessage.StringToDouble(message[0]);
     WaterDistanceSinceReset  = NmeaMessage.StringToDouble(message[2]);
     GroundDistanceCumulative = NmeaMessage.StringToDouble(message[4]);
     GroundDistanceSinceReset = NmeaMessage.StringToDouble(message[6]);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vtg"/> class.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="message">The NMEA message values.</param>
 public Vtg(string type, string[] message) : base(type, message)
 {
     if (message == null || message.Length < 7)
     {
         throw new ArgumentException("Invalid VTG", "message");
     }
     CourseTrue     = NmeaMessage.StringToDouble(message[0]);
     CourseMagnetic = NmeaMessage.StringToDouble(message[2]);
     SpeedKnots     = NmeaMessage.StringToDouble(message[4]);
     SpeedKph       = NmeaMessage.StringToDouble(message[6]);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gst"/> class.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="message">The NMEA message values.</param>
 public Gst(string type, string[] message) : base(type, message)
 {
     if (message == null || message.Length < 8)
     {
         throw new ArgumentException("Invalid GST", "message");
     }
     FixTime             = StringToTimeSpan(message[0]);
     Rms                 = NmeaMessage.StringToDouble(message[1]);
     SemiMajorError      = NmeaMessage.StringToDouble(message[2]);
     SemiMinorError      = NmeaMessage.StringToDouble(message[3]);
     ErrorOrientation    = NmeaMessage.StringToDouble(message[4]);
     SigmaLatitudeError  = NmeaMessage.StringToDouble(message[5]);
     SigmaLongitudeError = NmeaMessage.StringToDouble(message[6]);
     SigmaHeightError    = NmeaMessage.StringToDouble(message[7]);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gbs"/> class.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="message">The NMEA message values.</param>
 public Grs(string type, string[] message) : base(type, message)
 {
     if (message == null || message.Length < 8)
     {
         throw new ArgumentException("Invalid Grs", "message");
     }
     FixTime = StringToTimeSpan(message[0]);
     Mode    = message[1] == "1" ? GrsMode.RecomputedFromPosition : GrsMode.UsedForPosition;
     double[] residuals = new double[message.Length - 2];
     for (int i = 2; i < message.Length; i++)
     {
         residuals[i - 2] = NmeaMessage.StringToDouble(message[i]);
     }
     Residuals = residuals;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gll"/> class.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="message">The NMEA message values.</param>
 public Dtm(string type, string[] message) : base(type, message)
 {
     if (message == null || message.Length < 8)
     {
         throw new ArgumentException("Invalid DTM", "message");
     }
     LocalDatumCode = message[0];
     if (message[1].Length > 0)
     {
         LocalDatumSubdivisionCode = message[1][0];
     }
     LatitudeOffset     = NmeaMessage.StringToDouble(message[2]) * (message[3] == "S" ? -1 : 1);
     LongitudeOffset    = NmeaMessage.StringToDouble(message[4]) * (message[5] == "W" ? -1 : 1);
     AltitudeOffset     = NmeaMessage.StringToDouble(message[6]);
     ReferenceDatumCode = message[7];
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gbs"/> class.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="message">The NMEA message values.</param>
 public Gbs(string type, string[] message) : base(type, message)
 {
     if (message == null || message.Length < 8)
     {
         throw new ArgumentException("Invalid GBS", "message");
     }
     FixTime        = StringToTimeSpan(message[0]);
     LatitudeError  = NmeaMessage.StringToDouble(message[1]);
     LongitudeError = NmeaMessage.StringToDouble(message[2]);
     AltitudeError  = NmeaMessage.StringToDouble(message[3]);
     if (int.TryParse(message[4], System.Globalization.NumberStyles.Integer, CultureInfo.InvariantCulture, out int id))
     {
         SatelliteId = id;
     }
     MissedDetectionProbability = NmeaMessage.StringToDouble(message[5]);
     BiasEstimate      = NmeaMessage.StringToDouble(message[6]);
     StandardDeviation = NmeaMessage.StringToDouble(message[7]);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gns"/> class.
        /// </summary>
        /// <param name="type">The message type</param>
        /// <param name="message">The NMEA message values.</param>
        public Gns(string type, string[] message) : base(type, message)
        {
            if (message == null || message.Length < 12)
            {
                throw new ArgumentException("Invalid GNS", "message");
            }
            FixTime            = StringToTimeSpan(message[0]);
            Latitude           = NmeaMessage.StringToLatitude(message[1], message[2]);
            Longitude          = NmeaMessage.StringToLongitude(message[3], message[4]);
            ModeIndicators     = message[5].Select(t => ParseModeIndicator(t)).ToArray();
            NumberOfSatellites = int.Parse(message[6], CultureInfo.InvariantCulture);
            Hdop = NmeaMessage.StringToDouble(message[7]);
            OrthometricHeight = NmeaMessage.StringToDouble(message[8]);
            GeoidalSeparation = NmeaMessage.StringToDouble(message[9]);
            var timeInSeconds = StringToDouble(message[10]);

            if (!double.IsNaN(timeInSeconds))
            {
                TimeSinceLastDgpsUpdate = TimeSpan.FromSeconds(timeInSeconds);
            }
            else
            {
                TimeSinceLastDgpsUpdate = null;
            }
            if (message[11].Length > 0)
            {
                DgpsStationId = message[11];
            }

            if (message.Length > 12)
            {
                switch (message[12])
                {
                case "S": Status = NavigationalStatus.Safe; break;

                case "C": Status = NavigationalStatus.Caution; break;

                case "U": Status = NavigationalStatus.Unsafe; break;

                case "V":
                default: Status = NavigationalStatus.NotValid; break;
                }
            }
        }