Пример #1
0
        /// <summary>
        /// Reads a single NMEA sentence then attempts to convert it into an object-oriented form.
        /// </summary>
        /// <returns></returns>
        public NmeaSentence ReadTypedSentence()
        {
            // First, read a valid sentence
            NmeaSentence sentence = ReadValidSentence();

            /* 5/4/07: The original design of GPS.NET 2.0 checked the entire command word to determine
             *         the sentence. However, the NMEA specification states that the first two letters of
             *         a sentence may change.  For example, for "$GPGSV" there may be variations such as
             *         "$__GSV" where the first two letters change.  As a result, we need only test the last three
             *         characters.
             */

            // Is this a GPRMC sentence?
            if (sentence.CommandWord.EndsWith("RMC", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return new GprmcSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum);
            }
            if (sentence.CommandWord.EndsWith("RMF", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return new PgrmfSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum);
            }
            else if (sentence.CommandWord.EndsWith("GGA", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return new GpggaSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum);
            }
            else if (sentence.CommandWord.EndsWith("GLL", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return new GpgllSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum);
            }
            else if (sentence.CommandWord.EndsWith("GSV", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return new GpgsvSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum);
            }
            else if (sentence.CommandWord.EndsWith("GSA", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return new GpgsaSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum);
            }
            else
            {
                // Raise an event to try and parse this
                if (ResolveSentence != null)
                {
                    NmeaSentenceResolverEventArgs e = new NmeaSentenceResolverEventArgs(sentence);
                    ResolveSentence(this, e);

                    // Was anything returned?
                    if (e.Result != null)
                        return e.Result;
                }

                // It's completely unrecognized, so return it as is
                return sentence;
            }
        }
Пример #2
0
        /// <summary>
        /// Reads a single NMEA sentence then attempts to convert it into an object-oriented form.
        /// </summary>
        /// <returns></returns>
        public NmeaSentence ReadTypedSentence()
        {
            // First, read a valid sentence
            NmeaSentence sentence = ReadValidSentence();

            /* 5/4/07: The original design of GPS.NET 2.0 checked the entire command word to determine
             *         the sentence. However, the NMEA specification states that the first two letters of
             *         a sentence may change.  For example, for "$GPGSV" there may be variations such as
             *         "$__GSV" where the first two letters change.  As a result, we need only test the last three
             *         characters.
             */

            // Is this a GPRMC sentence?
            if (sentence.CommandWord.EndsWith("RMC", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return(new GprmcSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum));
            }
            if (sentence.CommandWord.EndsWith("RMF", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return(new PgrmfSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum));
            }
            else if (sentence.CommandWord.EndsWith("GGA", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return(new GpggaSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum));
            }
            else if (sentence.CommandWord.EndsWith("GLL", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return(new GpgllSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum));
            }
            else if (sentence.CommandWord.EndsWith("GSV", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return(new GpgsvSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum));
            }
            else if (sentence.CommandWord.EndsWith("GSA", StringComparison.Ordinal))
            {
                // Yes.  Convert it using the fast pre-parseed constructor
                return(new GpgsaSentence(sentence.Sentence, sentence.CommandWord, sentence.Words, sentence.ExistingChecksum));
            }
            else
            {
                // Raise an event to try and parse this
                if (ResolveSentence != null)
                {
                    NmeaSentenceResolverEventArgs e = new NmeaSentenceResolverEventArgs(sentence);
                    ResolveSentence(this, e);

                    // Was anything returned?
                    if (e.Result != null)
                    {
                        return(e.Result);
                    }
                }

                // It's completely unrecognized, so return it as is
                return(sentence);
            }
        }