コード例 #1
0
        public bool Parse(String nmea)
        {
            bool usedNmea = false;

            if (burst == null)
            {
                burst = new TNmeaBurst();
            }

            //try
            //{
            TalkerID tid = NmeaIDTools.ParseTalkerID(nmea);

            if (UsedTalkerIDs.Contains(tid))
            {
                NmeaSentence sentence = burst.AddNmeaSentence(nmea, tid);

                if (sentence != null &&
                    (!sentence.IsMultiString || ((MultiSentence)sentence).HasAllMessages))
                {
                    NmeaReceived?.Invoke(sentence);
                }

                usedNmea = true;
            }
            //}
            //catch (ExcessiveStringException e)
            //{
            //    Debug.WriteLine(e.Message, "NmeaParser:Parse");
            //}

            if (burst.IsFull)
            {
                burst.Validate();
                BurstReceived?.Invoke(burst);
                burst = null;
            }

            return(usedNmea);
        }
コード例 #2
0
        public NmeaSentence AddNmeaSentence(string sentence, TalkerID?tid = null)
        {
            if (sentence == null)
            {
                throw new ArgumentNullException();
            }

            if (!IsFull && NmeaSentence.validateChecksum(sentence))
            {
                TalkerID talkerID = tid != null ? (TalkerID)tid : NmeaIDTools.ParseTalkerID(sentence);

                switch (NmeaIDTools.ParseSentenceID(sentence))
                {
                case SentenceID.GGA:
                {
                    if (!gga.ContainsKey(talkerID))
                    {
                        ggaIsValidated = false;

                        GGASentence ggaSentence = new GGASentence(sentence);
                        gga.Add(talkerID, ggaSentence);
                        allSenteneces.Add(ggaSentence);
                        return(ggaSentence);
                    }
                    else
                    {
                        throw new ExcessiveStringException(SentenceID.GGA);
                    }
                }

                case SentenceID.GSA:
                {
                    gsaIsValidated = false;

                    GSASentence gsaSentence;
                    if (!gsa.ContainsKey(talkerID))
                    {
                        gsaSentence = new GSASentence(sentence);
                        gsa.Add(talkerID, gsaSentence);
                        allSenteneces.Add(gsaSentence);
                        return(gsaSentence);
                    }
                    else
                    {
                        gsaSentence = gsa[talkerID];
                        gsaSentence.Parse(sentence);
                        return(gsaSentence);
                    }
                }

                case SentenceID.RMC:
                {
                    if (!rmc.ContainsKey(talkerID))
                    {
                        rmcIsValidated = false;

                        RMCSentence rmcSentence = new RMCSentence(sentence);
                        rmc.Add(talkerID, rmcSentence);
                        allSenteneces.Add(rmcSentence);
                        return(rmcSentence);
                    }
                    else
                    {
                        throw new ExcessiveStringException(SentenceID.RMC);
                    }
                }

                case SentenceID.GSV:
                {
                    gsvIsValidated = false;

                    GSVSentence gsvSentence;
                    if (!gsv.ContainsKey(talkerID) || gsv[talkerID].TotalMessageCount == 0)
                    {
                        gsvSentence = new GSVSentence(sentence);
                        gsv.Add(talkerID, gsvSentence);
                        allSenteneces.Add(gsvSentence);
                        return(gsvSentence);
                    }
                    else
                    {
                        gsvSentence = gsv[talkerID];
                        if (gsvSentence.MessageCount < gsvSentence.TotalMessageCount)
                        {
                            gsvSentence.Parse(sentence);
                            return(gsvSentence);
                        }
                        else
                        {
                            throw new ExcessiveStringException(SentenceID.GSV);
                        }
                    }
                }
                }
            }

            return(null);
        }