public void TestGpgsv() { string input = "$GPGSV,3,3,11,22,42,067,42,75,14,311,43,50,05,244,00,,,,*49"; var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gsv)); Gsv gsv = (Gsv)msg; Assert.AreEqual(3, gsv.TotalMessages); Assert.AreEqual(3, gsv.MessageNumber); Assert.AreEqual(11, gsv.SVsInView); Assert.IsNotNull(gsv.SVs); Assert.AreEqual(3, gsv.SVs.Count); var sv = gsv.SVs[0]; Assert.AreEqual(22, sv.PrnNumber); Assert.AreEqual(42, sv.Elevation); Assert.AreEqual(67, sv.Azimuth); Assert.AreEqual(42, sv.SignalToNoiseRatio); Assert.AreEqual(SatelliteSystem.Gps, sv.System); sv = gsv.SVs[1]; Assert.AreEqual(75, sv.PrnNumber); Assert.AreEqual(14, sv.Elevation); Assert.AreEqual(311, sv.Azimuth); Assert.AreEqual(43, sv.SignalToNoiseRatio); Assert.AreEqual(SatelliteSystem.Glonass, sv.System); sv = gsv.SVs[2]; Assert.AreEqual(50, sv.PrnNumber); Assert.AreEqual(5, sv.Elevation); Assert.AreEqual(244, sv.Azimuth); Assert.AreEqual(00, sv.SignalToNoiseRatio); Assert.AreEqual(SatelliteSystem.Waas, sv.System); }
public void TestGpgsv_Empty() { string input = "$GPGSV,1,1,0,,,,,,,,,,,,,,,,*49"; var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gsv)); Gsv gsv = (Gsv)msg; Assert.IsTrue(((IMultiSentenceMessage)gsv).IsComplete); Assert.AreEqual(0, gsv.SatellitesInView); Assert.IsNotNull(gsv.SVs); Assert.AreEqual(0, gsv.SVs.Count); }
public void TestGpgsv_Empty() { string input = "$GPGSV,1,1,0,,,,,,,,,,,,,,,,*49"; var msg = NmeaMessage.Parse(input); Assert.IsInstanceOfType(msg, typeof(Gsv)); Gsv gsv = (Gsv)msg; Assert.AreEqual(1, gsv.TotalMessages); Assert.AreEqual(1, gsv.MessageNumber); Assert.AreEqual(0, gsv.SVsInView); Assert.IsNotNull(gsv.SVs); Assert.AreEqual(0, gsv.SVs.Count); }
public void TestGpgsv_MissingElevationAndAzimuth() { string msgstr = "$GPGSV,3,1,12,02,06,225,16,04,,,40,05,65,251,27,07,40,057,43,0*51"; var msg = NmeaMessage.Parse(msgstr); Assert.IsInstanceOfType(msg, typeof(Gsv)); Gsv gsv = (Gsv)msg; Assert.IsFalse(((IMultiSentenceMessage)gsv).IsComplete); Assert.AreEqual(12, gsv.SatellitesInView); Assert.IsNotNull(gsv.SVs); Assert.AreEqual(4, gsv.SVs.Count); Assert.AreEqual(4, gsv.SVs[1].Id); Assert.IsTrue(double.IsNaN(gsv.SVs[1].Elevation)); Assert.IsTrue(double.IsNaN(gsv.SVs[1].Azimuth)); Assert.AreEqual(40, gsv.SVs[1].SignalToNoiseRatio); }
public void TestGpgsv_MissingElevationAndAzimuth() { string msgstr = "$GPGSV,3,1,12,02,06,225,16,04,,,40,05,65,251,27,07,40,057,43,0*51"; var msg = NmeaMessage.Parse(msgstr); Assert.IsInstanceOfType(msg, typeof(Gsv)); Gsv gsv = (Gsv)msg; Assert.AreEqual(3, gsv.TotalMessages); Assert.AreEqual(1, gsv.MessageNumber); Assert.AreEqual(12, gsv.SVsInView); Assert.IsNotNull(gsv.SVs); Assert.AreEqual(4, gsv.SVs.Count); Assert.AreEqual(4, gsv.SVs[1].PrnNumber); Assert.IsTrue(double.IsNaN(gsv.SVs[1].Elevation)); Assert.IsTrue(double.IsNaN(gsv.SVs[1].Azimuth)); Assert.AreEqual(40, gsv.SVs[1].SignalToNoiseRatio); }
public void TestGpgsv_MultiNotMatching() { var input2 = "$GPGSV,3,2,9,00,30,055,48,00,19,281,00,27,19,275,00,12,16,319,00*4F"; var input3 = "$GPGSV,3,3,9,32,10,037,00,,,,,,,,,,,,*74"; var msg2 = NmeaMessage.Parse(input2); Assert.IsFalse(((IMultiSentenceMessage)msg2).IsComplete); var msg3 = NmeaMessage.Parse(input3, msg2 as IMultiSentenceMessage); Assert.IsFalse(((IMultiSentenceMessage)msg3).IsComplete); Assert.IsInstanceOfType(msg2, typeof(Gsv)); Assert.AreNotSame(msg2, msg3); Gsv gsv2 = (Gsv)msg2; Assert.AreEqual(9, gsv2.SatellitesInView); Assert.IsNotNull(gsv2.SVs); Assert.AreEqual(4, gsv2.SVs.Count); Gsv gsv3 = (Gsv)msg3; Assert.AreEqual(9, gsv3.SatellitesInView); Assert.IsNotNull(gsv3.SVs); Assert.AreEqual(1, gsv3.SVs.Count); }
public void TestGpgsv_MultiMissing() { var input1 = "$GPGSV,2,1,9,00,30,055,48,00,19,281,00,27,19,275,00,12,16,319,00*4D"; var input2 = "$GPGSV,2,2,8,00,30,055,48,00,19,281,00,27,19,275,00,12,16,319,00*4F"; //Satellite count doesn't match, so append will fail var msg1 = NmeaMessage.Parse(input1); Assert.IsFalse(((IMultiSentenceMessage)msg1).IsComplete); var msg2 = NmeaMessage.Parse(input2, msg1 as IMultiSentenceMessage); Assert.IsFalse(((IMultiSentenceMessage)msg2).IsComplete); Assert.IsInstanceOfType(msg2, typeof(Gsv)); Assert.AreNotSame(msg1, msg2); Gsv gsv1 = (Gsv)msg1; Assert.AreEqual(9, gsv1.SatellitesInView); Assert.IsNotNull(gsv1.SVs); Assert.AreEqual(4, gsv1.SVs.Count); Gsv gsv2 = (Gsv)msg2; Assert.AreEqual(8, gsv2.SatellitesInView); Assert.IsNotNull(gsv2.SVs); Assert.AreEqual(4, gsv2.SVs.Count); }
public void TestGpgsv_Multi() { var input1 = "$GPGSV,3,1,9,00,30,055,48,00,19,281,00,27,19,275,00,12,16,319,00*4C"; var input2 = "$GPGSV,3,2,9,00,30,055,48,00,19,281,00,27,19,275,00,12,16,319,00*4F"; var input3 = "$GPGSV,3,3,9,32,10,037,00,,,,,,,,,,,,*74"; var msg1 = NmeaMessage.Parse(input1); Assert.IsFalse(((IMultiSentenceMessage)msg1).IsComplete); var msg2 = NmeaMessage.Parse(input2, msg1 as IMultiSentenceMessage); Assert.IsFalse(((IMultiSentenceMessage)msg2).IsComplete); var msg3 = NmeaMessage.Parse(input3, msg2 as IMultiSentenceMessage); Assert.IsTrue(((IMultiSentenceMessage)msg3).IsComplete); Assert.IsInstanceOfType(msg1, typeof(Gsv)); Assert.AreSame(msg1, msg2); Assert.AreSame(msg1, msg3); Gsv gsv = (Gsv)msg1; Assert.AreEqual(9, gsv.SatellitesInView); Assert.IsNotNull(gsv.SVs); Assert.AreEqual(9, gsv.SVs.Count); }
public void SetGsv(Gsv message) { messages[message.TalkerId + "+" + message.GnssSignalId] = message; UpdateSatellites(); }
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}"); }); }