Esempio n. 1
0
        private void Device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            Dispatcher.BeginInvoke((Action) delegate()
            {
                _dataFound = true;
                if (_liveData)
                {
                    FileUtil.WriteToFile(args.Message, _dataTextSavePath);
                }

                switch (args.Message)
                {
                case Gpgga _:
                    var newReading = args.Message as Gpgga;
                    if (Navigatedisplay.IsGoodMessage(newReading))
                    {
                        LoggingService.AddInfo(args.Message.ToString(), "nmea");
                        Navigatedisplay.ParseNmeaMessage(newReading);
                        // Navigatedisplay.GetCourseCorrections(GpsCourse);
                    }

                    break;

                case GPRMC _:
                    var newReadingt = args.Message as Gpvtg;
                    break;
                }
            });
        }
Esempio n. 2
0
        private void Listener_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            var message = e.Message;
            var str     = message.ToString();

            LogNmea.Info(str);

            RunOnUiThread(() =>
            {
                tvOutput.Append($"\n{str}");
                if (message is Gga gga)
                {
                    position["Lat"] = gga.Latitude.ToString("F8");
                    position["Lon"] = gga.Longitude.ToString("F8");
                    position["Alt"] = gga.Altitude.ToString() + " " + gga.AltitudeUnits.ToString();
                    // position["Height"] = gga.HeightOfGeoid.ToString() + " " + gga.HeightOfGeoidUnits.ToString();
                    position["Quality"]    = gga.Quality.ToString();
                    position["Satellites"] = gga.NumberOfSatellites.ToString();
                    position["StationID"]  = gga.DgpsStationId.ToString();
                    position["HDOP"]       = gga.Hdop.ToString();
                }
                else if (message is Rmc rmc)
                {
                    position["Lat"]   = rmc.Latitude.ToString("F8");
                    position["Lon"]   = rmc.Longitude.ToString("F8");
                    position["Speed"] = rmc.Speed.ToString("F2");
                }
                tvStatus.Text = string.Join('\n', position.OrderBy(kv => kv.Key).Select(kv => $"{kv.Key.PadRight(15, ' ')}:  {kv.Value}"));
            });
        }
        private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            Dispatcher.BeginInvoke((Action) delegate()
            {
                messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
                if (messages.Count > 100)
                {
                    messages.Dequeue();                                       //Keep message queue at 100
                }
                output.Text = string.Join("\n", messages.ToArray());
                output.Select(output.Text.Length - 1, 0);                 //scroll to bottom

                if (args.Message is NmeaParser.Nmea.Gps.Gpgsv)
                {
                    var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args.Message;
                    if (args.IsMultipart && args.MessageParts != null)
                    {
                        satView.GpgsvMessages = args.MessageParts.OfType <NmeaParser.Nmea.Gps.Gpgsv>();
                    }
                }
                if (args.Message is NmeaParser.Nmea.Gps.Gprmc)
                {
                    gprmcView.Message = args.Message as NmeaParser.Nmea.Gps.Gprmc;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Gpgga)
                {
                    gpggaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgga;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Gpgsa)
                {
                    gpgsaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgsa;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Gpgll)
                {
                    gpgllView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgll;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
                {
                    pgrmeView.Message = args.Message as NmeaParser.Nmea.Gps.Garmin.Pgrme;
                }
                else if (args.Message is NmeaParser.Nmea.UnknownMessage)
                {
                    var ctrl = MessagePanel.Children.OfType <UnknownMessageControl>().Where(c => c.Message.MessageType == args.Message.MessageType).FirstOrDefault();
                    if (ctrl == null)
                    {
                        ctrl = new UnknownMessageControl()
                        {
                            Style = this.Resources["card"] as Style
                        };
                        MessagePanel.Children.Add(ctrl);
                    }
                    ctrl.Message = args.Message as NmeaParser.Nmea.UnknownMessage;
                }
                else
                {
                    //
                }
            });
        }
