Example #1
0
        public static GPGGAString ProcessGPGGA(string data)
        {
            GPGGAString GPGGA = new GPGGAString();

            try
            {
                //skip the message type
                data = data.Substring(data.IndexOf(',') + 1);

                string[] fields = Regex.Split(data, ",");

                GPGGA.Hour   = Convert.ToInt32(fields[0].Substring(0, 2));
                GPGGA.Minute = Convert.ToInt32(fields[0].Substring(2, 2));
                GPGGA.Second = Convert.ToInt32(fields[0].Substring(4, 2));

                GPGGA.Latitude = Convert.ToDouble(fields[1]) / 100;
                if (fields[2] == "S")
                {
                    GPGGA.LatitudeHemisphere = CompassDirection.South;
                }
                else
                {
                    GPGGA.LatitudeHemisphere = CompassDirection.North;
                }

                GPGGA.Longitude = Convert.ToDouble(fields[3]) / 100;
                if (fields[4] == "E")
                {
                    GPGGA.LatitudeHemisphere = CompassDirection.East;
                }
                else
                {
                    GPGGA.LatitudeHemisphere = CompassDirection.West;
                }

                GPGGA.GPSQuality = (GPSQuality)Convert.ToUInt32(fields[5]);

                GPGGA.NumSats = Convert.ToInt32(fields[6]);

                GPGGA.HDOP = Convert.ToDouble(fields[7]);

                GPGGA.Altitude = Convert.ToDouble(fields[8]);
            }
            catch (Exception e)
            {
            }

            return(GPGGA);
        }
Example #2
0
        public static GPGGAString ProcessGPGGA(string data)
        {
            GPGGAString GPGGA = new GPGGAString();

            try
            {
                //skip the message type
                data = data.Substring(data.IndexOf(',')+1);

                string[] fields = Regex.Split(data, ",");

                GPGGA.Hour = Convert.ToInt32(fields[0].Substring(0, 2));
                GPGGA.Minute = Convert.ToInt32(fields[0].Substring(2, 2));
                GPGGA.Second = Convert.ToInt32(fields[0].Substring(4, 2));

                GPGGA.Latitude = Convert.ToDouble(fields[1]) / 100;
                if (fields[2] == "S")
                    GPGGA.LatitudeHemisphere = CompassDirection.South;
                else
                    GPGGA.LatitudeHemisphere = CompassDirection.North;

                GPGGA.Longitude = Convert.ToDouble(fields[3]) / 100;
                if (fields[4] == "E")
                    GPGGA.LatitudeHemisphere = CompassDirection.East;
                else
                    GPGGA.LatitudeHemisphere = CompassDirection.West;

                GPGGA.GPSQuality = (GPSQuality)Convert.ToUInt32(fields[5]);

                GPGGA.NumSats = Convert.ToInt32(fields[6]);

                GPGGA.HDOP = Convert.ToDouble(fields[7]);

                GPGGA.Altitude = Convert.ToDouble(fields[8]);

            }
            catch (Exception e)
            {

            }

            return GPGGA;
        }
Example #3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!worker.CancellationPending)
            {
                if (locked)
                {
                    continue;
                }

                locked = true;

                byte[] buffer = new byte[256];
                this.tcpClient.Client.Receive(buffer);

                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                string message = encoding.GetString(buffer).Trim();

                //super super amazingly crappy 'parsing' of the string. Please don't ever use this. Just for testing quickly...

                if (message.Contains("$GPGGA"))
                {
                    try
                    {
                        message = message.Substring(message.IndexOf("$GPGGA"), 61);
                        GPGGAString data = NMEA.ProcessGPGGA(message);

                        //at some point should integrate gyro/accelerometer to get pitch/yaw/roll information
                        PositionData position = new PositionData(data.Longitude, data.Latitude, data.Altitude, 0, 0, 0);
                        this.LastPosition = position;

                        if (this.started)
                        {
                            this.OnPositionRecieved(position);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }

                locked = false;
            }
        }