コード例 #1
0
 /// <summary>
 /// Parses the word at the given position to Azimuth.
 /// </summary>
 /// <param name="position">Position of the Words array that gets parsed to Azimuth.</param>
 /// <returns>Invalid if position is outside of Words array or word at the position is empty.</returns>
 protected Azimuth ParseAzimuth(int position)
 {
     if (Words.Length <= position || Words[position].Length == 0)
     {
         return(Azimuth.Invalid);
     }
     return(Azimuth.Parse(Words[position], NmeaCultureInfo));
 }
コード例 #2
0
        /// <summary>
        /// Overrides OnSentanceChanged for the GPVTGSentence
        /// </summary>
        protected override void OnSentenceChanged()
        {
            // First, process the basic info for the sentence
            base.OnSentenceChanged();

            // Cache the sentence words
            string[] words     = Words;
            int      wordCount = words.Length;

            /*
             * $GPVTG
             *
             *  Track Made Good and Ground Speed.
             *
             *  eg1. $GPVTG, 360.0, T, 348.7, M, 000.0, N, 000.0, K*43
             *  eg2. $GPVTG, 054.7, T, 034.4, M, 005.5, N, 010.2, K
             *
             *             054.7, T      True track made good
             *             034.4, M      Magnetic track made good
             *             005.5, N      Ground speed, knots
             *             010.2, K      Ground speed, Kilometers per hour
             *
             *  eg3. $GPVTG, t, T, ,, s.ss, N, s.ss, K*hh
             *  0    = Track made good
             *  1    = Fixed text 'T' indicates that track made good is relative to true north
             *  2    = not used
             *  3    = not used
             *  4    = Speed over ground in knots
             *  5    = Fixed text 'N' indicates that speed over ground in in knots
             *  6    = Speed over ground in kilometers/hour
             *  7    = Fixed text 'K' indicates that speed over ground is in kilometers/hour
             *
             *
             *
             */

            #region Heading

            if (wordCount >= 1 && words[0].Length != 0)
            {
                _heading = Azimuth.Parse(words[0], NmeaCultureInfo);
            }
            else
            {
                _heading = Azimuth.Invalid;
            }

            #endregion Heading
        }
コード例 #3
0
        /// <summary>
        /// Overrides OnSentanceChanged for the GPVTGSentence
        /// </summary>
        protected override void OnSentenceChanged()
        {
            // First, process the basic info for the sentence
            base.OnSentenceChanged();

            // Cache the sentence words
            string[] words     = base.Words;
            int      wordCount = words.Length;

            /*
             * $GPVTG
             *
             *  Track Made Good and Ground Speed.
             *
             *  eg1. $GPVTG,360.0,T,348.7,M,000.0,N,000.0,K*43
             *  eg2. $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K
             *
             *
             *             054.7,T      True track made good
             *             034.4,M      Magnetic track made good
             *             005.5,N      Ground speed, knots
             *             010.2,K      Ground speed, Kilometers per hour
             *
             *
             *  eg3. $GPVTG,t,T,,,s.ss,N,s.ss,K*hh
             *  1    = Track made good
             *  2    = Fixed text 'T' indicates that track made good is relative to true north
             *  3    = not used
             *  4    = not used
             *  5    = Speed over ground in knots
             *  6    = Fixed text 'N' indicates that speed over ground in in knots
             *  7    = Speed over ground in kilometers/hour
             *  8    = Fixed text 'K' indicates that speed over ground is in kilometers/hour
             *
             *
             *
             */

            #region Bearing

            if (wordCount >= 1 && words[0].Length != 0)
            {
                _Bearing = Azimuth.Parse(words[0], NmeaCultureInfo);
            }
            else
            {
                _Bearing = Azimuth.Invalid;
            }

            #endregion

            #region Magnetic Variation

            if (wordCount >= 3 && words[2].Length != 0)
            {
                _MagneticVariation = new Longitude(double.Parse(words[2], NmeaCultureInfo) - _Bearing.DecimalDegrees);
            }
            else
            {
                _MagneticVariation = Longitude.Invalid;
            }

            #endregion

            #region Speed

            /* Speed is reported as both knots and KM/H.  We can parse either of the values.
             * First, try to parse knots.  If that fails, parse KM/h.
             */

            if (wordCount > 6 && words[5].Length != 0)
            {
                _Speed = new Speed(
                    // Parse the numeric portion
                    double.Parse(words[5], NmeaCultureInfo),
                    // Use knots
                    SpeedUnit.Knots);
            }
            else if (wordCount > 8 && words[7].Length != 0)
            {
                _Speed = new Speed(
                    // Parse the numeric portion
                    double.Parse(words[7], NmeaCultureInfo),
                    // Use knots
                    SpeedUnit.KilometersPerHour);
            }
            else
            {
                // Invalid speed
                _Speed = Speed.Invalid;
            }

            #endregion
        }