Esempio n. 4
0
        private void ConnectionViewModel_Received(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            switch (e.Message)
            {
            case Gprmc rmc:
                GpsData.FixInfo = FixString = rmc.Active ? "Fix" : "No Fix";
                if (rmc.Active)
                {
                    GpsData.Lat = rmc.Latitude;
                    LatStr      = $"{rmc.Latitude:0.0000}";

                    GpsData.Lon = rmc.Longitude;
                    LonStr      = $"{rmc.Longitude:0.0000}";

                    var dto = new DateTime(rmc.FixTime.Ticks, DateTimeKind.Utc);

                    GpsData.Time = dto.ToLocalTime();
                    DateStr      = $"{GpsData.Time:dd.MM.yyyy HH:mm:ss}";

                    GpsData.Speed = rmc.Speed * 1.852;

                    SpeedString = $"{GpsData.Speed:0.0} km/h";

                    var latlon = new Geographic(rmc.Longitude, rmc.Latitude);

                    GpsData.UtmRef = UtmrefString = ((MGRS)latlon).ToString();



                    if (TrackMeOnMap)
                    {
                        MapLocation = new MapPointLatLon(rmc.Latitude, rmc.Longitude);
                    }

                    if (SaveTrack)
                    {
                        try
                        {
                            using (var fs = File.AppendText("track.csv"))
                                using (var csv = new CsvWriter(fs, new Configuration()
                                {
                                    Delimiter = ";"
                                }))
                                {
                                    csv.WriteRecord(GpsData);
                                    csv.NextRecord();
                                }
                        }
                        catch (Exception exception)
                        {
                            SaveTrack = false;
                            ConnectionViewModel.StatusText = $"Failed to write track. {exception.Message}";
                        }
                    }
                }
                break;
            }
        }
Esempio n. 5
0
 private void gpsdevice_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
 {
     Dispatcher.BeginInvoke((Action) delegate()
     {
         messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
         if (messages.Count > 100)
         {
             messages.Dequeue();                       //Keep message queue at 100
         }
         if (_showDebugInfo)
         {
             //gpsInfo.Text = string.Join("\n", messages.ToArray());
             //gpsInfo.Select(gpsInfo.Text.Length - 1, 0); //scroll to bottom
         }
         if (args.Message is NmeaParser.Nmea.Gps.Gprmc)
         {
             gprmcView.Message = args.Message as NmeaParser.Nmea.Gps.Gprmc;
             double speed      = gprmcView.Message.Speed;
             speedArc.EndAngle = ((speed / 200) * 240) - 120;
             if (Properties.Settings.Default.speedInMeterSec)
             {
                 speedVal.Text      = speed.ToString();
                 speedUnitText.Text = "m/s";
             }
             else
             {
                 speedVal.Text      = (speed * 1.94384).ToString();
                 speedUnitText.Text = "Knots";
             }
         }
         else if (args.Message is NmeaParser.Nmea.Gps.Gpgga)
         {
             gpggaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgga;
             if (Properties.Settings.Default.altitudeInMeeters)
             {
                 altitudeVal.Text  = gpggaView.Message.Altitude.ToString();
                 altitudeUnit.Text = "Meters";  // gpggaView.Message.AltitudeUnits.ToString()
             }
             else
             {
                 altitudeVal.Text  = (gpggaView.Message.Altitude * 3.28084).ToString();
                 altitudeUnit.Text = "Feet";
             }
         }
         //else if (args.Message is NmeaParser.Nmea.UnknownMessage)
         //{
         //    if (_showDebugInfo)
         //        gpsInfo.Text += "\n Error: Unknown Signal Type!";
         //}
         else
         {
             // Do nothing
         }
     });
 }
Esempio n. 6
0
 private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
 {
     var _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
         if (messages.Count > 100)
         {
             messages.Dequeue();                                       //Keep message queue at 100
         }
         output.Text = string.Join("\n", messages.ToArray());
     });
 }
Esempio n. 7
0
        private void device_MessageReceived(object?sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            Dispatcher.BeginInvoke((Action) delegate()
            {
                messagesWindow.AddMessage(args.Message);

                if (args.Message is NmeaParser.Messages.Gsv gsv)
                {
                    skyViewWindow.GsvMessage = gsv;
                }
            });
        }
