示例#1
0
        /// <summary>CTor</summary>
        /// <param name="gps">GPS provider</param>
        public SatellitesView(GpsProvider gps)
        {
            if (gps == null)
            {
                throw new ArgumentNullException("gps");
            }

            this.gps = gps;
            this.gps.Start();
            InitializeComponent();
            gps.Satellite += GpsSatellite;
        }
示例#2
0
        private void GpsSatellite(GpsProvider sender, GpsSatelliteEventArgs e)
        {
            //Don't want the form to lock up if nothing's happening.
            System.Threading.Thread.Sleep(200);
            if (this.IsDisposed) return;
            if (InvokeRequired)
            {
                if ((DateTime.Now - lastGpsSatellite).TotalMilliseconds < 200)
                {
                    return;
                }

                BeginInvoke(new GpsSatelliteEventHandler(GpsSatellite), sender, e);
                return;
            }

            lastGpsSatellite = DateTime.Now;

            List<GpsSatellite> satl = new List<GpsSatellite>();
            foreach (GpsSatellite sat in e.Satellites)
            {
                if (sat.ID != 0)
                {
                    satl.Add(sat);
                }
            }

            if ((lblId == null) || (lblId.Length != satl.Count))
            {
                CreateLabels(satl.Count);
            }

            int i = 0;
            lvwSatellites.Items.Clear();
            foreach (var sat in satl)
            {
                lblId[i].Text = sat.ID.ToString();
                lblSnr[i].Tag = sat.SignalToNoiseRatio;
                lblSnr[i].Text = sat.SignalToNoiseRatio.ToString();
                lblSnr[i].BackColor = GetColorFromSnr(sat.SignalToNoiseRatio, sat.Active);
                lblSnr[i].ForeColor = Color.FromArgb((byte)~lblSnr[i].BackColor.R, (byte)~lblSnr[i].BackColor.G, (byte)~lblSnr[i].BackColor.B);

                ListViewItem itm = new ListViewItem(new[]{
                    sat.ID.ToString(),
                    sat.SignalToNoiseRatio.ToString(),
                    sat.Active.ToString(),
                    sat.Azimuth.ToString(),
                    sat.Elevation.ToString()
                });
                lvwSatellites.Items.Add(itm);

                ++i;
            }

            PosLabels();
            satellites = satl;
            panPosition.Invalidate();
        }
示例#3
0
 private void SatellitesView_Closed(object sender, EventArgs e)
 {
     if(gps != null)
     {
         gps.Satellite -= GpsSatellite;
         gps = null;
     }
 }
示例#4
0
        /// <summary>Called when a GPS sencence is received</summary>
        /// <param name="sender">A GPS provider</param>
        /// <param name="e">Event arguments containing a GPS sentence</param>
        void GpsSentenceEvent(GpsProvider sender, GpsSentenceEventArgs e)
        {
            if (logEverything)
            {//Verbose (to textbox)

                System.Threading.Thread.Sleep(200); //It might go too fast.

                if (e.Sentence != previousSentence)
                {
                    lock (sentenceCounterSyncObj) sentenceCounter = e.Counter;
                    LogSentence(e);
                    previousSentence = e.Sentence;
                }
            }

            if (AdvancedConfig.NmeaLog)
            {//NMEA file logging
                if (nmeaFileName == null)
                {
                    string nmeaFileLocation;

                    if (String.IsNullOrEmpty(AdvancedConfig.LogFileLocation))
                    {
                        nmeaFileLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                    }
                    else
                    {
                        nmeaFileLocation = AdvancedConfig.LogFileLocation;
                    }

                    nmeaFileName = Path.Combine(nmeaFileLocation, DateTime.Now.ToString("yyyyMMdd_HHmmss",
                                                                                CultureInfo.InvariantCulture) + ".nmea");
                }

                if (!File.Exists(nmeaFileName))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(nmeaFileName)))
                    {
                        try
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(nmeaFileName));
                        }
                        catch (Exception ex)
                        {
                            WriteToTextbox(string.Format(Properties.Resources.err_NmeaCreateDir, nmeaFileName, ex.Message));
                            return;
                        }
                    }
                }

                try
                {
                    using (FileStream file = File.Open(nmeaFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
                    {
                        file.Seek(file.Length, SeekOrigin.Begin);
                        StreamWriter w = new StreamWriter(file);
                        w.WriteLine(e.Sentence);
                        w.Flush();
                    }
                }
                catch (Exception ex)
                {
                    WriteToTextbox(string.Format(Properties.Resources.err_NmeaOpenFile, nmeaFileName, ex.Message));
                }
            }
        }
