예제 #1
0
        private void GpsdServiceOnLocationChanged(object source, GpsDataEventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                if (GpsTextBox == null)
                {
                    return;
                }
                GpsTextBox.Text = GpsTextBox.Text + e + "\n";
            });

            Console.WriteLine(e.ToString());
        }
예제 #2
0
        protected virtual void OnGpsDataReceived(GpsDataEventArgs e)
        {
            if (GpsInfo.CoordinateSystem == GpsCoordinateSystem.Lambert72)
            {
                var x = 0.0d;
                var y = 0.0d;
                var h = 0.0d;
                CoordinateConverterUtilities.GeoETRS89ToLambert72(e.Latitude, e.Longitude, 0, ref x, ref y, ref h);
                e.CoordinateSystem = GpsCoordinateSystem.Lambert72;
                e.Latitude         = x;
                e.Longitude        = y;
            }

            GpsCallbackEvent?.Invoke(this, e);
        }
예제 #3
0
 private void gpscontrol_GPSDataEvent(object sender, GpsDataEventArgs e)
 {
     if (isAdjust)
     {
         return;
     }
     if (e.Gsa.FormatFixType() != GSA.FixType.Fix_not)
     {
         string strdate = e.Rmc.FormatDate();
         string strtime = e.Gga.FormatTime();
         //strdate = "2012-07-25";
         if (Utility.UpdateTime(strdate, strtime))
         {
             isAdjust = true;
             AddToMemo("重新校准了系统时间");
             RefreshTime();
             GValue.SoundAlarmA();
         }
     }
 }
예제 #4
0
파일: Program.cs 프로젝트: sakatuba/GPS.NET
 private static void GpsdServiceOnLocationChanged(object sender, GpsDataEventArgs e)
 {
     System.Console.WriteLine(e.ToString());
 }
예제 #5
0
        public override bool Connect()
        {
            var data = (FileGpsInfo)GpsInfo;

            IsRunning = true;
            OnGpsStatusChanged(GpsStatus.Connecting);

            var parser         = new NmeaParser();
            var gpsdDataParser = new GpsdDataParser();

            var headerLine      = true;
            var latColumnIndex  = 0;
            var longColumnIndex = 0;
            var minArraySize    = 0;

            try
            {
                using (var streamReader = File.OpenText(data.FilePath))
                {
                    string line;
                    OnGpsStatusChanged(GpsStatus.Connected);
                    while (IsRunning && (line = streamReader.ReadLine()) != null)
                    {
                        OnRawGpsDataReceived(line);
                        switch (data.FileType)
                        {
                        case FileType.Nmea:
                            var nmeaResult = parser.Parse(line);
                            var result     = nmeaResult as GprmcMessage;
                            if (result == null)
                            {
                                continue;
                            }
                            OnGpsDataReceived(new GpsDataEventArgs(result));
                            break;

                        case FileType.Gpsd:
                            var gpsdResult  = gpsdDataParser.GetGpsData(line);
                            var gpsLocation = gpsdResult as GpsLocation;
                            if (gpsLocation == null)
                            {
                                continue;
                            }
                            OnGpsDataReceived(new GpsDataEventArgs(gpsLocation));
                            break;

                        case FileType.LatitudeLongitude:
                            if (headerLine)
                            {
                                var headers = line.Split(';');

                                for (var i = 0; i < headers.Length; i++)
                                {
                                    if (headers[i] == Properties.Settings.Default.File_Latitude_Header)
                                    {
                                        latColumnIndex = i;
                                    }
                                    if (headers[i] == Properties.Settings.Default.File_Longitude_Header)
                                    {
                                        longColumnIndex = i;
                                    }
                                }
                                minArraySize = Math.Max(latColumnIndex, longColumnIndex);
                                headerLine   = false;
                            }
                            else
                            {
                                var latLongResult = line.Split(';');
                                if (latLongResult.Length < 2)
                                {
                                    throw new InvalidFileFormatException(data.FilePath);
                                }
                                if (latLongResult.Length < minArraySize)
                                {
                                    continue;
                                }

                                double latitude;
                                if (
                                    !double.TryParse(latLongResult[latColumnIndex], NumberStyles.Any,
                                                     CultureInfo.InvariantCulture, out latitude))
                                {
                                    continue;
                                }
                                double longitude;
                                if (
                                    !double.TryParse(latLongResult[longColumnIndex], NumberStyles.Any,
                                                     CultureInfo.InvariantCulture, out longitude))
                                {
                                    continue;
                                }

                                var message = new GpsDataEventArgs(latitude, longitude);
                                OnGpsDataReceived(message);
                            }
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                        Thread.Sleep(data.ReadFrequenty);
                    }
                    Disconnect();
                    return(true);
                }
            }
            catch
            {
                Disconnect();
                throw;
            }
        }