コード例 #1
0
        public static String GetName(this TalkerID talkerID)
        {
            FieldInfo fi = talkerID.GetType().GetField(talkerID.ToString());

            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(talkerID.ToString());
            }
        }
コード例 #2
0
        public static TalkerID ParseTalkerID(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException();
            }

            if (value.StartsWith("$"))
            {
                value = value.Substring(1, 2);
            }

            TalkerID tid = TalkerID.Unknown;

            Enum.TryParse(value, true, out tid);

            return(tid);
        }
コード例 #3
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);
        }
コード例 #4
0
 public static String ToStringCode(this TalkerID talkerID)
 {
     return(talkerID == TalkerID.Unknown ? "$??" : $"${talkerID}");
 }
コード例 #5
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);
        }
コード例 #6
0
 public NmeaParser(TalkerID talkerID)
 {
     UsedTalkerIDs = new List <TalkerID>();
     UsedTalkerIDs.Add(talkerID);
 }