Beispiel #1
0
        /// <summary>
        /// Extracts a full NMEA string from the data recieved on the serialport, and parses this.
        /// The remaining and unparsed NMEA string is returned.
        /// </summary>
        /// <param name="strNMEA">NMEA ASCII data</param>
        /// <returns>Unparsed NMEA data</returns>
        private string GetNmeaString(string strNMEA)
        {
            strNMEA = strNMEA.Replace("\n", "").Replace("\r", ""); //Remove linefeeds

            int nStart = strNMEA.IndexOf("$");                     //Position of first NMEA data

            if (nStart < 0 || nStart == strNMEA.Length - 2)
            {
                return(strNMEA);
            }

            //This will never pass the last NMEA sentence, before the next one arrives
            //The following should instead stop at the end of the line.
            int nStop = strNMEA.IndexOf("$", nStart + 1);          //Position of next NMEA sentence

            if (nStop > -1)
            {
                string strData;
                strData = strNMEA.Substring(nStart, nStop - nStart).Trim();
                if (strData.StartsWith("$"))
                {
                    HasTimedOut        = false;
                    TimeSinceLastEvent = DateTime.Now.Ticks;
                    if (CheckSentence(strData))
                    {
                        FireEvent(GPSHandler.String2Eventtype(strData), strData);
                    }
                }
                return(strNMEA.Substring(nStop));
            }
            else
            {
                return(strNMEA);
            }
        }
Beispiel #2
0
        public MainForm()
        {
            InitializeComponent();

            GPS = new GPSHandler(this); //Initialize GPS handler
            GPS.TimeOut = 5; //Set timeout to 5 seconds
            GPS.NewGPSFix += new GPSHandler.NewGPSFixHandler(this.GPSEventHandler); //Hook up GPS data events to a handler
            frmGpsSettings = new FrmGpsSettings();
            frmNtripSettings = new FrmNTRIPSettings();
            ntrip = null;
            ntripStarted = false;
            Coms = new List<SerialPort>();
        }
Beispiel #3
0
 public void Emulator()
 {
     file = new System.IO.StreamReader(GPSHandler._NMEAInputFile);
     while (file != null)
     {
         if (file.EndOfStream)
         {
             //Start from beginning of file
             file.Close();
             file = new System.IO.StreamReader(GPSHandler._NMEAInputFile);
         }
         string line = file.ReadLine();
         SharpGps.SerialPort.GPSEventArgs e = new SharpGps.SerialPort.GPSEventArgs();
         e.TypeOfEvent = GPSHandler.String2Eventtype(line);
         e.Sentence    = line;
         NewGPSData(this, e);
         System.Threading.Thread.Sleep(50);
     }
 }