Esempio n. 8
0
        private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
            if (messages.Count > 100)
            {
                messages.Dequeue();                       //Keep message queue at 100
            }
            NmeaParser.Nmea.Gps.Gpgll               gll;
            NmeaParser.Nmea.Gps.Gpgga               gga;
            NmeaParser.Nmea.Gps.Garmin.Pgrme        rme;
            IEnumerable <NmeaParser.Nmea.Gps.Gpgsv> gpgsvParts;

            if (args.Message is NmeaParser.Nmea.Gps.Gpgsv)
            {
                var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args.Message;
                if (args.IsMultipart && args.MessageParts != null)
                {
                    gpgsvParts = args.MessageParts.OfType <NmeaParser.Nmea.Gps.Gpgsv>();
                }
            }
            if (args.Message is NmeaParser.Nmea.Gps.Gpgga)
            {
                gga = args.Message as NmeaParser.Nmea.Gps.Gpgga;
                settings.latitude = gga.Latitude;
                this.latitude.Invoke(new MethodInvoker(delegate
                {
                    this.latitude.Text = gga.Latitude.ToString();
                }));
                settings.longitude = gga.Longitude;
                this.longitude.Invoke(new MethodInvoker(delegate
                {
                    this.longitude.Text = gga.Longitude.ToString();
                }));
                settings.altitude = gga.Altitude;
                this.altitude.Invoke(new MethodInvoker(delegate
                {
                    this.altitude.Text = gga.Altitude.ToString() + " " + gga.AltitudeUnits;
                }));
            }
            else if (args.Message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
            {
                rme = args.Message as NmeaParser.Nmea.Gps.Garmin.Pgrme;
                double total_error = Math.Sqrt(rme.HorizontalError * rme.HorizontalError + rme.VerticalError * rme.VerticalError);
                if (total_error < 10.0)
                {
                    this.fix.Invoke(new MethodInvoker(delegate
                    {
                        fix.Text = "Good position";
                    }));
                    device.CloseAsync();
                }
            }
        }
Esempio n. 9
0
        private void Listener_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            var message = e.Message;

            RunOnUiThread(() =>
            {
                if (messages.Count == 100)
                {
                    messages.Dequeue();
                }
                messages.Enqueue(message);
                status.Text = string.Join("\n", messages.Reverse().Select(n => n.ToString()));
            });
        }
Esempio n. 10
0
        private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            Dispatcher.BeginInvoke((Action) delegate()
            {
                messagesWindow.AddMessage(args.Message);

                if (args.Message is NmeaParser.Nmea.Gps.Gpgsv)
                {
                    var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args.Message;
                    if (args.IsMultiPart && args.MessageParts != null)
                    {
                        skyViewWindow.GpgsvMessages = args.MessageParts.OfType <NmeaParser.Nmea.Gps.Gpgsv>();
                    }
                }
            });
        }
Esempio n. 11
0
        void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            var message = e.Message;

            if (message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
            {
                m_Accuracy = ((NmeaParser.Nmea.Gps.Garmin.Pgrme)message).HorizontalError;
            }
            else if (message is NmeaParser.Nmea.Gps.Gprmc)
            {
                var rmc = (NmeaParser.Nmea.Gps.Gprmc)message;
                if (rmc.Active)
                {
                    base.UpdateLocation(new Esri.ArcGISRuntime.Location.Location(new Esri.ArcGISRuntime.Geometry.MapPoint(rmc.Longitude, rmc.Latitude, SpatialReferences.Wgs84), m_Accuracy, rmc.Speed, rmc.Course, false));
                }
            }
        }
