Example #1
0
 public GpsPointData(Rmc rmc)
 {
     FixTime           = rmc.FixTime;
     Active            = rmc.Active;
     Latitude          = rmc.Latitude;
     Longitude         = rmc.Longitude;
     GpsSpeed          = rmc.Speed;
     Course            = rmc.Course;
     MagneticVariation = rmc.MagneticVariation;
     Altitude          = 0;
 }
Example #2
0
        public void TestGprmc()
        {
            string input = "$GPRMC,123519,A,4807.038,S,01131.000,W,022.4,084.4,230313,003.1,W*6A";
            var    msg   = NmeaMessage.Parse(input);

            Assert.IsInstanceOfType(msg, typeof(Rmc));
            Rmc rmc = (Rmc)msg;

            Assert.AreEqual(new DateTime(2013, 03, 23, 12, 35, 19, DateTimeKind.Utc), rmc.FixTime);
            Assert.AreEqual(-48.1173, rmc.Latitude);
            Assert.AreEqual(-11.516666666666667, rmc.Longitude, 0.0000000001);
        }
Example #3
0
        public void TestGnrmc()
        {
            string input = "$GNRMC,231011.00,A,3403.47163804,N,11711.80926595,W,0.019,11.218,201217,12.0187,E,D*01";
            var    msg   = NmeaMessage.Parse(input);

            Assert.IsInstanceOfType(msg, typeof(Rmc));
            Rmc rmc = (Rmc)msg;

            Assert.AreEqual("GNRMC", rmc.MessageType);
            Assert.AreEqual(new DateTime(2017, 12, 20, 23, 10, 11, DateTimeKind.Utc), rmc.FixTime);
            Assert.AreEqual(34.057860634, rmc.Latitude, 0.0000000001);
            Assert.AreEqual(-117.19682109916667, rmc.Longitude, 0.0000000001);
            Assert.AreEqual(true, rmc.Active);
            Assert.AreEqual(11.218, rmc.Course);
            Assert.AreEqual(12.0187, rmc.MagneticVariation);
            Assert.AreEqual(0.019, rmc.Speed);
        }
Example #4
0
        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}");
            });
        }