Beispiel #4
0
        private int urate = 1000; // Updaterate for all Params

        #endregion Fields

        #region Constructors

        public GpsDevice(HierachyItem owner)
        {
            GPS = new GPSHandler(); //Initialize GPS handler
            GPS.TimeOut = 5; //Set timeout to 5 seconds
            GPS.NewGPSFix += new GPSHandler.NewGPSFixHandler(this.GPSEventHandler); //Hook up GPS data events to a handle

            values = new MonitoredDictionary<string, UAVSingleParameter>(owner);
            if (!values.ContainsKey("lbRMCPosition")) values.Add(new UAVParameter("lbRMCPosition", GPS.GPRMC.Position, null,null, urate));
            if (!values.ContainsKey("lbRMCPositionLongitude")) values.Add(new UAVParameter("lbRMCPositionLongitude", 0, null,null, urate));
            if (!values.ContainsKey("lbRMCPositionLatitude")) values.Add(new UAVParameter("lbRMCPositionLatitude", 0, null,null, urate));
            if (!values.ContainsKey("lbRMCPositionUTM")) values.Add(new UAVParameter("lbRMCPositionUTM", 0, null,null, urate));
            if (!values.ContainsKey("lbRMCCourse")) values.Add(new UAVParameter("lbRMCCourse", 0, null,null, urate));
            if (!values.ContainsKey("lbRMCSpeed")) values.Add(new UAVParameter("lbRMCSpeed", 0, null,null, urate));
            if (!values.ContainsKey("lbRMCTimeOfFix")) values.Add(new UAVParameter("lbRMCTimeOfFix", 0, null,null, urate));
            if (!values.ContainsKey("lbRMCMagneticVariation")) values.Add(new UAVParameter("lbRMCMagneticVariation", 0, null,null, urate));
            if (!values.ContainsKey("lbGGAPosition")) values.Add(new UAVParameter("lbGGAPosition", 0, null,null, urate));
            if (!values.ContainsKey("lbGGATimeOfFix")) values.Add(new UAVParameter("lbGGATimeOfFix", 0, null,null, urate));
            if (!values.ContainsKey("lbGGAFixQuality")) values.Add(new UAVParameter("lbGGAFixQuality", 0, null,null, urate));
            if (!values.ContainsKey("lbGGANoOfSats")) values.Add(new UAVParameter("lbGGANoOfSats", 0, null,null, urate));
            if (!values.ContainsKey("lbGGAAltitude")) values.Add(new UAVParameter("lbGGAAltitude", 0, null,null, urate));
            if (!values.ContainsKey("lbGGAAltitudeUnit")) values.Add(new UAVParameter("lbGGAAltitudeUnit", 0, null,null, urate));

            if (!values.ContainsKey("lbGGAHDOP")) values.Add(new UAVParameter("lbGGAHDOP", 0, null,null, urate));
            if (!values.ContainsKey("lbGGAGeoidHeight")) values.Add(new UAVParameter("lbGGAGeoidHeight", 0, null,null, urate));
            if (!values.ContainsKey("lbGGADGPSupdate")) values.Add(new UAVParameter("lbGGADGPSupdate", 0, null,null, urate));
            if (!values.ContainsKey("lbGGADGPSID")) values.Add(new UAVParameter("lbGGADGPSID", 0, null,null, urate));
            if (!values.ContainsKey("lbGLLPosition")) values.Add(new UAVParameter("lbGLLPosition", 0, null,null, urate));
            if (!values.ContainsKey("lbGLLTimeOfSolution")) values.Add(new UAVParameter("lbGLLTimeOfSolution", 0, null,null, urate));
            if (!values.ContainsKey("lbGLLDataValid")) values.Add(new UAVParameter("lbGLLDataValid", 0, null,null, urate));
            if (!values.ContainsKey("lbGSAMode")) values.Add(new UAVParameter("lbGSAMode", 0, null,null, urate));
            if (!values.ContainsKey("lbGLLPosition")) values.Add(new UAVParameter("lbGLLPosition", 0,null,null, urate));
            if (!values.ContainsKey("lbGSAFixMode")) values.Add(new UAVParameter("lbGSAFixMode", 0, null,null, urate));
            if (!values.ContainsKey("lbGSAPRNs")) values.Add(new UAVParameter("lbGSAPRNs", 0, null,null, urate));
            if (!values.ContainsKey("lbGSAPDOP")) values.Add(new UAVParameter("lbGSAPDOP", 0, null,null, urate));
            if (!values.ContainsKey("lbGSAHDOP")) values.Add(new UAVParameter("lbGSAHDOP", 0, null,null, urate));
            if (!values.ContainsKey("lbGSAVDOP")) values.Add(new UAVParameter("lbGSAVDOP", 0, null,null, urate));
            if (!values.ContainsKey("lbRMEHorError")) values.Add(new UAVParameter("lbRMEHorError", 0, null,null, urate));
            if (!values.ContainsKey("lbRMEVerError")) values.Add(new UAVParameter("lbRMEVerError", 0, null,null, urate));
            if (!values.ContainsKey("lbRMESphericalError")) values.Add(new UAVParameter("lbRMESphericalError", 0, null,null, urate));
            if (!values.ContainsKey("lbRMEVerError")) values.Add(new UAVParameter("lbRMEVerError", 0, null,null, urate));
            if (!values.ContainsKey("lbRMEVerError")) values.Add(new UAVParameter("lbRMEVerError", 0, null,null, urate));
        }
