public void TestGPGGA_NoSats() { string input = "$GPGGA,181651.98,3403.47163804,N,11711.80926595,W,0,,,,M,,M,,*6E"; var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gga)); Gga gga = (Gga)msg; Assert.AreEqual(0, gga.NumberOfSatellites); }
public void TestGngga() { string input = "$GNGGA,231011.00,3403.47163804,N,11711.80926595,W,5,13,0.9,403.641,M,-32.133,M,1.0,0000*6D"; var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gga)); Gga gga = (Gga)msg; Assert.AreEqual(new TimeSpan(23, 10, 11), gga.FixTime); Assert.AreEqual(34.057860634, gga.Latitude); Assert.AreEqual(-117.19682109916667, gga.Longitude, 0.0000000001); Assert.AreEqual(NmeaParser.Nmea.Gga.FixQuality.FloatRtk, gga.Quality); Assert.AreEqual(13, gga.NumberOfSatellites); Assert.AreEqual(.9, gga.Hdop); Assert.AreEqual(403.641, gga.Altitude); Assert.AreEqual("M", gga.AltitudeUnits); Assert.AreEqual(-32.133, gga.HeightOfGeoid); Assert.AreEqual("M", gga.HeightOfGeoidUnits); Assert.AreEqual(0, gga.DgpsStationId); Assert.AreEqual(TimeSpan.FromSeconds(1), gga.TimeSinceLastDgpsUpdate); }
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(Gga)); Gga gga = (Gga)msg; Assert.AreEqual(new TimeSpan(23, 52, 36), gga.FixTime); Assert.AreEqual(39.432465, gga.Latitude); Assert.AreEqual(-119.7653516666666667, gga.Longitude, 0.0000000001); Assert.AreEqual(NmeaParser.Nmea.Gga.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); Assert.AreEqual(TimeSpan.MaxValue, gga.TimeSinceLastDgpsUpdate); }
static void Main(string[] args) { Logger logger = LogManager.GetCurrentClassLogger(); Parser.Default.ParseArguments <Options>(args) .WithParsed <Options>(o => { if (!Directory.Exists(o.InputFolder)) { logger.Error("Input folder does not exist... skipping"); return; } if (!Directory.Exists(o.Destination)) { logger.Info("output folder does not exist, creating"); Directory.CreateDirectory(o.Destination); } string[] gpsFiles = Directory.GetFiles(o.InputFolder, "*.gps", SearchOption.AllDirectories); logger.Info($"found {gpsFiles.Length} files"); DateTime maxSpeedDate = new DateTime(); DateTime currentDate = new DateTime(); DateTime lastDate = new DateTime(); bool dateSet = false; long maxSpeedKnots = 0; double longitude = 0; double latitude = 0; double alt = 0; bool latSet = false; bool longSet = false; bool altSet = false; int dayCount = 0; wptTypeCollection coll = new wptTypeCollection(); string gpxFileLocation = string.Empty; GpxClass track = new GpxClass(); List <wptType> waypoints = new List <wptType>(); for (int i = 0; i < gpsFiles.Length; i++) { string f = gpsFiles[i]; logger.Info($"Parsing {f}"); string[] lines = File.ReadAllLines(f); logger.Debug($"found {lines.Length} in {f}"); foreach (var readLine in lines) { DateTime internalDate = new DateTime(); string message = ""; if (readLine.StartsWith("[")) { long epoc = Convert.ToInt64(readLine.Split('[', ']')[1]); message = Regex.Replace(readLine, "\\[.*?\\]", ""); internalDate = UnixEPOCtoDateTime((double)epoc); if (currentDate.Date != internalDate.Date) { logger.Debug($"Date Change. old Date {currentDate} new Date {internalDate}"); currentDate = new DateTime(internalDate.Year, internalDate.Month, internalDate.Day); } if (!dateSet) { lastDate = currentDate; dateSet = true; } } if (message.StartsWith("$GPRMC") || message.StartsWith("$GNRMC")) //recomended minimum data for GPS { try { Rmc rmc = (Rmc)NmeaMessage.Parse(message); latitude = rmc.Latitude; longitude = rmc.Longitude; if ((double)maxSpeedKnots < rmc.Speed) { maxSpeedKnots = (long)rmc.Speed; maxSpeedDate = internalDate; } } catch (Exception ex) { logger.Warn($"GPRMC: {ex.Message}"); } } else if (message.StartsWith("$GPVTG") || message.StartsWith("$GNVTG")) // vector track and speed over ground { try { Vtg vtg = (Vtg)NmeaMessage.Parse(message); if ((double)maxSpeedKnots < vtg.SpeedKnots) { maxSpeedKnots = (long)vtg.SpeedKnots; maxSpeedDate = internalDate; } } catch (Exception ex) { logger.Warn($"$GPVTG: {ex.Message}"); } } else if (message.StartsWith("$GPGGA") || message.StartsWith("$GNGGA")) // fix information { try { Gga gga = (Gga)NmeaMessage.Parse(message); alt = gga.Altitude; longitude = gga.Longitude; latitude = gga.Latitude; latSet = true; longSet = true; altSet = true; } catch (Exception ex) { logger.Warn("GPGGA:" + ex.Message); } } else if (message.StartsWith("$GPGSA") || message.StartsWith("$GNGSA")) //overall satelite data { try { Gsa gsa = (Gsa)NmeaMessage.Parse(message); } catch (Exception ex) { logger.Warn("GPGSA:" + ex.Message); } } else if (message.StartsWith("$GPGSV") || message.StartsWith("$GNGSV")) { try { Gsv gsv = (Gsv)NmeaMessage.Parse(message); } catch (Exception ex) { logger.Warn("GPGSV:" + ex.Message); } } else if (message.StartsWith("$GPGLL") || message.StartsWith("$GNGLL")) { try { Gll gll = (Gll)NmeaMessage.Parse(message); longitude = gll.Longitude; latitude = gll.Latitude; latSet = true; longSet = true; } catch (Exception ex) { logger.Warn("GPGLL:" + ex.Message); } } if (latSet && longSet && altSet && CheckDouble(longitude) && CheckDouble(latitude) && CheckDouble(alt)) { waypoints.Add(new wptType(latitude, longitude, alt, internalDate)); latSet = false; longSet = false; altSet = false; if (lastDate.Date != currentDate.Date) { coll = new wptTypeCollection(); coll.AddRange(waypoints); track = new GpxClass(); track.Tracks.Add(new trkType() { name = currentDate.ToString(), trkseg = new trksegTypeCollection().AddItem( new trksegType() { trkpt = coll }) }); gpxFileLocation = Path.Combine(o.Destination, $"{lastDate.Date.ToString("yyyyMMdd")}.gpx"); track.ToFile(gpxFileLocation); waypoints = new List <wptType>(); dayCount++; lastDate = currentDate.Date; } } } } coll = new wptTypeCollection(); coll.AddRange(waypoints); track = new GpxClass(); track.Tracks.Add(new trkType() { name = currentDate.ToString(), trkseg = new trksegTypeCollection().AddItem( new trksegType() { trkpt = coll }) }); gpxFileLocation = Path.Combine(o.Destination, $"{lastDate.Date.ToString("yyyyMMdd")}.gpx"); track.ToFile(gpxFileLocation); Console.WriteLine($"Max speed: {maxSpeedKnots * 1.852}KM/h at {maxSpeedDate}"); }); }