Esempio n. 1
0
        /// <summary>
        /// Adds a GPGSV sentence, and parses it.
        /// </summary>
        /// <param name="NMEAsentence">NMEA string</param>
        /// <returns>Returns true if this is the last message in GSV nmea sentences</returns>
        public bool AddSentence(string NMEAsentence)
        {
            bool lastmsg = false;

            try
            {
                //Split into an array of strings.
                string[] split      = NMEAsentence.Split(new Char[] { ',' });
                int      satsInView = GPSHandler.intTryParse(split[3]);
                int      msgCount   = GPSHandler.intTryParse(split[1]); //Number of GPGSV messages
                int      msgno      = GPSHandler.intTryParse(split[2]); //Current messagenumber

                if (msgCount < msgno || msgno < 1)                      //check for invalid data (could be zero if parse failed)
                {
                    return(false);
                }

                if (msgno == 1)
                {
                    _satellites.Clear();                     //First message. Let's clear the satellite list
                    firstMessageParsed = true;
                }
                else if (!firstMessageParsed)                 //If we haven't received the first GSV message, return
                {
                    return(false);
                }

                lastmsg = (msgCount == msgno);                 //Is this the last GSV message in the GSV messages?
                int satsInMsg;
                if (!lastmsg)
                {
                    satsInMsg = 4;                     //If this isn't the last message, the message will hold info for 4 satellites
                }
                else
                {
                    satsInMsg = satsInView - 4 * (msgno - 1);                     //calculate number of satellites in last message
                }
                for (int i = 0; i < satsInMsg; i++)
                {
                    Satellite sat = new Satellite();
                    sat.PRN       = split[i * 4 + 4];
                    sat.Elevation = Convert.ToByte(split[i * 4 + 5]);
                    sat.Azimuth   = Convert.ToInt16(split[i * 4 + 6]);
                    Byte.TryParse(split[i * 4 + 7], out sat.SNR);
                    //sat.SNR = Convert.ToByte(split[i * 4 + 7]);
                    _satellites.Add(sat);
                }
            }
            catch { }
            return(lastmsg);
        }
Esempio n. 2
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 Char[] { ',' });
                if (split[1].Length >= 6)
                {
                    TimeSpan t = new TimeSpan(GPSHandler.intTryParse(split[1].Substring(0, 2)),
                                              GPSHandler.intTryParse(split[1].Substring(2, 2)), GPSHandler.intTryParse(split[1].Substring(4, 2)));
                    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]);
                GPSHandler.dblTryParse(split[8], out _dilution);
                GPSHandler.dblTryParse(split[9], out _altitude);
                _altitudeUnits = split[10][0];
                GPSHandler.dblTryParse(split[11], out _heightOfGeoid);
                GPSHandler.intTryParse(split[13], out _dGPSUpdate);
                _dGPSStationID = split[14];
            }
            catch { }
        }