Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the NMEA Geographic position, Latitude and Longitude and parses an NMEA sentence
        /// </summary>
        /// <param name="nmeaSentence"></param>
        public GPGLL(string nmeaSentence)
        {
            try
            {
                //Split into an array of strings.
                string[] split = nmeaSentence.Split(new[] { ',' });

                try
                {
                    _position = new Coordinate(GpsHandler.GPSToDecimalDegrees(split[3], split[4]),
                                               GpsHandler.GPSToDecimalDegrees(split[1], split[2]));
                }
                catch { _position = null; }

                try
                {
                    _timeOfSolution = new TimeSpan(int.Parse(split[5].Substring(0, 2)),
                                                   int.Parse(split[5].Substring(2, 2)),
                                                   int.Parse(split[5].Substring(4)));
                }
                catch
                {
                    _timeOfSolution = null; // TimeSpan.Zero;
                }
                _dataValid = (split[6] == "A");
            }
            catch { }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the NMEA Recommended minimum specific GPS/Transit data and parses an NMEA sentence
        /// </summary>
        /// <param name="nmeaSentence"></param>
        public GPRMC(string nmeaSentence)
        {
            try
            {
                //Split into an array of strings.
                string[] split = nmeaSentence.Split(new[] { ',' });

                //Extract date/time
                try
                {
                    string[] dateTimeFormats = { "ddMMyyHHmmss", "ddMMyy", "ddMMyyHHmmss.FFFFFF" };
                    if (split[9].Length >= 6)              //Require at least the date to be present
                    {
                        string time = split[9] + split[1]; // +" 0";
                        _timeOfFix = DateTime.ParseExact(time, dateTimeFormats, GpsHandler.NumberFormatEnUs, System.Globalization.DateTimeStyles.AssumeUniversal);
                    }
                    else
                    {
                        _timeOfFix = new DateTime();
                    }
                }
                catch { _timeOfFix = new DateTime(); }

                _status = split[2] == "A" ? StatusEnum.Ok : StatusEnum.Warning;

                _position = new Coordinate(GpsHandler.GPSToDecimalDegrees(split[5], split[6]),
                                           GpsHandler.GPSToDecimalDegrees(split[3], split[4]));

                double.TryParse(split[7], out _speed);
                double.TryParse(split[8], out _course);
                double.TryParse(split[10], out _magneticVariation);
            }
            catch { }
        }
Ejemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();

            Gps = new GpsHandler {
                TimeOut = 5
            };                                //Initialize GPS handler
            Gps.NewGpsFix += GpsEventHandler; //Hook up GPS data events to a handler
            FrmGpsSettings = new FrmGpsSettings();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the NMEA Global Positioning System Fix Data and parses an NMEA sentence
        /// </summary>
        /// <param name="nmeaSentence"></param>
        public GPGGA(string nmeaSentence)
        {
            try
            {
                if (nmeaSentence.IndexOf('*') > 0)
                {
                    nmeaSentence = nmeaSentence.Substring(0, nmeaSentence.IndexOf('*'));
                }
                //Split into an array of strings.
                string[] split = nmeaSentence.Split(new[] { ',' });
                if (split[1].Length >= 6)
                {
                    var hrs = 0;
                    var min = 0;
                    var sec = 0;

                    int.TryParse(split[1].Substring(0, 2), out hrs);
                    int.TryParse(split[1].Substring(2, 2), out min);
                    int.TryParse(split[1].Substring(4, 2), out sec);


                    TimeSpan t      = new TimeSpan(hrs, min, sec);
                    DateTime nowutc = DateTime.UtcNow;
                    nowutc     = nowutc.Add(-nowutc.TimeOfDay);
                    _timeOfFix = nowutc.Add(t);
                }

                _position = new Coordinate(GpsHandler.GPSToDecimalDegrees(split[4], split[5]),
                                           GpsHandler.GPSToDecimalDegrees(split[2], split[3]));
                if (split[6] == "1")
                {
                    FixQuality = FixQualityEnum.GPS;
                }
                else if (split[6] == "2")
                {
                    FixQuality = FixQualityEnum.DGPS;
                }
                else
                {
                    FixQuality = FixQualityEnum.Invalid;
                }
                _noOfSats = Convert.ToByte(split[7]);
                double.TryParse(split[8], out _dilution);
                double.TryParse(split[9], out _altitude);
                _altitudeUnits = split[10][0];
                double.TryParse(split[11], out _heightOfGeoid);
                int.TryParse(split[13], out _dGPSUpdate);
                _dGPSStationID = split[14];
            }
            catch { }
        }