예제 #1
0
        //=======================================================================

        //=======================================================================
        public static bool TryParse(string inputString, out GsaData gsaData)
        {
            try
            {
                gsaData = Parse(inputString);
                return(true);
            }
            catch
            {
                gsaData = null;
                return(false);
            }
        }
예제 #2
0
        //=======================================================================

        //=======================================================================
        private static GpsReading ParseSentences(string[] sentences)
        {
            //---- declare vars
            GpsReading gpsReading = new GpsReading();

            //---- loop through each sentence
            for (int i = 0; i < sentences.Length; i++)
            {
                //---- if the sentence has a header and data
                if (sentences[i].Length > 6)
                {
                    switch (sentences[i].Trim().Substring(0, 6).ToUpper())
                    {
                    case "$GPGSA":
                        gpsReading.DopActiveSatellites = GsaData.Parse(sentences[i]);
                        break;

                    case "$GPGSV":
                        gpsReading.SatellitesInView.Add(GsvData.Parse(sentences[i]));
                        break;

                    case "$GPGGA":
                        gpsReading.FixedGpsData = GgaData.Parse(sentences[i]);
                        break;

                    case "$GPRMC":
                        gpsReading.Summary = RmcData.Parse(sentences[i]);
                        break;

                    case "$GPMSS":
                        break;

                    case "$GPVTG":
                        break;
                    }
                }
            }

            //---- return our parsed gps reading
            return(gpsReading);
        }
예제 #3
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
        }