示例#5
0
        private void saveMenuItem_Click(object sender, EventArgs e)
        {
            if (CheckBoxToFile.Checked && String.IsNullOrEmpty(logLocationTextBox.Text))
            {
                MessageBox.Show(Properties.Resources.err_BadPath);
                return;
            }

            if (satellitesWindow != null)
            {
                satellitesWindow.Close(); //To prevent it from using different GPS provider
            }

            HookGps(false);
            gpsInstance.Dispose();
            gpsInstance = null;

            AdvancedConfig.ComPort = ComboBoxCOMPorts.Text;
            AdvancedConfig.BaudRate = (BaudRates)int.Parse(ComboBaudRate.Text);
            AdvancedConfig.PollingInterval = (int)NumericUpDownInterval.Value;
            AdvancedConfig.LogToTextBox = CheckBoxToTextBox.Checked;
            AdvancedConfig.LogToLogFile = CheckBoxToFile.Checked;
            AdvancedConfig.LogFileLocation = logLocationTextBox.Text;
            AdvancedConfig.LogAltitude = chkAltitude.Checked;
            AdvancedConfig.UseWindowsDriver = chkUseWindowsDriver.Checked;

            if (radioButtonKML.Checked)
            {
                AdvancedConfig.LogFormat = LogFormat.KML;
            }
            else if (optCSV.Checked)
            {
                AdvancedConfig.LogFormat = LogFormat.CSV;
            }
            else
            {
                AdvancedConfig.LogFormat = LogFormat.GPX;
            }

            if (optTrack.Checked)
            {
                AdvancedConfig.TrackType = TrackType.Track;
            }
            else
            {
                AdvancedConfig.TrackType = TrackType.Points;
            }

            AdvancedConfig.Store();
            ConfigurationManager.Save();

            HidePanel(settingsPanel);
            HidePanel(aboutPanel);
            ShowPanel(mainPanel);
        }
示例#6
0
 /// <summary>Called when GPS device receives information about satellites</summary>
 /// <param name="sender">A GPS provider</param>
 /// <param name="e">Event arguments containing information about sattellites</param>
 private void GpsSatelliteEvent(GpsProvider sender, GpsSatelliteEventArgs e)
 {
     if (statistic == null && InvokeRequired)
     {
         BeginInvoke(new GpsSatelliteEventHandler(GpsSatelliteEvent), sender, e);
         return;
     }
     int cnt = 0;
     foreach (GpsSatellite sat in e.Satellites)
     {
         if (sat.SignalToNoiseRatio != 0)
         {
             ++cnt;
         }
     }
     if (statistic != null)
     {
         statistic.CurrentSats = cnt;
     }
     else
     {
         lblSatellites.Text = cnt.ToString();
     }
 }
