Beispiel #1
0
        /// <summary>
        /// Called when the message is being loaded.
        /// </summary>
        /// <param name="message">The NMEA message values.</param>
        protected override void OnLoadMessage(string[] message)
        {
            if (message == null || message.Length < 14)
            {
                throw new ArgumentException("Invalid GPGGA", "message");
            }
            FixTime            = StringToTimeSpan(message[0]);
            Latitude           = NmeaMessage.StringToLatitude(message[1], message[2]);
            Longitude          = NmeaMessage.StringToLongitude(message[3], message[4]);
            Quality            = (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];
            HeightOfGeoid      = NmeaMessage.StringToDouble(message[10]);
            HeightOfGeoidUnits = 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;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when the message is being loaded.
        /// </summary>
        /// <param name="message">The NMEA message values.</param>
        protected override void OnLoadMessage(string[] message)
        {
            if (message == null || message.Length < 13)
            {
                throw new ArgumentException("Invalid GPRMB", "message");
            }

            Status = message[0] == "A" ? DataStatus.Ok : Gprmb.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";
        }
Beispiel #3
0
        /// <summary>
        /// Called when the message is being loaded.
        /// </summary>
        /// <param name="message">The NMEA message values.</param>
        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),
                                       0, DateTimeKind.Utc).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;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Called when the message is being loaded.
        /// </summary>
        /// <param name="message">The NMEA message values.</param>
        protected override void OnLoadMessage(string[] message)
        {
            if (message == null || message.Length < 14)
            {
                throw new ArgumentException("Invalid GPGGA", "message");
            }

            int fixQuality;
            int numberOfSatellites;

            Latitude           = NmeaMessage.StringToLatitude(message[1], message[2]);
            Longitude          = NmeaMessage.StringToLongitude(message[3], message[4]);
            Quality            = int.TryParse(message[5], NumberStyles.Integer, CultureInfo.InvariantCulture, out fixQuality) ? (FixQuality)fixQuality : FixQuality.Invalid;
            NumberOfSatellites = int.TryParse(message[6], NumberStyles.Integer, CultureInfo.InvariantCulture, out numberOfSatellites) ? numberOfSatellites : 0;
            Hdop                    = NmeaMessage.StringToDouble(message[7]);
            Altitude                = NmeaMessage.StringToDouble(message[8]);
            AltitudeUnits           = message[9];
            HeightOfGeoid           = NmeaMessage.StringToDouble(message[10]);
            HeightOfGeoidUnits      = message[11];
            TimeSinceLastDgpsUpdate = StringToTimeSpan(message[0]);
            if (message[13].Length > 0)
            {
                DgpsStationId = int.Parse(message[13], CultureInfo.InvariantCulture);
            }
            else
            {
                DgpsStationId = -1;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Called when the message is being loaded.
 /// </summary>
 /// <param name="message">The NMEA message values.</param>
 protected override void OnLoadMessage(string[] message)
 {
     if (message == null || message.Length < 4)
     {
         throw new ArgumentException("Invalid GPGLL", "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");
 }