コード例 #4
0
        /// <summary>
        /// Corrects this classes properties after the base sentence was changed.
        /// </summary>
        private new void SetPropertiesFromSentence()
        {
            // Cache the words
            string[] words     = Words;
            int      wordCount = words.Length;

            /*  $GPGSV
             *
             *  GPS Satellites in view
             *
             *  eg. $GPGSV, 3, 1, 11, 03, 03, 111, 00, 04, 15, 270, 00, 06, 01, 010, 00, 13, 06, 292, 00*74
             *  $GPGSV, 3, 2, 11, 14, 25, 170, 00, 16, 57, 208, 39, 18, 67, 296, 40, 19, 40, 246, 00*74
             *  $GPGSV, 3, 3, 11, 22, 42, 067, 42, 24, 14, 311, 43, 27, 05, 244, 00, ,, ,*4D
             *
             *
             *  $GPGSV, 1, 1, 13, 02, 02, 213, ,03, -3, 000, ,11, 00, 121, ,14, 13, 172, 05*62
             *
             *
             *  1    = Total number of messages of this type in this cycle
             *  2    = Message number
             *  3    = Total number of SVs in view
             *  4    = SV PRN number
             *  5    = Elevation in degrees, 90 maximum
             *  6    = Azimuth, degrees from true north, 000 to 359
             *  7    = SNR, 00-99 dB (null when not tracking)
             *  8-11 = Information about second SV, same as field 4-7
             *  12-15= Information about third SV, same as field 4-7
             *  16-19= Information about fourth SV, same as field 4-7
             */

            // Example (signal not acquired): $GPGSV, 1, 1, 01, 21, 00, 000, *4B
            // Example (signal acquired): $GPGSV, 3, 1, 10, 20, 78, 331, 45, 01, 59, 235, 47, 22, 41, 069, ,13, 32, 252, 45*70

            // Get the total message count
            if (wordCount > 0 && words[0].Length != 0)
            {
                TotalMessageCount = int.Parse(words[0], NmeaCultureInfo);
            }

            // Get the current message number
            if (wordCount > 1 && words[1].Length != 0)
            {
                CurrentMessageNumber = int.Parse(words[1], NmeaCultureInfo);
            }

            // Get the total message count
            if (wordCount > 2 && words[2].Length != 0)
            {
                SatellitesInView = int.Parse(words[2], NmeaCultureInfo);
            }

            // Make a new list of satellites
            Satellites = new List <Satellite>();

            // Now process each satellite
            for (int index = 0; index < 6; index++)
            {
                int currentWordIndex = index * 4 + 3;
                // Are we past the length of words?
                if (currentWordIndex > wordCount - 1)
                {
                    break;
                }
                // No.  Get the unique code for the satellite
                if (words[currentWordIndex].Length == 0)
                {
                    continue;
                }

                int                pseudorandomNumber = int.Parse(words[currentWordIndex], NmeaCultureInfo);
                Elevation          newElevation;
                Azimuth            newAzimuth;
                SignalToNoiseRatio newSignalToNoiseRatio;

                // Update the elevation
                if (wordCount > currentWordIndex + 1 && words[currentWordIndex + 1].Length != 0)
                {
                    newElevation = Elevation.Parse(words[currentWordIndex + 1], NmeaCultureInfo);
                }
                else
                {
                    newElevation = Elevation.Empty;
                }

                // Update the azimuth
                if (wordCount > currentWordIndex + 2 && words[currentWordIndex + 2].Length != 0)
                {
                    newAzimuth = Azimuth.Parse(words[currentWordIndex + 2], NmeaCultureInfo);
                }
                else
                {
                    newAzimuth = Azimuth.Empty;
                }

                // Update the signal strength
                if (wordCount > currentWordIndex + 3 && words[currentWordIndex + 3].Length != 0)
                {
                    newSignalToNoiseRatio = SignalToNoiseRatio.Parse(words[currentWordIndex + 3], NmeaCultureInfo);
                }
                else
                {
                    newSignalToNoiseRatio = SignalToNoiseRatio.Empty;
                }

                // Add the satellite to the collection
                Satellites.Add(new Satellite(pseudorandomNumber, newAzimuth, newElevation, newSignalToNoiseRatio, false));
            }
        }