Beispiel #1
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.Gsv gpgsv)
                {
                    if (args.IsMultipart && args.MessageParts != null)
                    {
                        gsvMessages[args.Message.MessageType] = args.MessageParts.OfType <NmeaParser.Nmea.Gsv>().ToList();
                        satView.GsvMessages = gsvMessages.SelectMany(m => m.Value);
                    }
                }
                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
                {
                    //
                }
            });
        }
Beispiel #2
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());
     });
 }
Beispiel #3
0
        private void OnMessageReceived(Nmea.NmeaMessage msg)
        {
            var args  = new NmeaMessageReceivedEventArgs(msg);
            var multi = msg as IMultiPartMessage;

            if (multi != null)
            {
                args.IsMultipart = true;
                if (MultiPartMessageCache.ContainsKey(msg.MessageType))
                {
                    var dic = MultiPartMessageCache[msg.MessageType];
                    if (dic.ContainsKey(multi.MessageNumber - 1) && !dic.ContainsKey(multi.MessageNumber))
                    {
                        dic[multi.MessageNumber] = msg;
                    }
                    else //Something is out of order. Clear cache
                    {
                        MultiPartMessageCache.Remove(msg.MessageType);
                    }
                }
                else if (multi.MessageNumber == 1)
                {
                    MultiPartMessageCache[msg.MessageType]    = new Dictionary <int, Nmea.NmeaMessage>(multi.TotalMessages);
                    MultiPartMessageCache[msg.MessageType][1] = msg;
                }
                if (MultiPartMessageCache.ContainsKey(msg.MessageType))
                {
                    var dic = MultiPartMessageCache[msg.MessageType];
                    if (dic.Count == multi.TotalMessages) //We have a full list
                    {
                        MultiPartMessageCache.Remove(msg.MessageType);
                        args.MessageParts = dic.Values.ToArray();
                    }
                }
            }

            if (MessageReceived != null)
            {
                MessageReceived(this, args);
            }
        }
Beispiel #4
0
        /// <summary>
        ///checks GPS messages, transfers location to the options view
        ///if a fix is obtained
        /// </summary>
        private void Device_MessageReceived(object sender, NmeaParser.NmeaMessageReceivedEventArgs args)
        {
            var message = args.Message;

            if (message is NmeaParser.Nmea.Rmc)
            {
                Coords[0] = ((NmeaParser.Nmea.Rmc)message).Longitude;
                Coords[1] = ((NmeaParser.Nmea.Rmc)message).Latitude;
            }
            else if (args.Message is NmeaParser.Nmea.Gga)
            {
                Coords[0] = ((NmeaParser.Nmea.Gga)message).Longitude;
                Coords[1] = ((NmeaParser.Nmea.Gga)message).Latitude;
            }
            else if (args.Message is NmeaParser.Nmea.Gll)
            {
                Coords[0] = ((NmeaParser.Nmea.Gll)message).Longitude;
                Coords[1] = ((NmeaParser.Nmea.Gll)message).Latitude;
            }
            else
            {
                return;
            }

            if (Double.IsNaN(Coords[0]) || Double.IsNaN(Coords[1]))
            {
                return;                                                     // no fix yet
            }
            try {
                currentDevice.MessageReceived -= Device_MessageReceived; // unsubscribe to avoid multiple messages
                fixTimer.Enabled = false;
                fixTimer.Dispose();
            } catch (Exception ex) {
                Logger.Error(ex);
            }
            Notification.ShowSuccess(Locale.Loc.Instance["LblGPSLocationSet"]);
            gotGPSFix.TrySetResult(true);
        }
Beispiel #5
0
		private void OnMessageReceived(Nmea.NmeaMessage msg)
		{
			var args = new NmeaMessageReceivedEventArgs(msg);
			var multi = msg as IMultiPartMessage;
			if (multi != null)
			{
				args.IsMultipart = true;
				if (MultiPartMessageCache.ContainsKey(msg.MessageType))
				{
					var dic = MultiPartMessageCache[msg.MessageType];
					if (dic.ContainsKey(multi.MessageNumber - 1) && !dic.ContainsKey(multi.MessageNumber))
					{
						dic[multi.MessageNumber] = msg;
					}
					else //Something is out of order. Clear cache
						MultiPartMessageCache.Remove(msg.MessageType);
				}
				else if (multi.MessageNumber == 1)
				{
					MultiPartMessageCache[msg.MessageType] = new Dictionary<int, Nmea.NmeaMessage>(multi.TotalMessages);
					MultiPartMessageCache[msg.MessageType][1] = msg;
				}
				if (MultiPartMessageCache.ContainsKey(msg.MessageType))
				{
					var dic = MultiPartMessageCache[msg.MessageType];
					if (dic.Count == multi.TotalMessages) //We have a full list
					{
						MultiPartMessageCache.Remove(msg.MessageType);
						args.MessageParts = dic.Values.ToArray();
					}
				}
			}

			if (MessageReceived != null)
			{
				MessageReceived(this, args);
			}
		}