Esempio n. 12
0
        private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            Dispatcher.BeginInvoke((Action) delegate()
            {
                messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
                if (messages.Count > 100)
                {
                    messages.Dequeue();                                       //Keep message queue at 100
                }
                output.Text = string.Join("\n", messages.ToArray());
                output.Select(output.Text.Length - 1, 0);                 //scroll to bottom

                if (args.Message is NmeaParser.Nmea.Gps.Gpgsv)
                {
                    var gpgsv = (NmeaParser.Nmea.Gps.Gpgsv)args.Message;
                    if (args.IsMultipart && args.MessageParts != null)
                    {
                        satView.GpgsvMessages = args.MessageParts.OfType <NmeaParser.Nmea.Gps.Gpgsv>();
                    }
                }
                if (args.Message is NmeaParser.Nmea.Gps.Gprmc)
                {
                    gprmcView.Message = args.Message as NmeaParser.Nmea.Gps.Gprmc;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Gpgga)
                {
                    gpggaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgga;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Gpgsa)
                {
                    gpgsaView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgsa;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Gpgll)
                {
                    gpgllView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgll;
                }
                else if (args.Message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
                {
                    pgrmeView.Message = args.Message as NmeaParser.Nmea.Gps.Garmin.Pgrme;
                }
            });
        }
Esempio n. 13
0
 private void Device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
 {
     if (e.Message is NmeaParser.Nmea.Gps.Gprmc)
     {
         gprmc = e.Message as NmeaParser.Nmea.Gps.Gprmc;
         //try {
         //    timer.Change((int)(1000.0/(gprmc.Speed/0.514444)), (int)(1000.0 / (gprmc.Speed / 0.514444)));
         //    }
         //catch (System.Exception ex) { Console.WriteLine(ex.Message); }
         try
         {
             new Thread(new ThreadStart(ThreadSafeUpdateLabel1)).Start();
         }
         catch (System.Exception ex) { Console.WriteLine(ex.Message); }
         try{
             new Thread(new ThreadStart(ThreadSafeUpdateGmap1)).Start();
         }
         catch (System.Exception ex) { Console.WriteLine(ex.Message); }
     }
 }
Esempio n. 14
0
        void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            var message = e.Message;

            if (message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
            {
                m_Accuracy = ((NmeaParser.Nmea.Gps.Garmin.Pgrme)message).HorizontalError;
            }
            else if (message is NmeaParser.Nmea.Gps.Gprmc)
            {
                var rmc = (NmeaParser.Nmea.Gps.Gprmc)message;
                if (rmc.Active && LocationChanged != null)
                {
                    LocationChanged(this, new Esri.ArcGISRuntime.Location.LocationInfo()
                    {
                        Course             = rmc.Course,
                        Speed              = rmc.Speed,
                        HorizontalAccuracy = m_Accuracy,
                        Location           = new Esri.ArcGISRuntime.Geometry.MapPoint(rmc.Longitude, rmc.Latitude, SpatialReferences.Wgs84)
                    });
                }
            }
        }
Esempio n. 15
0
        private void Listener_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            var message = e.Message;

            RunOnUiThread(() =>
            {
                if (messages.Count == 100)
                {
                    messages.Dequeue();
                }
                messages.Enqueue(message);
                status.Text = string.Join("\n", messages.Reverse().Select(n => n.ToString()));
                if (message is Rmc rmc)
                {
                    FindViewById <TextView>(Resource.Id.latitude).Text  = "Latitude = " + rmc.Latitude.ToString("0.0000000");
                    FindViewById <TextView>(Resource.Id.longitude).Text = "Longitude = " + rmc.Longitude.ToString("0.0000000");
                }
                else if (message is Gga gga)
                {
                    FindViewById <TextView>(Resource.Id.altitude).Text = "Altitude = " + gga.Altitude.ToString() + " " + gga.AltitudeUnits.ToString();
                }
            });
        }
