コード例 #1
0
        public void Update(String line)
        {
            try
            {
                //validate checksum first
                if (IsValidChecksum(line))
                {
                    if (line.StartsWith("$GPGGA"))
                    {
                        FixData newFix = FixData.Parse(line);
                        if (newFix != null && newFix.Valid)
                        {
                            //compute vertical speed
                            int newAltTimeSeconds = (newFix.Time.Hour * 3600)
                                                    + (newFix.Time.Minute * 60)
                                                    + (newFix.Time.Second);
                            double dt = newAltTimeSeconds - lastAltTimeSeconds;
                            if (lastAltitude > 0 && dt > 0)
                            {
                                double newVS = (newFix.Altitude - lastAltitude) / (dt);
                                VerticalSpeed = VerticalSpeed + 0.2f * (newVS - VerticalSpeed);
                            }
                            lastAltitude       = newFix.Altitude;
                            lastAltTimeSeconds = newAltTimeSeconds;

                            //compute maximum altitude
                            if (newFix.Altitude > MaximumAltitude)
                            {
                                MaximumAltitude = newFix.Altitude;
                            }
                        }
                        this.Fix = newFix;
                    }
                    else if (line.StartsWith("$GPRMC"))
                    {
                        this.Movement = MovementData.Parse(line);
                    }
                    else if (line.StartsWith("$GPGSV"))
                    {
                        this.Satellites = SatellitesData.Parse(line);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }