Example #1
0
 /// <summary>Raises the <see cref="GpsSentence"/> event</summary>
 /// <param name="e">Event arguments</param>
 protected virtual void OnGpsSentence(GpsSentenceEventArgs e)
 {
     if (GpsSentence != null)
     {
         GpsSentence(this, e);
     }
 }
Example #2
0
 void LogSentence(GpsSentenceEventArgs e)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new Action<GpsSentenceEventArgs>(LogSentence), e);
         return;
     }
     lock (sentenceCounterSyncObj)
     {
         if (sentenceCounter - e.Counter > 10)
         {
             return; //Too much sentences in queue for logging
         }
     }
     WriteToTextbox(e.Sentence);
     if (!logSentenceOnStack)
     {
         logSentenceOnStack = true;
         try { Application.DoEvents(); }
         finally { logSentenceOnStack = false; }
     }
 }
Example #3
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));
                }
            }
        }
Example #4
0
 /// <summary>Raises the <see cref="GpsSentence"/> event</summary>
 /// <param name="e">Event arguments</param>
 protected virtual void OnGpsSentence(GpsSentenceEventArgs e)
 {
     if (GpsSentence != null) GpsSentence(this, e);
 }