Esempio n. 16
0
        private void Device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            try
            {
                switch (e.Message.MessageType)
                {
                case "GPGSA":     // Overall satellite data
                    var gsaMessage = (Gpgsa)e.Message;
                    Debug.WriteLine($"Sat data.  Mode: {gsaMessage.GpsMode}. Count: {gsaMessage.SVs.Count}");
                    break;

                case "GPGGA":     // Fix information
                    var ggaMessage = (Gpgga)e.Message;
                    Debug.WriteLine($"Fix info.  Lat: {ggaMessage.Latitude}. Lon: {ggaMessage.Longitude}. Height: {ggaMessage.Altitude} {ggaMessage.AltitudeUnits}");
                    break;

                case "GPRMC":     // Recommended minimum data for gps
                    var rmcMessage = (Gprmc)e.Message;
                    Debug.WriteLine($"Fix info.  Lat: {rmcMessage.Latitude}. Lon: {rmcMessage.Longitude}. Course: {rmcMessage.Course}. Speed: {rmcMessage.Speed}");
                    break;

                case "GPGSV":     // Detailed Satellite data
                    var gsvMessage = (Gpgsv)e.Message;
                    Debug.WriteLine($"Fix info.  Sats in view: {gsvMessage.SVsInView }. Msgcount: {gsvMessage.TotalMessages}.");
                    break;

                default:
                    Debug.WriteLine($"Other message received: {e.Message.MessageType} - {e.Message}");
                    break;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
        }
Esempio n. 17
0
 private void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
 {
     //Access ui thread
     var _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         NmeaParser.Nmea.Gps.Gprmc ulos;
         if (args.Message is NmeaParser.Nmea.Gps.Gprmc)
         {
             ulos        = args.Message as NmeaParser.Nmea.Gps.Gprmc;
             var gpsData = new RoboCar.Data.GPSData {
                 Latitude = ulos.Latitude, Longitude = ulos.Longitude
             };
             if (UnityClient.Instance.Args != null)
             {
                 UnityClient.Instance.SendGpsData(gpsData);
             }
             //  System.Diagnostics.Debug.WriteLine("Latitude: " + ulos.Latitude + "Longitude" + ulos.Longitude);
         }
         //System.Diagnostics.Debug.WriteLine(args.Message.MessageType + ": " + args.Message.ToString());
         //messages.Enqueue(args.Message.MessageType + ": " + args.Message.ToString());
         //if (messages.Count > 100) messages.Dequeue(); //Keep message queue at 100
         //output.Text = string.Join("\n", messages.ToArray());
     });
 }
        protected virtual void OnMessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            const double knotsToMeterPerSecond = 0.5144;

            try
            {
                double?latitude  = null;
                double?longitude = null;

                switch (args.Message)
                {
                case NmeaParser.Messages.Gga gga:
                    TrackedSatelliteCount = gga.NumberOfSatellites;                 // Satellites being tracked
                                                                                    // gga.Hdop                                                 // Horizontal dilution of position
                    if (gga.Quality != NmeaParser.Messages.Gga.FixQuality.Invalid)
                    {
                        latitude  = gga.Latitude;
                        longitude = gga.Longitude;
                    }
                    break;

                case NmeaParser.Messages.Gsa gsa:
                    TrackedSatelliteCount = (gsa.SatelliteIDs?.Count() ?? 0);       // Satellite IDs used for fix
                                                                                    // gsa.Fix                                                  // None; 2D; or, 3D
                                                                                    // gsa.Pdop
                                                                                    // gsa.Hdop
                                                                                    // gsa.Vdop
                    break;

                case NmeaParser.Messages.Rma rma:
                    if (rma.Status != NmeaParser.Messages.Rma.PositioningStatus.Invalid)
                    {
                        latitude  = rma.Latitude;
                        longitude = rma.Longitude;
                        if (!double.IsNaN(rma.Course))
                        {
                            Course = rma.Course;
                        }
                        Velocity = (rma.Speed * knotsToMeterPerSecond);
                    }
                    break;

                case NmeaParser.Messages.Rmc rmc:
                    latitude  = rmc.Latitude;
                    longitude = rmc.Longitude;
                    if (!double.IsNaN(rmc.Course))
                    {
                        Course = rmc.Course;
                    }
                    Velocity = (rmc.Speed * knotsToMeterPerSecond);
                    break;
                }

                var validLatitude  = ((latitude != null) && (!double.IsNaN(latitude.Value)));
                var validLongitude = ((longitude != null) && (!double.IsNaN(longitude.Value)));

                if (validLatitude && validLongitude)
                {
                    var mapPoint = new MapPoint(longitude.Value, latitude.Value, SpatialReferences.Wgs84);
                    var location = new Esri.ArcGISRuntime.Location.Location(mapPoint, 2, Velocity, Course, false);
                    UpdateLocation(location);
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 19
0
        private static void Device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            DateTime nowUTC          = DateTime.Now.ToUniversalTime();
            double   lat             = 0.00;
            double   longitude       = 0.00;
            bool     hasValidMessage = false;
            string   msgType         = "";

            DateTime fixtime = DateTime.Now.ToUniversalTime();

            if (e.Message is NmeaParser.Nmea.Gps.Gprmc)
            {
                var message = e.Message as NmeaParser.Nmea.Gps.Gprmc;
                lat             = message.Latitude;
                fixtime         = message.FixTime.ToUniversalTime();
                longitude       = message.Longitude;
                hasValidMessage = true;
                msgType         = "GPRMC";

                if (!double.IsNaN(message.Course))
                {
                    lastBearing = message.Course;
                }
            }
            else if (e.Message is NmeaParser.Nmea.Gps.Gpgga)
            {
                var message = e.Message as NmeaParser.Nmea.Gps.Gpgga;
                fixtime         = new DateTime(nowUTC.Year, nowUTC.Month, nowUTC.Day, message.FixTime.Hours, message.FixTime.Minutes, message.FixTime.Seconds, message.FixTime.Milliseconds);
                lat             = message.Latitude;
                longitude       = message.Longitude;
                hasValidMessage = true;
                msgType         = "GPGGA";
            }
            else if (e.Message is NmeaParser.Nmea.Gps.Gpgll)
            {
                var message = e.Message as NmeaParser.Nmea.Gps.Gpgll;

                lat             = message.Latitude;
                longitude       = message.Longitude;
                hasValidMessage = true;
                fixtime         = new DateTime(nowUTC.Year, nowUTC.Month, nowUTC.Day, message.FixTime.Hours, message.FixTime.Minutes, message.FixTime.Seconds, message.FixTime.Milliseconds);
                msgType         = "GPGLL";
            }
            else if (e.Message is NmeaParser.Nmea.Gps.Gpbod)
            {
                var message = e.Message as NmeaParser.Nmea.Gps.Gpbod;
                lastBearing = message.TrueBearing;
            }

            if (hasValidMessage)
            {
                intialized = true;
                lock (instance.coordinatesQueue)
                {
                    if (!OverrideLat.HasValue || !OverrideLong.HasValue)
                    {
                        var coords = new GpsCoords {
                            Altitude = null, Latitude = lat, Longitude = longitude, Timestamp = nowUTC
                        };
                        coords.TranslateByHeading(lastBearing, gpsOffsetFeet, inReverse);
                        instance.coordinatesQueue.Enqueue(coords);
                    }
                    else
                    {
                        instance.coordinatesQueue.Enqueue(new GpsCoords {
                            Altitude = null, Latitude = OverrideLat, Longitude = OverrideLong, Timestamp = nowUTC
                        });
                    }
                }

                try
                {
                    //Logger.Log("GPS", "Sending GPS Message. " + lat.ToString() + ", " + longitude.ToString());
                    if (!OverrideLat.HasValue || !OverrideLong.HasValue)
                    {
                        Messenger.Default.Send <GPSEventMessage>(new GPSEventMessage {
                            Timestamp = fixtime, Latitude = lat, Longitude = longitude, MessageType = msgType
                        });
                    }
                    else
                    {
                        Messenger.Default.Send <GPSEventMessage>(new GPSEventMessage {
                            Timestamp = fixtime, Latitude = OverrideLat.Value, Longitude = OverrideLong.Value, MessageType = msgType
                        });
                    }
                }
                catch (Exception gExc)
                {
                    Logging.Logger.Log(gExc);
                }
            }

            lock (instance.coordinatesQueue)
            {
                while (instance.coordinatesQueue.Count > instance.maxMessages)
                {
                    instance.coordinatesQueue.Dequeue();
                }
            }
        }
Esempio n. 20
0
 private void NmeaMessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
 {
     OnMessageReceived(e.Message);
 }
        void device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs e)
        {
            var message = e.Message;

            ParseMessage(message);
        }