/// <summary> /// Event handler for the SerialGPS, parses the NMEA message and updates CurrentGeopoint. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _serialGPSDevice_MessageReceived(object sender, NmeaMessageReceivedEventArgs e) { if (!_serialGPSDeviceFound) { _serialGPSDeviceFound = true; } double Latitude = 0.0, Longitude = 0.0; NMEAMessage = e.Message.ToString(); //Parse all NMEA messages supported by BU353-s4. //Only GGA, RMC, and GLL support location switch (e.Message.MessageType) { case "GPGGA": Gpgga gga = (Gpgga)e.Message; Latitude = gga.Latitude; Longitude = gga.Longitude; break; case "GPRMC": Gprmc rmc = (Gprmc)e.Message; Latitude = rmc.Latitude; Longitude = rmc.Longitude; break; case "GPGLL": Gpgll gll = (Gpgll)e.Message; Latitude = gll.Latitude; Longitude = gll.Longitude; break; case "GPGSA": Gpgsa gsa = (Gpgsa)e.Message; break; case "GPGSV": Gpgsv gsv = (Gpgsv)e.Message; break; } //make sure the delta-p is above a threshold if (Latitude != 0.0 && Longitude != 0.0) { double distance = Haversine(Latitude, Longitude, CurrentGeopoint.Position.Latitude, CurrentGeopoint.Position.Longitude); if (distance > 0) //2.5m is minimum accuracy of BU-353 S4 and WAAS/SBAS corrections { CurrentGeopoint = CreateGeopoint(Latitude, Longitude); } } }
private void NmeaStreamDevice_MessageReceived(object sender, NmeaMessageReceivedEventArgs e) { if (!messageStats.ContainsKey(e.Message.MessageType)) { messageStats.Add(e.Message.MessageType, 0); } messageStats[e.Message.MessageType]++; switch (e.Message.MessageType) { case "GPGSV": Gpgsv gpgsv = (Gpgsv)e.Message; numSattelites = gpgsv.SVsInView; break; case "GPGLL": //enthält GPS Daten Gpgll gpgll = (Gpgll)e.Message; if (gpgll.DataActive) { lon = gpgll.Longitude; lat = gpgll.Latitude; validGpsSignal = true; gpsLlTimestamp = DateTime.Now; } break; case "GPGSA": Gpgsa gpgsa = (Gpgsa)e.Message; fixMode = gpgsa.FixMode; break; case "GPRMC": //enthält GPS Daten Gprmc gprmc = (Gprmc)e.Message; break; case "GPVTG": break; case "GPZDA": break; case "GPGGA": //enthält GPS Daten Gpgga gpgga = (Gpgga)e.Message; altitude = gpgga.Altitude; break; default: lock (lockVictim) { tourStreamWriter.WriteLine(String.Format("UNIMP_GPS;", e.Message.ToString())); } break; } }
public void TestGpgga() { string input = "$GPGGA,235236,3925.9479,N,11945.9211,W,1,10,0.8,1378.0,M,-22.1,M,,*46"; var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gpgga)); Gpgga gga = (Gpgga)msg; Assert.AreEqual(new TimeSpan(23, 52, 36), gga.TimeSinceLastDgpsUpdate); Assert.AreEqual(39.432465, gga.Latitude); Assert.AreEqual(-119.7653516666666667, gga.Longitude, 0.0000000001); Assert.AreEqual(NmeaParser.Nmea.Gps.Gpgga.FixQuality.GpsFix, gga.Quality); Assert.AreEqual(10, gga.NumberOfSatellites); Assert.AreEqual(.8, gga.Hdop); Assert.AreEqual(1378, gga.Altitude); Assert.AreEqual("M", gga.AltitudeUnits); Assert.AreEqual(-22.1, gga.HeightOfGeoid); Assert.AreEqual("M", gga.HeightOfGeoidUnits); Assert.AreEqual(-1, gga.DgpsStationId); }
public int ParseNmeaMessage(Gpgga message) { int CogNow = 0; NavigationDisplay navi = new NavigationDisplay(); int SecondsNow = message.FixTime.Seconds; SecondsNow = SecondsNow == 60 ? 0 : SecondsNow; if (SecondsNow > Seconds) { if (NavMessages.Count > 1000) { NavMessages.Dequeue(); } NavMessages.Enqueue(message); var ImmediateCOG = FindCOGFromQueue(0, 5); CogNow = ImmediateCOG; navi.NavReadings.CogSlow = NavMessages.Count(); } Seconds = SecondsNow; return(CogNow); }
public bool IsGoodMessage(Gpgga newReading) { return(newReading.NumberOfSatellites > 3 && Math.Abs(newReading.Latitude) > 0); }