Exemplo n.º 1
0
        private void OnRMCSentence(int sourceID, TalkerIdentifiers talkerID, object[] parameters)
        {
            if (RMCSentenceReceived != null)
            {
                DateTime tStamp = parameters[0] == null ? DateTime.MinValue : (DateTime)parameters[0];

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

                bool isValid = (parameters[1].ToString() != "Invalid") &&
                               (!double.IsNaN(latitude)) && latitude.IsValidLatDeg() &&
                               (!double.IsNaN(longitude)) && longitude.IsValidLonDeg() &&
                               (!double.IsNaN(groundSpeed)) &&
                               //(!double.IsNaN(courseOverGround)) &&
                               (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 (parameters[3].ToString() == "S")
                    {
                        latitude = -latitude;
                    }
                    if (parameters[5].ToString() == "W")
                    {
                        longitude = -longitude;
                    }
                }

                RMCSentenceReceived.Rise(this, new RMCMessageEventArgs(sourceID, talkerID, dateTime, latitude, longitude, groundSpeed, courseOverGround, magneticVariation, isValid));
            }
        }
Exemplo n.º 2
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());
                    }
                }
            }
        }