Exemple #1
0
        //=======================================================================
        #region -= static methods =-

        //=======================================================================
        public static GsaData Parse(string inputString)
        {
            //---- declare vars
            GsaData data       = new GsaData();
            string  dataString = inputString.Substring(0, inputString.IndexOf('*'));            // strip off the checksum

            string[] values = dataString.Split(',');

            //---- if we don't have 18 (header + 17), it's no good
            if (values.Length < 18)
            {
                throw new FormatException();
            }

            //---- mode
            data.FixMode = FixModeUtil.Parse(values[1]);

            //---- fix type
            data.FixType = (FixType)int.Parse(values[2]);

            //---- loop through the satellites (3-14)
            for (int i = 3; i < 15; i++)
            {
                if (!string.IsNullOrEmpty(values[i]))
                {
                    //---- create a new satellite
                    Satellite sat = new Satellite();

                    //---- these we don't know, so set to -1/false
                    sat.AngleOfElvation   = -1;
                    sat.Azimuth           = -1;
                    sat.SignalStrength    = -1;
                    sat.UsedInPositionFix = false;

                    //---- get the satellite ID
                    sat.ID = int.Parse(values[i]);

                    //---- add the sat to the collection
                    data.SatellitesUsed.Add(sat);
                }
            }


            try
            {
                //---- PDOP
                data.DilutionOfPrecision = decimal.Parse(values[15]);

                //---- HDOP
                data.HorizontalDilutionOfPrecision = decimal.Parse(values[16]);

                //---- VDOP
                data.VerticalDilutionOfPrecision = decimal.Parse(values[17]);
            }
            catch (FormatException e)
            {
            }

            //---- return
            return(data);

            //GPS DOP and active satellites

            //eg1. $GPGSA,A,3,,,,,,16,18,,22,24,,,3.6,2.1,2.2*3C
            //eg2. $GPGSA,A,3,19,28,14,18,27,22,31,39,,,,,1.7,1.0,1.3*35

            //1    = Mode:
            //       M=Manual, forced to operate in 2D or 3D
            //       A=Automatic, 3D/2D
            //2    = Mode:
            //       1=Fix not available
            //       2=2D
            //       3=3D
            //3-14 = IDs of SVs used in position fix (null for unused fields)
            //15   = PDOP
            //16   = HDOP
            //17   = VDOP
        }
Exemple #2
0
        //=======================================================================
        #region -= static methods =-

        //=======================================================================
        public static GsvData Parse(string inputString)
        {
            //---- declare vars
            GsvData data       = new GsvData();
            string  dataString = inputString.Substring(0, inputString.IndexOf('*'));            // strip off the checksum

            string[] values = dataString.Split(',');

            //---- if we don't have 20 (header + 19), it's no good
            if (values.Length < 20)
            {
                return(data);
            }

            //---- number of messages
            data.MessageCount = int.Parse(values[1]);

            //---- message number
            data.MessageNumber = int.Parse(values[2]);

            //---- total number of satellites in view
            data.SatellitesInView = int.Parse(values[3]);

            //---- loop through the satellites (up to 4)
            for (int i = 0; i < 4; i++)
            {
                //---- create a new satellite
                Satellite sat = new Satellite();

                //---- satellite information starts at index 4, goes for 4 lines, and then starts over (4-7), (8-11), (12-15), (16-19)
                int satIndex = (4 + (4 * i));

                //---- satellite ID
                sat.ID = (string.IsNullOrEmpty(values[satIndex]) ? 0 : int.Parse(values[satIndex]));

                //---- if we got a satellite
                if (sat.ID > 0)
                {
                    //---- elevation
                    sat.AngleOfElvation = (string.IsNullOrEmpty(values[satIndex + 1]) ? 0 : int.Parse(values[satIndex + 1]));

                    //---- azimuth
                    sat.Azimuth = (string.IsNullOrEmpty(values[satIndex + 2]) ? 0 : int.Parse(values[satIndex + 2]));

                    //---- signal strength
                    sat.SignalStrength = (string.IsNullOrEmpty(values[satIndex + 3]) ? 0 : int.Parse(values[satIndex + 3]));

                    //---- used in fix? [TODO: Verify this assumption of signal 00 is all right]
                    if (sat.SignalStrength > 0)
                    {
                        sat.UsedInPositionFix = true;
                    }
                    else
                    {
                        sat.UsedInPositionFix = false;
                    }

                    //---- add the sat
                    data.Satellites.Add(sat);
                }
            }

            //---- return
            return(data);

            //$GPGSV,1,1,13,02,02,213,,03,-3,000,,11,00,121,,14,13,172,05*67
            //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
        }