Beispiel #5
0
        /// <summary>
        /// Responds to sentence events from GPS receiver
        /// </summary>
        private void GPSEventHandler(object sender, GPSHandler.GPSEventArgs e)
        {
            tbRawLog.Text += e.Sentence + "\r\n";
            if (tbRawLog.Text.Length > 20 * 1024 * 1024) //20Kb maximum - prevents crash
            {
                tbRawLog.Text = tbRawLog.Text.Substring(10 * 1024 * 1024);
            }
            tbRawLog.ScrollToCaret(); //Scroll to bottom

            switch (e.TypeOfEvent)
            {
                case GPSEventType.GPRMC:  //Recommended minimum specific GPS/Transit data
                    if (GPS.HasGPSFix) //Is a GPS fix available?
                    {
                        //lbRMCPosition.Text = GPS.GPRMC.Position.ToString("#.000000");
                        lbRMCPosition.Text = GPS.GPRMC.Position.ToString("DMS");
                        double[] utmpos = TransformToUTM(GPS.GPRMC.Position);
                        lbRMCPositionUTM.Text = utmpos[0].ToString("#.0N ") + utmpos[0].ToString("#.0E") + " (Zone: " + utmpos[2] + ")";
                        lbRMCCourse.Text = GPS.GPRMC.Course.ToString();
                        lbRMCSpeed.Text = GPS.GPRMC.Speed.ToString() + " mph";
                        lbRMCTimeOfFix.Text = GPS.GPRMC.TimeOfFix.ToString("F");
                        lbRMCMagneticVariation.Text = GPS.GPRMC.MagneticVariation.ToString();
                    }
                    else
                    {
                        statusBar1.Text = "No fix";
                        lbRMCCourse.Text = "N/A";
                        lbRMCSpeed.Text = "N/A";
                        lbRMCTimeOfFix.Text = GPS.GPRMC.TimeOfFix.ToString();
                    }
                    break;
                case GPSEventType.GPGGA: //Global Positioning System Fix Data
                    if (GPS.GPGGA.Position != null)
                        lbGGAPosition.Text = GPS.GPGGA.Position.ToString("DM");
                    else
                        lbGGAPosition.Text = "";
                    lbGGATimeOfFix.Text = GPS.GPGGA.TimeOfFix.Hour.ToString() + ":" + GPS.GPGGA.TimeOfFix.Minute.ToString() + ":" + GPS.GPGGA.TimeOfFix.Second.ToString();
                    lbGGAFixQuality.Text = GPS.GPGGA.FixQuality.ToString();
                    lbGGANoOfSats.Text = GPS.GPGGA.NoOfSats.ToString();
                    lbGGAAltitude.Text = GPS.GPGGA.Altitude.ToString() + " " + GPS.GPGGA.AltitudeUnits;
                    lbGGAHDOP.Text = GPS.GPGGA.Dilution.ToString();
                    lbGGAGeoidHeight.Text = GPS.GPGGA.HeightOfGeoid.ToString();
                    lbGGADGPSupdate.Text = GPS.GPGGA.DGPSUpdate.ToString();
                    lbGGADGPSID.Text = GPS.GPGGA.DGPSStationID;
                    break;
                case GPSEventType.GPGLL: //Geographic position, Latitude and Longitude
                    lbGLLPosition.Text = GPS.GPGLL.Position.ToString();
                    lbGLLTimeOfSolution.Text = (GPS.GPGLL.TimeOfSolution.HasValue ? GPS.GPGLL.TimeOfSolution.Value.Hours.ToString() + ":" + GPS.GPGLL.TimeOfSolution.Value.Minutes.ToString() + ":" + GPS.GPGLL.TimeOfSolution.Value.Seconds.ToString() : "");
                    lbGLLDataValid.Text = GPS.GPGLL.DataValid.ToString();
                    break;
                case GPSEventType.GPGSA: //GPS DOP and active satellites
                    if (GPS.GPGSA.Mode == 'A')
                        lbGSAMode.Text = "Auto";
                    else if (GPS.GPGSA.Mode == 'M')
                        lbGSAMode.Text = "Manual";
                    else lbGSAMode.Text = "";
                    lbGSAFixMode.Text = GPS.GPGSA.FixMode.ToString();
                    lbGSAPRNs.Text = "";
                    if (GPS.GPGSA.PRNInSolution.Count > 0)
                        foreach (string prn in GPS.GPGSA.PRNInSolution)
                            lbGSAPRNs.Text += prn + " ";
                    else
                        lbGSAPRNs.Text += "none";
                    lbGSAPDOP.Text = GPS.GPGSA.PDOP.ToString() + " (" + DOPtoWord(GPS.GPGSA.PDOP) + ")";
                    lbGSAHDOP.Text = GPS.GPGSA.HDOP.ToString() + " (" + DOPtoWord(GPS.GPGSA.HDOP) + ")";
                    lbGSAVDOP.Text = GPS.GPGSA.VDOP.ToString() + " (" + DOPtoWord(GPS.GPGSA.VDOP) + ")";
                    break;
                case GPSEventType.GPGSV: //Satellites in view
                    if (NMEAtabs.TabPages[NMEAtabs.SelectedIndex].Text == "GPGSV") //Only update this tab when it is active
                        DrawGSV();
                    break;
                case GPSEventType.PGRME: //Garmin proprietary sentences.
                    lbRMEHorError.Text = GPS.PGRME.EstHorisontalError.ToString();
                    lbRMEVerError.Text = GPS.PGRME.EstVerticalError.ToString();
                    lbRMESphericalError.Text = GPS.PGRME.EstSphericalError.ToString();
                    break;
                case GPSEventType.TimeOut: //Serialport timeout.
                    statusBar1.Text = "Serialport timeout";
                    /*notification1.Caption = "GPS Serialport timeout";
                    notification1.InitialDuration = 5;
                    notification1.Text = "Check your settings and connection";
                    notification1.Critical = false;
                    notification1.Visible = true;
                     */
                    break;
            }
        }