Exemple #1
0
        private void Parse(int sourceID, string message)
        {
            NMEAIncomingMessageReceived.Rise(this, new NMEAMessageEventArgs(sourceID, message));

            try
            {
                var pResult = NMEAParser.Parse(message);

                if (pResult is NMEAStandartSentence)
                {
                    NMEAStandartSentence sentence = (NMEAStandartSentence)pResult;
                    if (standardSenteceParsers.ContainsKey(sentence.SentenceID))
                    {
                        standardSenteceParsers[sentence.SentenceID](sourceID, sentence.TalkerID, sentence.parameters);
                    }
                    else
                    {
                        NMEAStandartUnsupportedSentenceParsed.Rise(this, new NMEAUnsupportedStandartEventArgs(sourceID, sentence));
                    }
                }
                else
                {
                    NMEAProprietaryUnsupportedSentenceParsed.Rise(this, new NMEAUnsupportedProprietaryEventArgs(sourceID, (pResult as NMEAProprietarySentence)));
                }
            }
            catch (Exception ex)
            {
                LogEventHandler.Rise(this, new LogEventArgs(LogLineType.ERROR, ex));
            }
        }
Exemple #2
0
 public NMEAUnsupportedStandartEventArgs(int sourceID, NMEAStandartSentence sentence)
 {
     SourceID = sourceID;
     Sentence = sentence;
 }
