コード例 #1
0
        //=========================================================================

        //=========================================================================
        /// <summary>
        /// Raises our gps data received event in a thread safe way
        /// </summary>
        public void RaiseGpsDataReceivedEventArgs()
        {
            //---- raise the event
            if (this.GpsDataRecieved != null)
            {
                this.GpsDataRecieved(this, new GpsDataReceivedEventArgs(GpsReading.Parse(this._nmeaSentenceBuffer)));
            }
        }
コード例 #2
0
        protected virtual GpsInfo ParseGpsInfo(string[] commands)
        {
            var reading = GpsReading.Parse(commands);

            if (reading.FixedGpsData == null)
            {
                return(null);
            }

            var gpsInfo = new GpsInfo();

            if (reading.FixedGpsData.Elevation != null)
            {
                gpsInfo.AltitudeMeters = Convert.ToDouble(reading.FixedGpsData.Elevation.Value);
            }
            if (reading.FixedGpsData.Position != null)
            {
                gpsInfo.LatitudeDegrees  = Convert.ToDouble(reading.FixedGpsData.Position.Latitude.Degrees);
                gpsInfo.LongitudeDegrees = Convert.ToDouble(reading.FixedGpsData.Position.Longitude.Degrees);
            }

            //采用gps本身提供的日期,20160509
            gpsInfo.UtcTime = reading.Summary.UtcDateTime;

            //gpsInfo.UtcTime = reading.FixedGpsData.UtcTime;
            gpsInfo.LocalTime             = gpsInfo.UtcTime.ToLocalTime();
            gpsInfo.FixedSatelliteCount   = reading.FixedGpsData.NumberOfSatelitesInUse;
            gpsInfo.TrackedSatelliteCount = gpsInfo.FixedSatelliteCount;
            gpsInfo.FixQuality            = reading.FixedGpsData.Quality;
            if (reading.GroundVector != null && reading.GroundVector.GroundSpeedInKmh != 0)
            {
                gpsInfo.SpeedInKmh = reading.GroundVector.GroundSpeedInKmh;
            }
            if (reading.Summary != null && reading.Summary.GroundSpeed != 0)
            {
                var summary = reading.Summary;
                gpsInfo.SpeedInKmh   = Convert.ToDouble(summary.GroundSpeed);
                gpsInfo.AngleDegrees = Convert.ToDouble(summary.Heading);
            }
            if (reading.Heading != null)
            {
                //20160111,使用高精度版本
                tempVersion          = true;
                gpsInfo.AngleDegrees = reading.Heading.BearingDegrees;
                //高精度和普通科三gps角度会差180度,如:高精度3°,普通184°
                //gpsInfo.AngleDegrees = gpsInfo.AngleDegrees + 180;
                //if (gpsInfo.AngleDegrees > 360)
                //    gpsInfo.AngleDegrees = gpsInfo.AngleDegrees - 360;

                gpsInfo.FixedSatelliteCount   = reading.Heading.SatellitesInSolution;
                gpsInfo.TrackedSatelliteCount = reading.Heading.SatellitesInTrack;
                //记录上一次角度
                lastAngleDegrees = gpsInfo.AngleDegrees;
            }
            if (tempVersion)
            {
                //20160111,使用高精度版本,(有时Heading为空的情况)
                gpsInfo.HighPrecisionVersion = true;
                if (reading.Heading == null)
                {
                    gpsInfo.AngleDegrees = lastAngleDegrees;
                }
            }
            return(gpsInfo);
        }