示例#7
0
        /// <summary>Called when GPS position is received</summary>
        /// <param name="sender">A GPS provider</param>
        /// <param name="e">Event arguments containing actual GPS position</param>
        void GpsPositionReceived(GpsProvider sender, GpsPositionEventArgs e)
        {
            GpsPosition pos = e.Position;
            if (waitForStop || !gpsRunning)
            {
                return;
            }

            if ((DateTime.Now - lastGpsLoggedAt).TotalMilliseconds < 10)
            {
                return; //I've experianced multiple logs at same place in same time
            }

            if (pos.Longitude.HasValue && pos.Latitude.HasValue)
            {
                afterStart = false;
                invalidPositionCount = 0;
                lastGpsLoggedAt = DateTime.Now;
                DateTime time = AdvancedConfig.UseGpsTime ? pos.GpsTime.ToLocalTime() : DateTime.Now;
                decimal? altitude = pos.Altitude.HasValue ? pos.Altitude + (decimal)AdvancedConfig.AltitudeCorrection : null;

                string gpsData = string.Format(
                    AdvancedConfig.TextLogFormat,
                    time.ToUniversalTime(),
                    Math.Round(pos.Longitude.Value, 7),
                    Math.Round(pos.Latitude.Value, 7),
                    altitude.HasValue ? Math.Round(altitude.Value, 7) : 0,
                    time,
                    AdvancedConfig.ElevationUnitName,
                    statistic == null ? 0.0M : statistic.SumLength * AdvancedConfig.DistanceMultiplier,
                    AdvancedConfig.DistanceUnitName
                );

                if (!positionLogged)
                {
                    bool logThisPoint = false; //Check if the point is not too neer to stop-start point
                    decimal? distance = null;
                    if (lastPositionA == null)
                    {
                        //Stop-start point unknown (immediately after start)
                        logThisPoint = true;
                    }
                    else
                    {
                        distance = Math.Abs(GpsPosition.CalculateDistance(lastPositionA.Value, pos, OpenNETCF.IO.Serial.GPS.Units.Kilometers) * 1000);
                        if (distance < AdvancedConfig.MinimalDistance)
                        {
                            //Point is to near
                            lastPositionC = pos; //Remember it
                            lastTimeC = time;    //And remember the time
                        }
                        else
                        {
                            //Points are far enough
                            logThisPoint = true;//Log this point
                            if (lastPositionC != null && time != lastTimeA && lastTimeA != lastTimeC)
                            {
                                WriteToFile(
                                    lastTimeC,
                                    Convert.ToDouble(Math.Round(lastPositionC.Value.Latitude.Value, 7)),
                                    Convert.ToDouble(Math.Round(lastPositionC.Value.Longitude.Value, 7)),
                                    Convert.ToDouble(Math.Round(lastPositionC.Value.Altitude.HasValue ? lastPositionC.Value.Altitude.Value + AdvancedConfig.AltitudeCorrection : 0, 7))
                                );
                            }
                        }
                    }

                    WriteToTextbox(gpsData + (logThisPoint ? "" : " X"));
                    OnPoint(time, new GpsPoint(pos.Latitude.Value, pos.Longitude.Value, pos.Altitude), logThisPoint);

                    if (logThisPoint)
                    {
                        if (distance.HasValue)
                        {
                            ShowSpeed(distance.Value / 1000 / (decimal)(time - lastTimeA).TotalHours);
                        }

                        Status(Properties.Resources.status_PositionReceived);
                        lastPositionA = pos; //Remember position
                        lastTimeA = time;    //Remember time
                        lastPositionC = pos;
                        lastTimeC = time;
                        WriteToFile(
                            time,
                            Convert.ToDouble(Math.Round(pos.Latitude.Value, 7)),
                            Convert.ToDouble(Math.Round(pos.Longitude.Value, 7)),
                            Convert.ToDouble(altitude.HasValue ? Math.Round(altitude.Value, 7) : 0));

                    }
                    else
                    {
                        Status(string.Format(Properties.Resources.PointsTooNear, distance));
                    }

                    StopGps();
                }
                positionLogged = true;
            }
            else
            {
                if (++invalidPositionCount == int.MaxValue)
                {
                    invalidPositionCount = 0;
                }

                if (!afterStart && AdvancedConfig.InvalidPositionsMax != 0 && invalidPositionCount >= AdvancedConfig.InvalidPositionsMax)
                {
                    invalidPositionCount = 0;
                    Status(string.Format(Properties.Resources.status_InvalidPosWait, invalidPositionCount));
                    StopGps();
                }
                else if (afterStart || AdvancedConfig.InvalidPositionsMax == 0)
                {
                    if ((DateTime.Now - lastInvPosUserTime).TotalMilliseconds >= 900)
                    {
                        Status(string.Format("inv. pos. {0}", invalidPositionCount));
                        lastInvPosUserTime = DateTime.Now;
                    }
                }
                else
                {
                    if ((DateTime.Now - lastInvPosUserTime).TotalMilliseconds >= 900)
                    {
                        Status(string.Format(Properties.Resources.status_InvalidPos, invalidPositionCount));
                        lastInvPosUserTime = DateTime.Now;
                    }
                }

            }
        }
示例#8
0
 /// <summary>Called when GPS movement information is received</summary>
 /// <param name="sender">A GPS provider</param>
 /// <param name="e">Event arguments containing movement data</param>
 private void GpsMovementEvent(GpsProvider sender, GpsMovementEventArgs e)
 {
     if (statistic != null)
     {
         statistic.ActualSpeed = e.Speed;
     }
 }
示例#9
0
 /// <summary>Called when error occurs in GPS device</summary>
 /// <param name="sender">A GPS provider</param>
 /// <param name="message">Error message text</param>
 /// <param name="exception">Exceptin which caused error to occur. May be null.</param>
 void GpsErrorRaised(GpsProvider sender, string message, Exception exception)
 {
     if (logEverything)
     {
         WriteToTextbox(message/* + ". The GPS data is: " + gps_data*/);
         if (exception != null)
         {
             WriteExceptionToTextBox(exception);
         }
     }
     Status(Properties.Resources.err_ErrorTitle + " " + (exception == null ? message : exception.Message));
 }
示例#10
0
        /// <summary>Called when GPS provider status changes</summary>
        /// <param name="sender">A GPS provider</param>
        /// <param name="state">Current status of <paramref name="sender"/></param>
        void GpsCommStateChanged(GpsProvider sender, GpsState state)
        {
            switch (state)
            {
                /*case States.AutoDiscovery:
                    if (logEverything)  WriteToTextbox("AutoDiscovery");
                    Status("Auto discovery");
                    break;*/
                case GpsState.Opening:
                    if (logEverything)
                    {
                        WriteToTextbox(Properties.Resources.Opening);
                    }

                    Status(Properties.Resources.status_Opening);
                    break;
                case GpsState.Open:
                    if (logEverything)
                    {
                        WriteToTextbox(Properties.Resources.Running);
                    }
                    Status(Properties.Resources.status_Running);
                    break;
                case GpsState.Closed:
                    if (logEverything)
                    {
                        WriteToTextbox(Properties.Resources.Stopped);
                    }

                    Status(Properties.Resources.Status_Stopped);
                    break;
                case GpsState.Closing:
                    if (logEverything)
                    {
                        WriteToTextbox(Properties.Resources.Stopping);
                    }
                    Status(Properties.Resources.Status_Stopping);
                    break;
            }
        }