Exemple #3
0
        private void gtrPort_NewNMEAMessage(object sender, NewNMEAMessageEventArgs e)
        {
            logger.Write(string.Format("{0} (RedGTR) >> {1}", gtrPort.PortName, e.Message));

            try
            {
                var result = NMEAParser.Parse(e.Message);

                if (result is NMEAProprietarySentence)
                {
                    NMEAProprietarySentence pResult = result as NMEAProprietarySentence;

                    if (pResult.Manufacturer == ManufacturerCodes.TNT)
                    {
                        if (pResult.SentenceIDString == "0") // ACK
                        {
                            Parse_ACK(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "!") // Device info
                        {
                            Parse_DEVICE_INFO(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "5")
                        {
                            Parse_LOC_DATA_VAL(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "9")
                        {
                            Parse_REM_RECEIVED(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "B")
                        {
                            Parse_REM_TOUT(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "C")
                        {
                            Parse_REM_PONG(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "D")
                        {
                            Parse_REM_PONGEX(pResult.parameters);
                        }
                        else if (pResult.SentenceIDString == "O")
                        {
                            Parse_PRETMP_VAL(pResult.parameters);
                        }
                    }
                    else
                    {
                        // not supported manufacturer code
                    }
                }
                else
                {
                    NMEAStandartSentence sSentence = result as NMEAStandartSentence;

                    if (sSentence.SentenceID == SentenceIdentifiers.RMC)
                    {
                        Parse_RMC(sSentence.parameters);
                    }
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex, false);
            }
        }
Exemple #4
0
        public override void ProcessIncoming(NMEASentence sentence)
        {
            if (sentence is NMEAStandartSentence)
            {
                NMEAStandartSentence nSentence = (sentence as NMEAStandartSentence);

                if (detected)
                {
                    ResetTimer();
                }

                if (nSentence.SentenceID == SentenceIdentifiers.HDT)
                {
                    if (!detected)
                    {
                        detected = true;
                    }

                    double hdn = O2D(nSentence.parameters[0]);
                    if (!double.IsNaN(hdn))
                    {
                        Heading = hdn;
                        HeadingUpdated.Rise(this, new EventArgs());
                    }
                }
                else if (nSentence.SentenceID == SentenceIdentifiers.RMC)
                {
                    if (!detected)
                    {
                        detected = true;
                    }

                    DateTime tStamp = nSentence.parameters[0] == null ? DateTime.MinValue : (DateTime)nSentence.parameters[0];

                    var      latitude         = O2D(nSentence.parameters[2]);
                    var      longitude        = O2D(nSentence.parameters[4]);
                    var      groundSpeed      = O2D(nSentence.parameters[6]);
                    var      courseOverGround = O2D(nSentence.parameters[7]);
                    DateTime dateTime         = nSentence.parameters[8] == null ? DateTime.MinValue : (DateTime)nSentence.parameters[8];

                    bool isValid = (nSentence.parameters[1].ToString() != "Invalid") &&
                                   (!double.IsNaN(latitude)) && latitude.IsValidLatDeg() &&
                                   (!double.IsNaN(longitude)) && longitude.IsValidLonDeg() &&
                                   (!double.IsNaN(groundSpeed)) &&
                                   (nSentence.parameters[11].ToString() != "N");

                    if (isValid)
                    {
                        dateTime    = dateTime.AddHours(tStamp.Hour);
                        dateTime    = dateTime.AddMinutes(tStamp.Minute);
                        dateTime    = dateTime.AddSeconds(tStamp.Second);
                        dateTime    = dateTime.AddMilliseconds(tStamp.Millisecond);
                        groundSpeed = 3.6 * NMEAParser.Bend2MpS(groundSpeed);

                        if (nSentence.parameters[3].ToString() == "S")
                        {
                            latitude = -latitude;
                        }
                        if (nSentence.parameters[5].ToString() == "W")
                        {
                            longitude = -longitude;
                        }

                        Latitude         = latitude;
                        Longitude        = longitude;
                        GroundSpeed      = groundSpeed;
                        CourseOverGround = courseOverGround;
                        GNSSTime         = dateTime;

                        LocationUpdated.Rise(this, new EventArgs());
                    }
                }
            }
        }
Exemple #5
0
        private void port_NewNMEAMessage(object sender, NewNMEAMessageEventArgs e)
        {
            if (LogEvent != null)
            {
                LogEvent(this, new LogEventArgs(LogLineType.INFO, string.Format("<< {0}", e.Message)));
            }

            try
            {
                var sentence = NMEAParser.Parse(e.Message);

                if (sentence is NMEAProprietarySentence)
                {
                    NMEAProprietarySentence snt = ((NMEAProprietarySentence)(sentence));

                    if (snt.SentenceIDString == "0")
                    {
                        // ACK - analyze error code
                        Process_ACK(snt.parameters);
                    }
                    else if (snt.SentenceIDString == "5")
                    {
                        // local data value
                        Process_LOC_DATA(snt.parameters);
                    }
                    else if (snt.SentenceIDString == "!")
                    {
                        // device info
                        Process_DEVICE_INFO(snt.parameters);
                    }
                    else if (snt.SentenceIDString == "C")
                    {
                        Process_FIX_UPDATE(snt.parameters);
                    }
                    else if (snt.SentenceIDString == "M")
                    {
                        Process_BUOYS_STATUS(snt.parameters);
                    }
                    else if (snt.SentenceIDString == "N")
                    {
                        Process_DPTTMP(snt.parameters);
                    }
                    else if (snt.SentenceIDString == "O")
                    {
                        Process_PRETMP(snt.parameters);
                    }
                    else
                    {
                        if (LogEvent != null)
                        {
                            LogEvent(this, new LogEventArgs(LogLineType.ERROR, string.Format("Unsupported sentence ID: {0}", snt.SentenceIDString)));
                        }
                    }
                }
                else
                {
                    NMEAStandartSentence snt = ((NMEAStandartSentence)(sentence));

                    if (snt.SentenceID == SentenceIdentifiers.GGA)
                    {
                        Process_GGA(snt.parameters);
                    }
                    else if (snt.SentenceID == SentenceIdentifiers.RMC)
                    {
                        Process_RMC(snt.parameters);
                    }
                    else if (snt.SentenceID == SentenceIdentifiers.MTW)
                    {
                        Process_MTW(snt.parameters);
                    }
                    else
                    {
                        if (LogEvent != null)
                        {
                            LogEvent(this, new LogEventArgs(LogLineType.ERROR, string.Format("Unsupported sentence ID: {0}", snt.SentenceID)));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (LogEvent != null)
                {
                    LogEvent(this, new LogEventArgs(LogLineType.ERROR, ex));
                }
            }
        }