void CreateLog(string logfile) { TextReader tr = new StreamReader(logfile); // this.Invoke( (System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile + "\n"); }); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; updateDisplay(); }
void CreateLog(string logfile) { TextReader tr = new StreamReader(logfile); // AppendSerialLog(string.Format(LogStrings.CreatingKmlPrompt, Path.GetFileName(logfile))); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = SerialStatus.Done; }
private void BUT_firstperson_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { Directory.CreateDirectory(Settings.Instance.LogDir); openFileDialog1.InitialDirectory = Settings.Instance.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir cannot be created if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { AppendSerialLog(Environment.NewLine + Environment.NewLine + string.Format(LogStrings.ProcessingLog, logfile)); this.Refresh(); LogOutput lo = new LogOutput(); try { TextReader tr = new StreamReader(logfile); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { AppendSerialLog(LogStrings.ErrorProcessingLogfile + Environment.NewLine + ex.Message); continue; } lo.writeKMLFirstPerson(logfile + "-fp.kml"); AppendSerialLog(LogStrings.Done); } } } }
private void BUT_firstperson_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = Settings.Instance.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { TXT_seriallog.AppendText("\n\nProcessing " + logfile + "\n"); this.Refresh(); LogOutput lo = new LogOutput(); try { TextReader tr = new StreamReader(logfile); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing log. Is it still downloading? " + ex.Message); continue; } lo.writeKMLFirstPerson(logfile + "-fp.kml"); TXT_seriallog.AppendText("Done\n"); } } } }
private void BUT_redokml_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = MainV2.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { TXT_seriallog.AppendText("\n\nProcessing " + logfile + "\n"); this.Refresh(); LogOutput lo = new LogOutput(); try { TextReader tr = new StreamReader(logfile); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex.ToString()); } lo.writeKML(logfile + ".kml"); TXT_seriallog.AppendText("Done\n"); } } } }
private void BUT_redokml_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = Settings.Instance.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { AppendSerialLog(Environment.NewLine + Environment.NewLine + string.Format(LogStrings.ProcessingLog, logfile)); this.Refresh(); LogOutput lo = new LogOutput(); try { using (TextReader tr = new StreamReader(logfile)) { while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } } } catch (Exception ex) { AppendSerialLog(LogStrings.ErrorProcessingLogfile + Environment.NewLine + ex.ToString()); } lo.writeKML(logfile + ".kml"); AppendSerialLog(LogStrings.Done); } } } }
private void BUT_firstperson_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = MainV2.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { TXT_seriallog.AppendText("\n\nProcessing " + logfile + "\n"); this.Refresh(); LogOutput lo = new LogOutput(); try { TextReader tr = new StreamReader(logfile); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing log. Is it still downloading? " + ex.Message); continue; } lo.writeKMLFirstPerson(logfile + "-fp.kml"); TXT_seriallog.AppendText("Done\n"); } } } }
void CreateLog(string logfile) { TextReader tr = new StreamReader(logfile); // this.Invoke((System.Windows.Forms.MethodInvoker)delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile + "\n"); }); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; updateDisplay(); }
private void but_dflogtokml_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "Log Files|*.log;*.bin"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = Settings.Instance.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { LogOutput lo = new LogOutput(); try { StreamReader tr; if (logfile.ToLower().EndsWith(".bin")) { using (tr = new StreamReader(logfile)) { GC.Collect(); CollectionBuffer temp = new CollectionBuffer(tr.BaseStream); uint a = 0; foreach (var line in temp) { lo.processLine(line); a++; if ((a % 100000) == 0) Console.WriteLine(a); } temp.Dispose(); } } else { using (tr = new StreamReader(logfile)) { while (!tr.EndOfStream) { lo.processLine(tr.ReadLine()); } tr.Close(); } } } catch (Exception ex) { CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex); } lo.writeKML(logfile + ".kml"); } } } }
void CreateLog(string logfile) { TextReader tr = new StreamReader(logfile); // LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error }
void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (comPort.BytesToRead > 0 && threadrun) { updateDisplay(); string line = ""; comPort.ReadTimeout = 500; try { line = comPort.ReadLine(); //readline(comPort); if (!line.Contains("\n")) line = line + "\n"; } catch { line = comPort.ReadExisting(); //byte[] data = readline(comPort); //line = Encoding.ASCII.GetString(data, 0, data.Length); } receivedbytes += line.Length; //string line = Encoding.ASCII.GetString(data, 0, data.Length); switch (status) { case serialstatus.Connecting: if (line.Contains("ENTER") || line.Contains("GROUND START") || line.Contains("reset to FLY") || line.Contains("interactive setup") || line.Contains("CLI") || line.Contains("Ardu")) { try { //System.Threading.Thread.Sleep(200); //comPort.Write("\n\n\n\n"); } catch { } System.Threading.Thread.Sleep(500); // clear history this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.Clear(); }); // comPort.Write("logs\r"); status = serialstatus.Done; } break; case serialstatus.Closefile: sw.Close(); DateTime logtime = new DFLog().GetFirstGpsTime(logfile); if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); logfile = newlogfilename; } catch (Exception ex) { log.Error(ex); CustomMessageBox.Show( "Failed to rename file " + logfile + "\nto " + newlogfilename, Strings.ERROR); } } TextReader tr = new StreamReader(logfile); // this.Invoke( (System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile); }); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; comPort.DiscardInBuffer(); break; case serialstatus.Createfile: receivedbytes = 0; Directory.CreateDirectory(MainV2.LogDir); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + currentlog + ".log"; sw = new StreamWriter(logfile); status = serialstatus.Waiting; lock (thisLock) { this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.Clear(); }); } //if (line.Contains("Dumping Log")) { status = serialstatus.Reading; } break; case serialstatus.Done: // // if (line.Contains("start") && line.Contains("end")) { Regex regex2 = new Regex(@"^Log ([0-9]+)[,\s]", RegexOptions.IgnoreCase); if (regex2.IsMatch(line)) { MatchCollection matchs = regex2.Matches(line); logcount = int.Parse(matchs[0].Groups[1].Value); genchkcombo(logcount); //status = serialstatus.Done; } } if (line.Contains("No logs")) { status = serialstatus.Done; } break; case serialstatus.Reading: if (line.Contains("packets read") || line.Contains("Done") || line.Contains("logs enabled")) { status = serialstatus.Closefile; Console.Write("CloseFile: " + line); break; } sw.Write(line); continue; case serialstatus.Waiting: if (line.Contains("Dumping Log") || line.Contains("GPS:") || line.Contains("NTUN:") || line.Contains("CTUN:") || line.Contains("PM:")) { status = serialstatus.Reading; Console.Write("Reading: " + line); } break; } lock (thisLock) { this.BeginInvoke((MethodInvoker) delegate() { Console.Write(line); TXT_seriallog.AppendText(line.Replace((char) 0x0, ' ')); // auto scroll if (TXT_seriallog.TextLength >= 10000) { TXT_seriallog.Text = TXT_seriallog.Text.Substring(TXT_seriallog.TextLength/2); } TXT_seriallog.SelectionStart = TXT_seriallog.Text.Length; TXT_seriallog.ScrollToCaret(); TXT_seriallog.Refresh(); }); } } //log.Info("exit while"); } catch (Exception ex) { CustomMessageBox.Show("Error reading data" + ex.ToString()); } }
void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { while (comPort.BytesToRead > 0 && threadrun) { updateDisplay(); string line = ""; comPort.ReadTimeout = 500; try { line = comPort.ReadLine(); //readline(comPort); if (!line.Contains("\n")) { line = line + "\n"; } } catch { line = comPort.ReadExisting(); //byte[] data = readline(comPort); //line = Encoding.ASCII.GetString(data, 0, data.Length); } receivedbytes += line.Length; //string line = Encoding.ASCII.GetString(data, 0, data.Length); switch (status) { case serialstatus.Connecting: if (line.Contains("ENTER") || line.Contains("GROUND START") || line.Contains("reset to FLY") || line.Contains("interactive setup") || line.Contains("CLI") || line.Contains("Ardu")) { try { //System.Threading.Thread.Sleep(200); //comPort.Write("\n\n\n\n"); } catch { } System.Threading.Thread.Sleep(500); // clear history this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.Clear(); }); // comPort.Write("logs\r"); status = serialstatus.Done; } break; case serialstatus.Closefile: sw.Close(); DateTime logtime = DFLog.GetFirstGpsTime(logfile); if (logtime != DateTime.MinValue) { string newlogfilename = MainV2.LogDir + Path.DirectorySeparatorChar + logtime.ToString("yyyy-MM-dd HH-mm-ss") + ".log"; try { File.Move(logfile, newlogfilename); logfile = newlogfilename; } catch (Exception ex) { log.Error(ex); CustomMessageBox.Show("Failed to rename file " + logfile + "\nto " + newlogfilename, Strings.ERROR); } } TextReader tr = new StreamReader(logfile); // this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.AppendText("Creating KML for " + logfile); }); LogOutput lo = new LogOutput(); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); try { lo.writeKML(logfile + ".kml"); } catch { } // usualy invalid lat long error status = serialstatus.Done; comPort.DiscardInBuffer(); break; case serialstatus.Createfile: receivedbytes = 0; Directory.CreateDirectory(MainV2.LogDir); logfile = MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + currentlog + ".log"; sw = new StreamWriter(logfile); status = serialstatus.Waiting; lock (thisLock) { this.Invoke((System.Windows.Forms.MethodInvoker) delegate() { TXT_seriallog.Clear(); }); } //if (line.Contains("Dumping Log")) { status = serialstatus.Reading; } break; case serialstatus.Done: // // if (line.Contains("start") && line.Contains("end")) { Regex regex2 = new Regex(@"^Log ([0-9]+)[,\s]", RegexOptions.IgnoreCase); if (regex2.IsMatch(line)) { MatchCollection matchs = regex2.Matches(line); logcount = int.Parse(matchs[0].Groups[1].Value); genchkcombo(logcount); //status = serialstatus.Done; } } if (line.Contains("No logs")) { status = serialstatus.Done; } break; case serialstatus.Reading: if (line.Contains("packets read") || line.Contains("Done") || line.Contains("logs enabled")) { status = serialstatus.Closefile; Console.Write("CloseFile: " + line); break; } sw.Write(line); continue; case serialstatus.Waiting: if (line.Contains("Dumping Log") || line.Contains("GPS:") || line.Contains("NTUN:") || line.Contains("CTUN:") || line.Contains("PM:")) { status = serialstatus.Reading; Console.Write("Reading: " + line); } break; } lock (thisLock) { this.BeginInvoke((MethodInvoker) delegate() { Console.Write(line); TXT_seriallog.AppendText(line.Replace((char)0x0, ' ')); // auto scroll if (TXT_seriallog.TextLength >= 10000) { TXT_seriallog.Text = TXT_seriallog.Text.Substring(TXT_seriallog.TextLength / 2); } TXT_seriallog.SelectionStart = TXT_seriallog.Text.Length; TXT_seriallog.ScrollToCaret(); TXT_seriallog.Refresh(); }); } } //log.Info("exit while"); } catch (Exception ex) { CustomMessageBox.Show("Error reading data" + ex.ToString()); } }
private void but_dflogtokml_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = MainV2.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { DialogResult copterlog = CustomMessageBox.Show("Is this a Copter Log?", "", MessageBoxButtons.YesNo); foreach (string logfile in openFileDialog1.FileNames) { LogOutput lo = new LogOutput(); try { TextReader tr = new StreamReader(logfile); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine(), copterlog == DialogResult.Yes); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex.ToString()); } lo.writeKML(logfile + ".kml"); } } }
private void but_dflogtokml_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Log Files|*.log;*.bin"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = MainV2.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { LogOutput lo = new LogOutput(); try { StreamReader tr; if (logfile.ToLower().EndsWith(".bin")) { var ms = new MemoryStream(); var lines = BinaryLog.ReadLog(logfile); foreach (var line in lines) { ms.Write(ASCIIEncoding.ASCII.GetBytes(line),0,line.Length); } ms.Seek(0, SeekOrigin.Begin); tr = new StreamReader(ms); } else { tr = new StreamReader(logfile); } while (!tr.EndOfStream) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex.ToString()); } lo.writeKML(logfile + ".kml"); } } }
private void but_dflogtokml_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "Log Files|*.log;*.bin"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = MainV2.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { LogOutput lo = new LogOutput(); try { StreamReader tr; if (logfile.ToLower().EndsWith(".bin")) { string tempfile = Path.GetTempFileName(); BinaryLog.ConvertBin(logfile, tempfile); tr = new StreamReader(tempfile); } else { tr = new StreamReader(logfile); } while (!tr.EndOfStream) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex); } lo.writeKML(logfile + ".kml"); } } } }
private void BUT_redokml_Click(object sender, EventArgs e) { using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Filter = "*.log|*.log"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; try { openFileDialog1.InitialDirectory = Settings.Instance.LogDir + Path.DirectorySeparatorChar; } catch { } // incase dir doesnt exist if (openFileDialog1.ShowDialog() == DialogResult.OK) { foreach (string logfile in openFileDialog1.FileNames) { TXT_seriallog.AppendText("\n\nProcessing " + logfile + "\n"); this.Refresh(); LogOutput lo = new LogOutput(); try { TextReader tr = new StreamReader(logfile); while (tr.Peek() != -1) { lo.processLine(tr.ReadLine()); } tr.Close(); } catch (Exception ex) { CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex.ToString()); } lo.writeKML(logfile + ".kml"); TXT_seriallog.AppendText("Done\n"); } } } }