Exemplo n.º 1
0
 /// <summary>
 /// constructor for GPSStringReceivedEventArgs
 /// </summary>
 /// <param name="data">GPS data recieved</param>
 public GPSStringReceivedEventArgs(GPSData data)
 {
     this.data = data;
 }
Exemplo n.º 2
0
        private bool parseNMEAStrings(string NMEAstrings)
        {
            gpsdata = new GPSData();
            string[] SplitNMEAStrings;
            string GPGGA = "";
            string GPRMC = "";

                SplitNMEAStrings = NMEAstrings.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string SplitNMEAString in SplitNMEAStrings)
                {
                    if (SplitNMEAString.Contains("$GPGGA"))
                    {
                        GPGGA = SplitNMEAString;
                    }
                    else if (SplitNMEAString.Contains("GPRMC"))
                    {
                        GPRMC = SplitNMEAString;
                    }
                }

                if (GPGGA == "" || GPRMC == "")
                {
                    return false;
                }

                string[] GPRMC_Data = GPRMC.Split(new string[] { "," }, StringSplitOptions.None);
                string[] GPGGA_Data = GPGGA.Split(new string[] { "," }, StringSplitOptions.None);
                try
                {
                    Double GPGGA_Lat = Convert.ToDouble(GPGGA_Data[2]);
                    gpsdata.Lat.Degrees = (byte)(GPGGA_Lat / 100.0);
                    gpsdata.Lat.Minutes = (byte)(GPGGA_Lat - gpsdata.Lat.Degrees * 100);
                    gpsdata.Lat.FractionalMinutes = Convert.ToUInt16((GPGGA_Lat % 1) * 10000.0);

                    Double GPGGA_Long = Convert.ToDouble(GPGGA_Data[4]);
                    gpsdata.Long.Degrees = (byte)(GPGGA_Long / 100.0);
                    gpsdata.Long.Minutes = (byte)(GPGGA_Long - gpsdata.Long.Degrees * 100);
                    gpsdata.Long.FractionalMinutes = Convert.ToUInt16((GPGGA_Long % 1) * 10000.0);

                    gpsdata.Altitude = Convert.ToDouble(GPGGA_Data[9]);

                    if (GPGGA_Data[4].ToUpper() == "N")
                    {
                        gpsdata.Lat.North = true;
                    }
                    else
                    {
                        gpsdata.Lat.North = false;
                    }
                    if (GPGGA_Data[6].ToUpper() == "E")
                    {
                        gpsdata.Long.East = true;
                    }
                    else
                    {
                        gpsdata.Long.East = false;
                    }
                    Double GPRMC_Time = Convert.ToDouble(GPRMC_Data[1]);

                    int hour = (int)(GPRMC_Time / 10000.0);
                    int min = (int)((GPRMC_Time - hour * 10000) / 100.0);
                    int d_sec = (int)(GPRMC_Time - hour * 10000 - min * 100);
                    int r_sec = (int)(GPRMC_Time % 1 * 1000);

                    string GPRMC_Date = GPRMC_Data[9];

                    int year = Convert.ToInt32(GPRMC_Date[4].ToString() + GPRMC_Date[5].ToString());
                    int month = Convert.ToInt32(GPRMC_Date[2].ToString() + GPRMC_Date[3].ToString());
                    int day = Convert.ToInt32(GPRMC_Date[0].ToString() + GPRMC_Date[1].ToString());

                    gpsdata.GPSDateTime = new DateTime(year + 2000, month, day, hour, min, d_sec, r_sec);

                    gpsdata.Velocity = Convert.ToDouble(GPRMC_Data[7]);
                    gpsdata.Course = Convert.ToDouble(GPRMC_Data[8]);

                    connected = true;
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Input string was not in a correct format.")
                    {
                        //this means the gps is not connected to satellites
                        connected = false;
                        return true;
                    }
                }

                return true;
        }